[BUG] Stdio MCP server receives a CLAUDE_CODE_SESSION_ID different from the value passed to hooks / Bash tool on --resume sessions
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code (2.1.156)
What's Wrong?
Since v2.1.154 ("Stdio MCP server subprocesses now receive CLAUDE_CODE_SESSION_ID"), stdio MCP server subprocesses receive CLAUDE_CODE_SESSION_ID in their environment. However on --resume <id> sessions, the value passed to the MCP server is different from the value passed to hooks and Bash-tool subprocesses (the latter being added in v2.1.132 and explicitly documented as "matching the session_id passed to hooks").
What Should Happen?
Both subprocess kinds should see the same CLAUDE_CODE_SESSION_ID. Either source is acceptable as long as they agree; the value already passed to hooks/Bash-tool (i.e. the --resume <id> argument) is the more user-intuitive choice, since that's the identifier the user typed.
Steps to Reproduce
claude --resume <existing-session-id>(any resumed session)- From a Bash tool subprocess inside that session:
``bash``
env | grep CLAUDE_CODE_SESSION_ID
# → CLAUDE_CODE_SESSION_ID=<--resume argument value>
- From any stdio MCP server spawned by that session (inspect its env via
ps eww -p <mcp-pid>):
````
CLAUDE_CODE_SESSION_ID=<a different, newly minted UUID>
- Both values are immutable across the lifetime of their respective processes — this is not a timing race; the values are simply different from the moment each subprocess starts.
A small Python probe (parent-process walk → env diff between Bash subprocess and the MCP server pgrep'd as a child of the same CC binary → 2-second re-read to confirm env immutability) produced consistent results across three independent resumed sessions on the same machine, all reproducing the mismatch:
{"resumed": true, "shell": "6f9c6ba7-...", "mcp": "a8c42e74-...", "match": false, "immutable_2s": true}
{"resumed": true, "shell": "95114ba4-...", "mcp": "a3fd372a-...", "match": false, "immutable_2s": true}
{"resumed": true, "shell": "5560ac9d-...", "mcp": "1a1f6e1c-...", "match": false, "immutable_2s": true}
Environment
- Claude Code 2.1.156 (current latest)
- macOS / Apple Silicon
- Stdio MCP server registered in user-level
~/.claude.json(so this is not #61752, which covers plugin-bundled MCP servers)
Related issues
- #8069 / #10806 (closed) —
--resumemints a newsession_idrather than preserving the original; both closed without a maintainer ack. The mismatch reported here is a consequence of that behavior leaking through to subprocess env, but the user-facing surface (env var consistency across hook/Bash/MCP) is independent. - #61752 (closed) — different layer: plugin MCP servers don't get the env var at all.
- #25642 (closed, v2.1.132) — added env var to Bash tool, "matching
session_idpassed to hooks". - #56879 (closed) — docs for the env var.