[BUG] VS Code terminal mode: daemon-hosted session can never hold the IDE connection (front-end keeps reclaiming it), so mcp__ide__* tools are missing
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
In VS Code over Remote-SSH, with the extension in terminal mode (claudeCode.useTerminal: true):
/idealways fails with "Failed to connect to Visual Studio Code".- The session's
ideMCP server logs "WebSocket is not open. Cannot start transport." mcp__ide__getDiagnosticsis never available to the model.
This happens in an existing conversation and in a brand-new one.
Interactive sessions are hosted by the background daemon (claude daemon run --origin transient, with each session under bg-pty-host). The claude process in the VS Code integrated terminal is only a front-end attached to that session. Both processes connect to the extension's IDE server for the same window:
- The front-end has
CLAUDE_CODE_SSE_PORTand connects first. - The daemon-hosted session, which owns the
ideMCP tools, connects afterwards.
The IDE server keeps only the newest client and closes the previous one with a close frame that has no status code. So the session's connection pushes the front-end out, the front-end reconnects immediately, and the session is pushed out within milliseconds. The session then reports "WebSocket is not open".
What Should Happen?
When the front-end runs in a VS Code terminal, the daemon-hosted session should still get a working IDE connection (getDiagnostics, diffs). For example, the front-end and the session could share one connection, or the server could accept both.
Error Messages/Logs
/ide
⎿ Failed to connect to Visual Studio Code.
[DEBUG] MCP server "ide": Starting connection with timeout of 30000ms
[DEBUG] MCP server "ide": Connection failed after 122ms: WebSocket is not open. Cannot start transport.
[ERROR] MCP server "ide" Connection failed: WebSocket is not open. Cannot start transport.
Steps to Reproduce
- On a macOS host, install Claude Code 2.1.287. Open it in VS Code via Remote-SSH, with extension 2.1.287 and Use Terminal enabled.
- Open a folder and start Claude from the extension. Two processes result:
- The terminal
claudehasTERM_PROGRAM=vscodeandCLAUDE_CODE_SSE_PORT=<port>. - The session process's parent chain is
claude daemon run, thenbg-pty-host, with noCLAUDE_CODE_SSE_PORT.
- Run
/ide. It prints "Failed to connect to Visual Studio Code", andmcp__ide__getDiagnosticsis not in the tool list. - Run
lsof -nP -iTCP:<port>. The only ESTABLISHED client is the terminal front-end. - To show the server's behaviour without Claude: open a VS Code window on an empty folder, so that a new
~/.claude/ide/<port>.lockappears.
- Open websocket client A with the lock's token (
X-Claude-Code-Ide-Authorization, subprotocolmcp) and sendinitialize. The server answers. - Open client B the same way. The server sends A a close frame with no status code.
- A wrong token is closed with code 1008 instead.
- Against the window from step 2, open one extra connection with the real token. It is closed after about 3 ms, and the front-end's local port changes (observed: 57975 → 59217), which means the front-end was disconnected and reconnected.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.287 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
- VS Code 1.140.0 over Remote-SSH, extension
anthropic.claude-code2.1.287. The remote host is macOS 26.6.2 on Intel. getDiagnosticsworked in a terminal-mode session on 2026-09-30 with CLI 2.1.286. The same failure now reproduces with 2.1.286, so the CLI version alone is not the trigger. I don't know whether that earlier session was daemon-hosted.claude -p --idenever starts theideserver, so it can't reproduce this. An interactive session under a pty can (claude --ide --debug-file <file>).- Related but different: #96742, where panel sessions never get the IDE server advertised. Here the port is advertised, and the two clients take the connection from each other.