claude-code - 💡(How to fix) Fix [BUG] Detaching VSCode window leaves a "Ghost Session" due to unclosed stdio pipes [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52798Fetched 2026-04-25 06:20:38
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×4

Error Message

Error Messages/Logs

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

Root Cause

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.

Fix Action

Fix / Workaround

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.

Code Example

No explicit error message is shown in the UI. The issue happens silently in the background processes.
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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" />

extent analysis

TL;DR

Listen to VSCode's Window State Change or Detach lifecycle events to explicitly close the old MCP Client when a window is detached.

Guidance

  • Investigate VSCode's API for Window State Change or Detach events to determine the best way to listen for these events in the Claude Code extension.
  • Implement a callback function to explicitly call close() on the old MCP Client when a detach event occurs, ensuring the Daemon can recognize the disconnection immediately.
  • Verify that the workaround of manually executing Ctrl + R (Developer: Reload Window) still works as a temporary solution until the fix is implemented.
  • Review the attached architecture diagram to understand the current architecture and how the suggested fix will affect it.

Example

No code snippet is provided as the issue does not contain sufficient code context.

Notes

The suggested fix relies on the availability of VSCode's Window State Change or Detach lifecycle events, which may require further investigation to implement correctly.

Recommendation

Apply the suggested fix by listening to VSCode's Window State Change or Detach lifecycle events and explicitly closing the old MCP Client, as this addresses the root cause of the issue and provides a more permanent solution than the temporary workaround.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING