[BUG] MCP server child processes not terminated on Windows after session exit, causing process accumulation

Resolved 💬 4 comments Opened May 14, 2026 by tang-zhilei Closed May 23, 2026

Environment

  • OS: Windows 11 Home China 10.0.26200
  • Claude Code Version: 2.1.140 (VS Code extension, panel mode)
  • Shell: Git Bash (bash via MSYS2)
  • MCP servers: 5 (serena, fetch, sequential-thinking, context7, memory)

Summary

When a Claude Code session exits (normally, via close, or crash), all MCP server child processes remain running as orphan processes. Each new session spawns a fresh set of MCP servers, causing linear process accumulation. After 3 sessions in one morning, we observed ~36 orphan processes consuming ~4 GB RAM.

Steps to Reproduce

  1. Start a Claude Code session in VS Code on Windows
  2. Verify MCP servers are spawned: Get-Process java,python,node shows new processes
  3. Close/exit the Claude Code session
  4. Run Get-Process java,python,node again — all MCP server processes are still running
  5. Start another session — a second batch spawns alongside the first
  6. Repeat — processes accumulate linearly with each session

Observed behavior

After 3 sessions started/stopped in one morning (10:41, 10:46, 10:56):

| Process Type | Count (observed) | Count (expected) | Purpose |
|---|---|---|---|
| java.exe | 6 | 2 | 3x Serena JDTLS (~400MB each), 1x VS Code JLS, 2x IntelliJ |
| python.exe | 12 | 4 | 3x (serena-agent × 2 + mcp-server-fetch × 2) |
| node.exe | 18 | 6 | 3x (sequential-thinking + context7 + memory) × 2 each |

Each session batch spawns 11 child processes:

  • 1 Java (Serena Eclipse JDTLS, ~400 MB)
  • 4 Python (serena-agent × 2, mcp-server-fetch × 2)
  • 6 Node (3 MCP servers × 2: npx wrapper + actual process)

Expected behavior

When Claude Code exits, all child processes spawned for MCP servers should be terminated.

Root cause analysis

On Unix, child processes receive SIGHUP when the parent exits. On Windows, there is no equivalent signal — child processes become orphaned and continue running indefinitely. Claude Code does not appear to track spawned MCP server PIDs for explicit termination on exit.

Impact

  • Memory leak: Each stale session leaves ~1.5-2 GB of orphan processes
  • Resource exhaustion: Over a workday, this can consume 10+ GB RAM
  • CPU waste: Idle JDTLS instances consume CPU for background indexing
  • Port/pipe conflicts: Multiple instances may conflict on named pipes or ports

Workaround

Manually cleaning up orphan processes after each session:

# Find and kill MCP-related orphan processes
Stop-Process -Name java,python,node -Force  # (be careful not to kill active sessions)

Or use reliable-mcp as a process wrapper.

Related issues

  • #28126 — Task subagents spawn duplicate MCP servers on Windows
  • #48649 — Subagents spawn duplicate MCP server processes
  • #48423 — Subagents inherit all MCP servers causing stdio saturation

View original on GitHub ↗

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