anthropics / anthropics/claude-code

[BUG] VS Code extension: closing a session tab (×) leaves the claude process and its MCP servers running

Open
#94,292 0 comments 0 reactions 0 assignees View on GitHub
area:ide area:mcp bug has repro platform:linux platform:vscode
Dominant language
Python
Stars
145k
Forks
23.1k
PR merge metrics
PR metrics pending

Description

## Summary

In the VS Code extension, closing a Claude Code tab with the tab's **×** does not terminate the underlying `claude` process. The process keeps running (with its stdio MCP servers) until VS Code exits. Blank "new session" views that never received a prompt are affected too, so every opened-then-closed tab leaks a full `claude` process.

## Environment

- Claude Code VS Code extension `2.1.270` (`anthropic.claude-code-2.1.270-linux-x64`), native binary
- VS Code `1.137.0`
- Kubuntu 26.04.1 (Linux 7.0), Node 22.23.1 via nvm
- `permissions.defaultMode: bypassPermissions`, 4 stdio MCP servers at user scope (gcloud, postgres, chrome-devtools, figma) at the time of the measurement

## Steps to reproduce

1. Open the Claude Code panel in VS Code, open a new session tab (no need to type anything).
2. Close that tab with the × on the tab.
3. `ls ~/.claude/sessions/` — the `.json` for that session is still there; `ps -p ` shows the `native-binary/claude --output-format stream-json` process still alive, with its MCP child processes.

Repeat: each open/close cycle adds one process.

## What I measured

With 3 tabs actually open, I had **5** `claude` processes (two with `sessionId`s that have no transcript in `~/.claude/projects/` at all — blank views closed with ×), later **6** for 3 tabs after a window reload. Each process carried its own 4 stdio MCP servers: **66 MCP processes and ~3.5 GB RSS** for Claude Code alone (per-session trees between 260 MB and 1.2 GB).

The extension host log (`Claude VSCode.log`) for that window shows 6 `init` and 10 `launch_claude` webview messages, and **no message of any kind when a tab is closed** — no dispose/kill/close request reaches the extension side:

```
$ grep -oE '"request":\{"type":"[a-z_]+"' "Claude VSCode.log" | sort | uniq -c | sort -rn
155 webview_focused
117 update_session_state
77 rename_tab
...
6 init
$ grep -oE 'Received message from webview: \{"type":"[a-z_]+"' … | sort | uniq -c
10 launch_claude
2 interrupt_claude
```

(no `close_*`, `kill_*`, `dispose_*` entries exist)

## Expected

Closing a tab disposes the session: the `claude` process and its MCP children exit, and `~/.claude/sessions/.json` is removed. At minimum, blank views that never received a prompt should be reaped when their tab is closed.

## Actual

Process and MCP children keep running until VS Code exits. `~/.claude/sessions/.json` stays. Nothing in the UI shows these sessions, so users cannot see or close them.

## Workaround

A cron that kills `claude-vscode` sessions whose `sessionId` has no transcript and that are older than 10 minutes (reads `~/.claude/sessions/*.json`). Closed tabs that *do* have a transcript cannot be distinguished from open ones from outside, so those still leak.

Contributor guide

No contributing guide indexed for this repository

Research direction

Trace the VS Code webview-to-extension message handling around tab closure, comparing it with the existing launch_claude and interrupt_claude messages in Claude VSCode.log. Use ~/.claude/sessions/*.json and process inspection to verify behavior for blank and prompted tabs. Done means closing a tab terminates its claude process and MCP children and removes its session file.

Written by the indexing model from the issue text.

Assessment

Tech stack
vscode
Domain
desktop, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.