Windows: MCP server child processes not cleaned up on exit/crash
Description
On Windows, MCP server processes spawned by Claude Code are not properly terminated when Claude Code exits or crashes. This leads to accumulation of orphaned Python/Node processes over time.
Environment
- OS: Windows 11
- Claude Code version: 2.0.76
- MCP servers: Various (uvx-based Python servers, npx-based Node servers)
Steps to Reproduce
- Start Claude Code with MCP servers configured (e.g., sqlite, fetch, puppeteer)
- Use the session normally
- Exit Claude Code (or let it crash/timeout)
- Check running processes - MCP server processes remain running
Observed Behavior
After several Claude Code sessions, I found:
- 85+ orphaned Python processes from uv/cache (uvx MCP servers)
- 27+ orphaned PowerShell processes
- Multiple duplicate instances of the same MCP server
These processes accumulate over days and cause:
- High memory usage
- Repeated popup windows (authentication dialogs, login prompts)
- System slowdown
Expected Behavior
When Claude Code exits (gracefully or via crash), all spawned MCP server child processes should be terminated.
Suggested Fix
On Windows, use Job Objects to group child processes with the parent. When the parent process terminates (for any reason), Windows will automatically terminate all processes in the job.
Current Workaround
Added a Stop hook to clean up processes on graceful exit - but this only works for graceful exits, not crashes.
Additional Context
This appears to be Windows-specific. Unix systems handle child process cleanup differently (process groups, SIGHUP propagation).
Found 3 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/1935
- https://github.com/anthropics/claude-code/issues/11778
- https://github.com/anthropics/claude-code/issues/8865
This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and 👍 the existing issue instead
- To prevent auto-closure, add a comment or 👎 this comment
🤖 Generated with Claude Code
This issue has been automatically closed as a duplicate of #1935.
If this is incorrect, please re-open this issue or create a new one.
🤖 Generated with Claude Code