Bug Description
When an MCP server (Streamable HTTP transport) restarts or invalidates sessions, Claude Code's MCP client continues sending the stale Mcp-Session-Id header on every request. The server responds with {"error": "Not Found: invalid session ID"}, and every subsequent MCP tool call fails. The client never attempts to re-initialize.
The only workaround is to fully exit and restart Claude Code (/exit → relaunch), which forces a fresh initialize handshake.
Expected Behavior
Per the MCP Streamable HTTP spec, when the server returns an error indicating the session is no longer valid, the client should discard the stale session ID and perform a new initialize handshake transparently.
Actual Behavior
Claude Code caches the Mcp-Session-Id at connection time and never refreshes it. When the session becomes invalid (server restart, container redeployment, session timeout), all MCP tools break with no recovery path except a full CLI restart.
Frequency & Impact
Over a 7-day period (Feb 14–20, 2026), this bug forced 14 full Claude Code restarts across 14 separate sessions, totaling 53 mentions in session transcripts of stale-session/reconnect issues. On the most active day (Feb 19), 6 out of 6 sessions required at least one restart due to this bug.
Every deployment cycle triggers it: the workflow is build Docker image → deploy to server → container restarts → MCP session invalidated → Claude Code broken → must /exit and relaunch. This is a core development loop that happens multiple times per day.
The restart penalty is high: full context reload, re-reading of project files, loss of conversation flow, and re-establishment of all MCP connections.
Reproduction Steps
- Configure a Streamable HTTP MCP server in
~/.claude.json:
{
"mcpServers": {
"my-server": {
"type": "http",
"url": "https://example.com/mcp",
"headers": { "Authorization": "Bearer <key>" }
}
}
}
- Launch Claude Code — MCP tools work (client performs
initialize, gets session ID)
- Restart the MCP server (e.g.,
docker restart my-container)
- Try any MCP tool — fails with
"invalid session ID" or similar
- All subsequent MCP tool calls fail
- Only fix: exit Claude Code entirely and relaunch
Environment
- Claude Code on WSL2 (Linux 6.6.87.2-microsoft-standard-WSL2)
- MCP server: custom Streamable HTTP server in Docker (C++, session-based)
- Transport: Streamable HTTP (
"type": "http")
Related Issues
Suggested Fix
When Mcp-Session-Id returns an HTTP error (404, 410, or a JSON-RPC error indicating invalid session), the client should:
- Discard the cached session ID
- Send a new
initialize request
- Cache the new session ID
- Retry the original request
This is standard session recovery and would eliminate the most disruptive friction point in the MCP workflow.
Bug Description
When an MCP server (Streamable HTTP transport) restarts or invalidates sessions, Claude Code's MCP client continues sending the stale
Mcp-Session-Idheader on every request. The server responds with{"error": "Not Found: invalid session ID"}, and every subsequent MCP tool call fails. The client never attempts to re-initialize.The only workaround is to fully exit and restart Claude Code (
/exit→ relaunch), which forces a freshinitializehandshake.Expected Behavior
Per the MCP Streamable HTTP spec, when the server returns an error indicating the session is no longer valid, the client should discard the stale session ID and perform a new
initializehandshake transparently.Actual Behavior
Claude Code caches the
Mcp-Session-Idat connection time and never refreshes it. When the session becomes invalid (server restart, container redeployment, session timeout), all MCP tools break with no recovery path except a full CLI restart.Frequency & Impact
Over a 7-day period (Feb 14–20, 2026), this bug forced 14 full Claude Code restarts across 14 separate sessions, totaling 53 mentions in session transcripts of stale-session/reconnect issues. On the most active day (Feb 19), 6 out of 6 sessions required at least one restart due to this bug.
Every deployment cycle triggers it: the workflow is build Docker image → deploy to server → container restarts → MCP session invalidated → Claude Code broken → must
/exitand relaunch. This is a core development loop that happens multiple times per day.The restart penalty is high: full context reload, re-reading of project files, loss of conversation flow, and re-establishment of all MCP connections.
Reproduction Steps
~/.claude.json:{ "mcpServers": { "my-server": { "type": "http", "url": "https://example.com/mcp", "headers": { "Authorization": "Bearer <key>" } } } }initialize, gets session ID)docker restart my-container)"invalid session ID"or similarEnvironment
"type": "http")Related Issues
Suggested Fix
When
Mcp-Session-Idreturns an HTTP error (404, 410, or a JSON-RPC error indicating invalid session), the client should:initializerequestThis is standard session recovery and would eliminate the most disruptive friction point in the MCP workflow.