Subagents spawn duplicate MCP server processes, multiplying kernel resource consumption
Summary
Each subagent spawned by Claude Code runs as a separate claude.exe process that independently spawns its own set of MCP server child processes. With N concurrent sessions and M configured MCP servers, this creates N×M child processes, each with 3 stdio pipes (kernel objects), plus duplicated file watchers and memory allocations.
Problem
When Claude Code spawns subagents (via the Agent tool), each subagent:
- Starts as a new
claude.exeprocess - Spawns its own MCP server child processes (StdioClientTransport)
- Creates its own set of chokidar file watchers
- Maintains its own message buffers and caches
For a typical setup with 5 configured MCP servers:
| Scenario | claude.exe | MCP child procs | stdio pipes | chokidar watchers |
|---|---|---|---|---|
| 1 session | 1 | 5 | 15 | 8 |
| 1 session + 2 subagents | 3 | 15 | 45 | 24 |
| 3 sessions + 2 subagents each | 9 | 45 | 135 | 72 |
Each pipe is a kernel object consuming Non-Paged Pool. Each watcher set creates thousands of ReadDirectoryChangesW handles (see #48648).
Observed Impact
On a Windows 11 system with 64 GB RAM, 3 concurrent claude.exe instances (main + subagents) were observed with:
- Combined private memory: ~15 GB
- Non-Paged Pool: 35 GB (normal: few hundred MB)
- System crash: DWM STATUS_NO_MEMORY (0xc00001ad)
Suggested Improvements
- Share MCP server connections: Subagents could connect to parent's MCP servers via IPC rather than spawning their own
- Lazy MCP startup: Only spawn MCP servers when a tool from that server is actually called
- MCP server pooling: Maintain a process-level pool of MCP server connections shared across all agents
- Watcher deduplication: Share file watchers across the process tree
Environment
- claude.exe v2.1.109 (Bun binary)
- Windows 11 Pro 10.0.26200, 64 GB RAM
Related Issues
- #42169 (resource exhaustion with multiple claude.exe processes)
- #48648 (chokidar watcher NPP exhaustion)
- #20369 (orphaned subagent processes)
- #48647 (Buffer.slice retention per MCP connection)
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗