Skip to content

[BUG] MCP calls routed to wrong server when multiple Claude Code sessions run concurrently #28093

@logpie

Description

@logpie

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

  1. Open two terminal tabs
  2. Tab 1: cd /path/to/project-a && claude
  3. Tab 2: cd /path/to/project-b && claude
  4. In both tabs near-simultaneously, ask Claude to call Codex (e.g., "Ask Codex to review this code")
  5. Check Codex session logs: ls -lt ~/.codex/sessions/$(date +%Y/%m/%d)/
  6. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:mcpbugSomething isn't workingplatform:macosIssue specifically occurs on macOSstaleIssue is inactive

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions