Pass workspace directory to MCP servers
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
- #7281 - WSL2 Remote spawns MCP with wrong cwd (my previous report)
- #4222 - MCP servers not launched in workspace folder
- #5387 - Related duplicate
Environment
- Codex VS Code extension: v0.4.67
- Platform: WSL2 Ubuntu on Windows 11
- VS Code: Remote - WSL
4 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Reviewed the potential duplicates - this is not a duplicate:
| Issue | Problem | This Issue |
|-------|---------|------------|
| #8260 | MCP servers fail to connect in Remote-SSH | MCP works, but spawns with wrong
cwd|| #7820 | MCPs in config.toml not visible to VS Code | MCPs are visible and functional |
| #8029 | Sandbox settings ignored | Unrelated (sandbox vs cwd) |
Key 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.
The fact that codex doesn't pass the project dir is puzzling to me.
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.