[BUG] /ide fails when cwd is a subdirectory of the workspace folder — CLI aborts after successful connect (2.1.216, re-report of #14832)

Status Open
Reported on v2.1.216
Maintainer reply None cached
Activity 0 comments · opened Jul 21, 2026

Description

/ide fails with the generic "Failed to connect to Visual Studio Code." whenever the CLI's cwd is a subdirectory of the VS Code window's workspace folder instead of the workspace folder itself. The connection itself succeeds — the extension log shows a completed WebSocket upgrade, auth, and MCP transport connect — and the CLI then aborts ~10 ms later, apparently in post-connect validation. The error message gives no hint that the workspace/cwd mismatch is the cause.

This is a re-report of #14832 (same behavior on v2.0.74, auto-closed as stale without a fix), now reproduced on 2.1.216 with server-side log evidence.

Environment

  • Claude Code CLI: 2.1.216
  • VS Code extension (anthropic.claude-code): 2.1.216 (versions match)
  • OS: Windows 11 + WSL2 (Ubuntu), VS Code 1.129.1 via Remote-WSL
  • Terminal: VS Code integrated terminal (WSL)

Steps to reproduce

  1. Open a VS Code (WSL) window on a parent folder, e.g. ~/ — lock file shows "workspaceFolders":["/home/<user>"].
  2. In an integrated terminal, cd ~/projects/<repo> (a subdirectory of the workspace folder) and start claude. The env correctly contains CLAUDE_CODE_SSE_PORT=<port> for that window.
  3. Run /ide → "Failed to connect to Visual Studio Code."
  4. File → Add Folder to Workspace… → add ~/projects/<repo> (so cwd now exactly matches a workspace folder root).
  5. Run /ide again → "Connected to Visual Studio Code." Nothing else changed.

Evidence

Extension log (~/.vscode-server/data/logs/<ts>/exthost1/Anthropic.claude-code/Claude VSCode.log) during a failing /ide attempt:

16:28:13.452 [info] New WS connection from: /
16:28:13.453 [info] MCP server connected to transport
16:28:13.453 [info] Registered diagnostic client: client_10
16:28:13.463 [info] WS client disconnected        <-- CLI hangs up 10 ms after successful connect
  • No Unauthorized WebSocket connection attempt errors — auth passed.
  • A hand-rolled WebSocket client using the same lock-file port + x-claude-code-ide-authorization token gets a full MCP initialize response (serverInfo: "Claude Code VSCode MCP" 2.1.216), so the server side is healthy.
  • Lock file is valid: extension-host PID alive, port listening on 127.0.0.1, transport: ws, runningInWindows: false.

Expected behavior

Either of:

  1. /ide connects when cwd is inside a workspace folder (subdirectory match) — the common case of opening an editor on a parent folder and running the CLI in a project below it; or
  2. if exact-root matching is intentional, the error says so, e.g. "VS Code window workspace (/home/<user>) does not match the CLI working directory (…/projects/<repo>) — add the folder to the workspace or start claude at the workspace root", instead of the generic connection failure.

Workaround

Add the CLI's cwd as a workspace folder (File → Add Folder to Workspace) or open the window directly on the project root.

View original on GitHub ↗