[BUG] Backend claude process and its MCP/socat children are not terminated on tab close, session resume, or project deletion — leading to unbounded process accumulation.
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?
The VS Code Claude Code extension does not terminate the backend claude process (native-binary) — nor its child processes (stdio MCP servers, socat bridge) — when a chat tab/window is closed, when a session is resumed, or when the associated project directory is deleted.
Over ~1 hour of normal usage (opening/closing tabs, resuming sessions, one auto-update of an MCP server binary), the number of live backend claude processes grew to 6, each with its own child MCP server + socat process — none were ever torn down:
````
PID(claude) PPID(ext.host) STARTED ARGS (relevant) CHILDREN
146927 145677 16:37:12 (fresh session) mcp-server-a (147249), socat (147287)
147914 145677 16:37:24 --resume 909997d8-... mcp-server-a (147957), socat (147992)
173711 172425 17:03:20 (fresh session) mcp-server-a (173990), socat (174026)
177148 172425 17:04:17 --resume f9aef7ad-... mcp-server-a (177189), socat (177222)
177333 172425 17:04:21 --resume e0a5c130-... mcp-server-a (177375), socat (177408)
227358 172425 17:35:54 (fresh session) mcp-server-a (227406), socat (227467)
(mcp-server-a here is a stdio MCP server configured in my ~/.claude.json; any long-lived stdio MCP server would show the same pattern.)
Key observations:
- All 6
claudeprocesses are still alive and consuming resources (confirmed viaps -eo pid,ppid,lstart,etime,cmd). These are not orphans reparented to PID 1 — they are legitimate live children of two separate extension-host processes (145677, 172425). The extension host itself simply never terminates them. - Two of the sessions (146927/147914, both under extension host 145677) are bound, via their MCP server's open file descriptors, to a project directory that has since been deleted.
lsofshows the child MCP server still holding(deleted)file handles for that removed directory — the corresponding tab/window was closed (or the project removed) well before the backend process and its MCP child were cleaned up. They simply keep running with no useful purpose. - Within extension host 172425, three separate
claudebackend processes were spawned within ~65 seconds of each other (17:03:20, 17:04:17, 17:04:21), two of them via--resume <session-id>of what looks like the same session lineage. The earlier process in each case was not terminated before the resumed one was spawned, resulting in two or three live backends for what the user experiences as a single continuous conversation.
Individually each leaked process is small (tens of MB RSS, near-zero CPU while idle), but the leak is unbounded — it grows with every tab/window/session-resume cycle and is never reclaimed except by fully restarting VS Code (killing all extension hosts). On a long-running dev machine this is a real resource-exhaustion risk (I noticed the process count creeping up over a single day of normal usage).
What Should Happen?
- Closing a chat tab/window should terminate its corresponding
claudebackend process and all of its children (MCP stdio servers,socatbridge). - Resuming a session (
--resume <id>) should replace/terminate the previous backend process for that session id, not run alongside it. - If a project's directory is deleted or becomes unreachable, any backend process bound to it should be detected as stale and terminated, or at minimum the extension should not keep holding processes/file handles against a path that no longer exists.
Error Messages/Logs
None — no crash, no error surfaced in the UI or in the extension's output channel. The processes just accumulate silently in the background.
Steps to Reproduce
- Configure at least one stdio MCP server in
~/.claude.json(mcpServers.<name>.command) so eachclaudebackend session spawns a visible long-lived child process. - Open a project in VS Code and start a Claude Code chat session.
- Note the resulting process tree:
```
ps -eo pid,ppid,lstart,etime,cmd | grep -E 'native-binary/claude| serve'
claude` backend process plus its MCP server child(ren).
You should see one
- Close the chat tab (or close the VS Code window) without explicitly ending the session.
- Re-run the same
pscommand. Theclaudebackend process and its MCP server child are still present and running, with no corresponding visible tab/window. - Repeat steps 2–4 a few times over the course of normal usage (opening new tabs, resuming previous sessions via history, occasionally deleting/moving a project folder that had an open session).
- Observe that the count of live
claudebackend + MCP child +socatprocesses only grows — it never decreases — even though the number of actually-open tabs/windows stays constant or shrinks.
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.205
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_