[BUG] Detaching VSCode window leaves a "Ghost Session" due to unclosed stdio pipes

Resolved 💬 2 comments Opened Apr 24, 2026 by jihosong-git Closed Jun 13, 2026

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?

When dragging and detaching a VSCode window/tab, the original UI is destroyed, but the background Bridge process and TCP connection to the Daemon remain alive. From the Daemon's perspective, it cannot distinguish whether this is a Ghost session or a normal session waiting for user input. Ultimately, the Ghost session is maintained in the background for several minutes until VSCode's Garbage Collector (GC) cleans up the extension host.

What Should Happen?

When a window is detached and the old view is destroyed, close() should be explicitly called on the old MCP Client, or the stdio pipes should be gracefully closed. This would allow the Daemon to recognize the disconnection immediately and clean up the orphaned session.

Error Messages/Logs

No explicit error message is shown in the UI. The issue happens silently in the background processes.

Steps to Reproduce

Open two or more Claude Code sessions (tabs/windows) in the VSCode integrated terminal.

Drag one of the tabs to detach it into a new, separate window (e.g., drag it to another monitor).

Check the background processes or Daemon connection status (you will see the old Bridge process / TCP connection is still alive even though the original UI tab is gone).

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.119

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

VS Code integrated terminal

Additional Information

Root Cause Analysis:
When the detach event occurs, the architecture acts as "Original window UI disappears + A cloned window is created." At this time, only the UI is destroyed. The VSCode extension host does not send a termination signal to the underlying Bridge process, nor does it call stdio close.

Workaround:
Users can manually execute Ctrl + R (Developer: Reload Window) to forcefully shut down the Extension Host, which instantly cleans up the orphaned Bridge process and sockets.

Suggested Fix:
Listen to VSCode's Window State Change or Detach lifecycle events, and explicitly call close() on the existing object (Old MCP Client) before the new window instance takes over control.

(Please see the attached architecture diagram for better understanding)

<img width="1646" height="855" alt="Image" src="https://github.com/user-attachments/assets/c41f32c8-f950-40d4-b56a-5025924a9cf5" />

View original on GitHub ↗

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