Bug Summary
When two Claude Code sessions call mcp__codex__codex concurrently, the MCP call can be routed to the wrong Codex MCP server process (belonging to a different Claude Code session/project). This causes Codex to operate in the wrong project directory with the wrong context.
Environment
- codex-cli: 0.103.0
- Claude Code: latest as of 2026-02-23
- macOS Darwin 24.6.0 (arm64, Apple Silicon)
- Multiple Claude Code sessions in separate terminal tabs, each with its own Codex MCP server
Steps to Reproduce
- Open two terminal tabs
- Tab 1:
cd /path/to/project-a && claude
- Tab 2:
cd /path/to/project-b && claude
- In both tabs near-simultaneously, ask Claude to call Codex (e.g., "Ask Codex to review this code")
- Check Codex session logs:
ls -lt ~/.codex/sessions/$(date +%Y/%m/%d)/
- Inspect session metadata:
python3 -c "import json; print(json.loads(open('FILE').readline())['payload']['cwd'])"
Expected Behavior
Each Codex MCP session should have the cwd matching the Claude Code session that initiated it.
Actual Behavior
Some sessions receive the wrong cwd, git context, and even the wrong prompt. Specifically:
- 3 sessions got a parent directory with no git context
- 1 session got a completely different project's directory (project-B instead of project-A), including that project's AGENTS.md, git repo URL, and git branch
Evidence from Session Logs
Wrong session (started 02:28:39 UTC):
session_meta.cwd = /path/to/project-B # WRONG — should be project-A
session_meta.git.repository_url = <project-B repo>
session_meta.git.branch = main
The turn_context and user messages in this session contain:
AGENTS.md instructions for /path/to/project-B
<cwd>/path/to/project-B</cwd>
- A prompt referencing
cd /path/to/project-B && git diff HEAD~1
But this call was initiated from a Claude Code session running in /path/to/project-A.
Correct retry (started 02:40:02 UTC, same prompt retried):
session_meta.cwd = /path/to/project-A # CORRECT
session_meta.git.repository_url = <project-A repo>
session_meta.git.branch = feature-branch
Full Day Analysis (9 sessions, all initiated from project-A)
| Time (UTC) |
Session CWD |
Correct? |
| 20:01 |
project-A |
Yes |
| 22:12 |
project-A |
Yes |
| 22:44 |
parent dir (no git) |
No |
| 22:44 |
project-A |
Yes |
| 23:18 |
parent dir (no git) |
No |
| 23:28 |
project-A |
Yes |
| 02:28 |
parent dir (no git) |
No |
| 02:28 |
project-B |
No |
| 02:40 |
project-A |
Yes |
Failure rate: 4/9 (44%)
Analysis
The MCP protocol uses stdio pipes, so each Codex MCP server subprocess should be isolated. However, the evidence shows that Claude Code's MCP client layer is sometimes delivering calls to the wrong Codex MCP server process. This is not a Codex server bug — the server correctly operates in whatever context it receives.
The bug appears to correlate with concurrent MCP calls from multiple Claude Code sessions. The wrong-cwd sessions tend to appear near-simultaneously with correct ones (e.g., 22:44:23 wrong + 22:44:53 correct, 02:28:27 wrong + 02:28:39 wrong + 02:40:02 correct retry).
The "parent dir" failures (3 cases) suggest the MCP server was spawned before the cwd was properly set. The "project-B" failure (1 case) suggests the call was delivered to project-B's already-running MCP server instead of project-A's.
Impact
- Codex reads files from the wrong project
- Codex may execute commands in the wrong directory (if sandbox allows writes)
- Codex reviews/analysis is based on wrong codebase
- User observes "hanging" because Codex is working in a different context and may be confused by the prompt referencing non-existent files
- Workaround: retry the call (it usually succeeds on second attempt)
Reproduction Script
# Setup
mkdir -p /tmp/codex-repro/project-a /tmp/codex-repro/project-b
cd /tmp/codex-repro/project-a && git init -q && echo "# A" > README.md && git add . && git commit -qm "init"
cd /tmp/codex-repro/project-b && git init -q && echo "# B" > README.md && git add . && git commit -qm "init"
# Then open two Claude Code sessions and call Codex simultaneously.
# Check ~/.codex/sessions/ for cwd mismatches.
Bug Summary
When two Claude Code sessions call
mcp__codex__codexconcurrently, the MCP call can be routed to the wrong Codex MCP server process (belonging to a different Claude Code session/project). This causes Codex to operate in the wrong project directory with the wrong context.Environment
Steps to Reproduce
cd /path/to/project-a && claudecd /path/to/project-b && claudels -lt ~/.codex/sessions/$(date +%Y/%m/%d)/python3 -c "import json; print(json.loads(open('FILE').readline())['payload']['cwd'])"Expected Behavior
Each Codex MCP session should have the
cwdmatching the Claude Code session that initiated it.Actual Behavior
Some sessions receive the wrong
cwd,gitcontext, and even the wrong prompt. Specifically:Evidence from Session Logs
Wrong session (started 02:28:39 UTC):
The
turn_contextand user messages in this session contain:AGENTS.md instructions for /path/to/project-B<cwd>/path/to/project-B</cwd>cd /path/to/project-B && git diff HEAD~1But this call was initiated from a Claude Code session running in
/path/to/project-A.Correct retry (started 02:40:02 UTC, same prompt retried):
Full Day Analysis (9 sessions, all initiated from project-A)
Failure rate: 4/9 (44%)
Analysis
The MCP protocol uses stdio pipes, so each Codex MCP server subprocess should be isolated. However, the evidence shows that Claude Code's MCP client layer is sometimes delivering calls to the wrong Codex MCP server process. This is not a Codex server bug — the server correctly operates in whatever context it receives.
The bug appears to correlate with concurrent MCP calls from multiple Claude Code sessions. The wrong-cwd sessions tend to appear near-simultaneously with correct ones (e.g., 22:44:23 wrong + 22:44:53 correct, 02:28:27 wrong + 02:28:39 wrong + 02:40:02 correct retry).
The "parent dir" failures (3 cases) suggest the MCP server was spawned before the cwd was properly set. The "project-B" failure (1 case) suggests the call was delivered to project-B's already-running MCP server instead of project-A's.
Impact
Reproduction Script