[BUG] VS Code extension only allows one CLI instance to have IDE integration at a time

Resolved 💬 2 comments Opened Mar 29, 2026 by trgoodwin Closed Apr 29, 2026

Problem

The VS Code extension's WebSocket server only supports one CLI connection at a time. When multiple claude CLI sessions connect to the same VS Code window (e.g. from separate terminal tabs), only the most recent one gets IDE integration. The others silently fall back from "IDE: Connected" to "IDE: Installed".

This means only one session gets file-open notifications, selection context, and diagnostics — the rest fly blind.

Reproduction steps

  1. Open VS Code with the Claude Code extension active
  2. Open a terminal tab and run claude — observe "IDE: Connected" in the status line
  3. Open a second terminal tab and run claude — observe "IDE: Connected" in the new session
  4. Return to the first session — it now shows "IDE: Installed" (no longer connected)

Root cause

In the extension's WebSocket connection handler, when a new CLI connects, the previous connection is explicitly closed:

// Pseudocode from extension.js (beautified)
if (currentTransport) {
  diagnosticProvider.unregisterClient(currentDiagClientId);
  currentTransport.close();  // <-- kills the previous CLI's IDE connection
}
let newTransport = new WebSocketTransport(ws);
currentTransport = newTransport;  // <-- single-slot replacement
mcpServer.connect(newTransport);

Additionally, the MCP Protocol class's connect() method enforces single-transport: "Already connected to a transport. Call close() before connecting...".

The getter F = () => currentTransport returns only the latest transport, so event handlers (selection changes, file opens, diagnostics) only notify one client.

Proposed fix

Replace the single-connection model with a multiplexing transport:

  1. Maintain a Map of connected clients instead of a single transport variable
  2. Connect the MCP server once to a multiplexing transport that sits between the server and all WebSocket clients
  3. Route request/responses by ID — namespace each client's JSON-RPC request IDs (e.g. clientId:originalId) to avoid collisions, restore original IDs when sending responses back
  4. Broadcast notifications (diagnostics, selection changes, file opens, log events) to all connected clients
  5. Per-client diagnostic registration — each client gets its own registerClient() callback; disconnecting one doesn't unregister others
  6. Clean per-client teardown — only the disconnected client's state is cleaned up

The transport getter becomes: F = () => clients.size > 0 ? multiplexTransport : null

I've validated this approach with a monkey-patch on the installed extension — multiple CLI sessions maintain simultaneous "IDE: Connected" status and all receive IDE events.

Related issues

  • #39486 — Similar symptom (MCP disconnect on multi-session) but for .mcp.json-configured MCP servers, not the VS Code extension's IDE integration
  • #10071 — MCP auto-reconnect feature request (would mitigate but not fix)
  • #27390 — Protocol instance reuse fix in Claude Desktop (same class of bug, different product)

Environment

  • Claude Code CLI v2.1.87
  • VS Code extension anthropic.claude-code v2.1.87
  • macOS (Darwin 25.4.0)

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗