anthropics / anthropics/claude-code

CLI loses SSE/WebSocket MCP connection after session switch in sidebar

Open
#94,483 1 comment 0 reactions 0 assignees View on GitHub
area:ide area:mcp bug platform:linux
Dominant language
Python
Stars
145k
Forks
23.1k
PR merge metrics
PR metrics pending

Description

## Description

When Claude Code CLI is launched from an IDE integration that uses `CLAUDE_CODE_SSE_PORT` (e.g., Emacs `claude-code-ide.el`), the CLI connects to the WebSocket MCP server on startup and registers tools like `openDiff`. However, after navigating to the session list (← arrow in sidebar), selecting another session, and returning — the CLI re-initializes MCP connections but **only reconnects to the HTTP MCP server** configured via `--mcp-config`. The SSE/WebSocket connection (from `CLAUDE_CODE_SSE_PORT`) is **not re-established**.

As a result, tools registered on the WebSocket server (`openDiff`, `closeAllDiffTabs`, `close_tab`) disappear, and features like ediff stop working.

## Steps to Reproduce

1. Launch Claude Code CLI from an IDE integration that uses `CLAUDE_CODE_SSE_PORT` for a WebSocket MCP server and `--mcp-config` for an HTTP MCP server
2. Verify `openDiff` tool works (e.g., ediff appears on file edit)
3. Press ← to open the session list in the sidebar
4. Select any other session
5. Return to the original session
6. Request a file edit — ediff no longer appears

## Observed Behavior

After session switch, the CLI sends `server/discover` → `initialize` → `tools/list` to the HTTP MCP server only, which returns its tools (without `openDiff`). No reconnection attempt is made to the WebSocket server at `CLAUDE_CODE_SSE_PORT`. The environment variable is still present in the process — the CLI simply does not re-establish the connection.

## Expected Behavior

After session switch, the CLI should reconnect to the SSE/WebSocket endpoint at `CLAUDE_CODE_SSE_PORT` in addition to the HTTP MCP server from `--mcp-config`, preserving all registered tools.

## Environment

- Claude Code CLI (latest as of 2025-09-15)
- Emacs 30+ with `claude-code-ide` package
- Linux

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the session-switch MCP reinitialization path and the CLAUDE_CODE_SSE_PORT entry point, comparing it with the --mcp-config HTTP path. Reproduce the sidebar session switch described here and verify that the WebSocket tools openDiff, closeAllDiffTabs, and close_tab remain available afterward.

Written by the indexing model from the issue text.

Assessment

Tech stack
emacs, python
Domain
cli, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.