MCP server processes not terminated when Agent subprocesses exit
Bug Description
When Claude Code spawns Agent subprocesses (via the Agent tool), each subprocess starts its own MCP server connections as configured in ~/.claude.json. When the Agent subprocess completes and exits, the MCP server processes are not terminated, becoming orphan processes that accumulate indefinitely.
Impact
This caused a kernel panic on my Mac (M1 Pro, macOS 26.3/Sequoia) due to memory exhaustion.
Reproduction Steps
- Configure a memory-intensive MCP server in
~/.claude.json, e.g.:
``json``
{
"mcpServers": {
"auggie": { "command": "auggie", "args": ["--mcp", "--mcp-auto-workspace"] }
}
}
- In a Claude Code session, run a task that spawns many Agent subprocesses (e.g., batch document processing using the Agent tool)
- Observe that each Agent subprocess spawns its own MCP server process (
node /opt/homebrew/bin/auggie --mcp ...) - When the Agent subprocess exits, the MCP server process remains alive as an orphan
Evidence from Kernel Panic Analysis
On 2026-03-17, a Claude Code session spawned 298 Agent subprocesses for knowledge base document summarization (~3/min over 100 minutes). Each spawned an auggie --mcp node process (~400 MB each). After the Agent subprocess completed, the auggie processes were never terminated.
From the panic stackshot:
- 248 orphaned
node(auggie) processes consuming 111.1 GB total resident memory - System had 88 swap files, compressor segments at 100% (BAD)
- Watchdog timeout after 91 seconds → kernel panic
From Langfuse traces (ClickHouse):
- 298 single-turn
claude-codesessions between 17:10–18:50 - All with prompt:
"You are a documentation analysis expert. Generate a concise yet informative summary..." - These were Agent tool subprocesses, each creating its own session
Memory distribution of orphaned processes:
| Bucket | Count | Total Memory |
|--------|-------|-------------|
| 300-700 MB | 245 | ~110 GB |
| 50-300 MB | 6 | ~0.8 GB |
| <50 MB | 2 | ~0.1 GB |
Expected Behavior
When an Agent subprocess exits, all child processes (including MCP servers) should be terminated via SIGTERM/SIGKILL, or the MCP server connections should be properly shut down.
Workaround
Remove memory-intensive MCP servers from global ~/.claude.json, or add cleanup to the Stop hook:
pkill -f "auggie --mcp"
Environment
- Claude Code version: 2.1.77
- macOS 26.3 (25D125), Darwin Kernel 25.3.0
- Hardware: Mac Studio M1 Max (T6000)
- MCP server: auggie (Augment Code CLI)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗