Pass workspace directory to MCP servers #9989
Description
Summary
The Codex VS Code extension spawns MCP servers from the VS Code installation directory instead of the workspace directory. This fundamentally breaks semantic code analysis tools like Serena that rely on correct working directory to index and analyze codebases.
Impact
Serena provides symbolic code operations that are essential for large codebase work:
find_symbol/find_referencing_symbols- call graph traversalreplace_symbol_body- precise symbol-level editsget_symbols_overview- fast structural understanding
Without correct cwd, these tools cannot auto-detect the project, forcing users to manually activate projects every session. This defeats the purpose of semantic tooling.
Current State
| Client | MCP Server cwd | Works? |
|---|---|---|
| Codex CLI | Project directory | ✅ |
| Codex VS Code (Remote: WSL) | /mnt/c/.../Microsoft VS Code |
❌ |
Proposed Fix
When spawning MCP servers, pass cwd: ${workspaceFolder} (or the active workspace root). This is a one-line fix that would unblock all path-dependent MCP tools.
Workarounds Attempted
--project-from-cwdflag in Serena - fails because cwd is wrong- Manual
activate_projecteach session - works but error-prone - Wrapper scripts - cannot access workspace info at spawn time
CODEX_WORKSPACE_ROOTenv var - only available at tool-call time, not spawn time
I've also filed a feature request on Serena to use CODEX_WORKSPACE_ROOT at tool-call time (oraios/serena#970), but the proper fix should be in the VS Code extension.
Related Issues
- Spawns multiple MCP servers with wrong cwd and doesn’t clean them up #7281 - WSL2 Remote spawns MCP with wrong cwd (my previous report)
- MCP servers are not launched in the VSCode workspace folder #4222 - MCP servers not launched in workspace folder
- Add cwd (Current Working Directory) to Notify Input #5387 - Related duplicate
Environment
- Codex VS Code extension: v0.4.67
- Platform: WSL2 Ubuntu on Windows 11
- VS Code: Remote - WSL
Activity
github-actions commentedon Jan 27, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
ginishuh commentedon Jan 27, 2026
Reviewed the potential duplicates - this is not a duplicate:
cwdKey distinction: The other issues are about MCP connectivity/visibility. This issue is specifically about the working directory passed to MCP servers being the VS Code installation path instead of the workspace root.
The root cause may be shared (VS Code extension's MCP handling), but the symptom and fix are different. This requires explicitly passing
cwd: ${workspaceFolder}when spawning MCP server processes.Related but distinct from #7281 and #4222 which I also filed - those focus on the general problem, while this issue emphasizes the impact on semantic code tools like Serena.
[-]VS Code extension should pass workspace directory to MCP servers (blocking semantic code tools like Serena)[/-][+]Pass workspace directory to MCP servers[/+]drozzy commentedon Feb 8, 2026
The fact that codex doesn't pass the project dir is puzzling to me.
ub3dqy commentedon Apr 14, 2026
I can confirm this is broader than MCP server spawn and appears to affect the extension's working-directory normalization in general.
In my setup, the same Remote-WSL / Windows-workspace-path bug causes all lifecycle hooks to fail in the VS Code extension, even though the hook commands themselves use absolute paths.
Environment
0.119.0-alpha.28(embedded app-server)codex-cli 0.120.0E:\Project\memory claude\memory claude(note Windows path + spaces)codex_hooks = trueSymptom
Inside the VS Code extension, all hooks are shown as
failedin the UI:SessionStartUserPromptSubmitStopPostToolUseDownstream capture/logging writes nothing during those sessions.
Evidence
Inspecting
~/.codex/logs_2.sqlite, thecwdrecorded inturnspans is malformed:That path is neither the VS Code install directory nor the WSL workspace root. It looks like the extension/app-server is combining the VS Code install dir with the raw Windows workspace path instead of normalizing
E:\...to/mnt/e/...first.Why this matters
This is not only an MCP-server spawn problem. Once the extension hands child processes an invalid cwd, other path-dependent subprocesses also break. In my case that meant hook commands consistently reported
failedin the extension, while the same hook stack worked fine outside the extension.Confirmed workaround
Run standalone
codexdirectly from a WSL terminal in the project root:In that mode:
/mnt/e/Project/memory claude/memory claudecompletedSo this still looks like a VS Code extension Remote-WSL cwd-normalization bug, but the impact is broader than MCP tooling: it can break extension-managed hooks and other child-process workflows too.
fix(mcp): accept workspace_root arg on all 9 tools + hardened resolution
fix(daemon): a bridge's launch directory counts only inside a project (…
Daemon: a session's bridge registers its own project, for Claude Code…