MCP server processes leak on host after subagent/session termination
Resolved 💬 3 comments Opened Mar 29, 2026 by psychologistgbi-beep Closed Apr 2, 2026
Bug description
MCP server processes spawned by Claude Code are not terminated when a subagent or session ends. Each process consumes ~44 MB of RAM and accumulates over time, leading to significant memory waste.
Reproduction steps
- Configure an MCP server in Claude Code settings (e.g.,
mcp-postgres-full-access) - Use the Agent tool to spawn multiple subagents that use MCP tools
- Wait for subagents to complete
- Check running processes:
``bash``
ps aux | grep "mcp-postgres" | grep -v grep | wc -l
Observed behavior
After a session with ~30 agent runs and subagents, 172 orphaned MCP processes remained on the host:
$ ps aux | grep "mcp-postgres" | grep -v grep | wc -l
172
$ ps aux | grep "mcp-postgres" | grep -v grep | awk '{sum += $6} END {print sum/1024 " MB total, " NR " processes"}'
1087.31 MB total, 172 processes
Each process is npm exec mcp-postgres-full-access postgresql://... consuming ~44 MB.
Expected behavior
MCP server processes should be terminated when:
- A subagent (Agent tool) completes or is cancelled
- A Claude Code session ends
- The parent
claudeCLI process exits
Workaround
Manual cleanup:
pkill -f "mcp-postgres-full-access"
Active agents will re-spawn their MCP servers automatically.
Environment
- Claude Code version: 2.1.87
- OS: macOS (Darwin 25.3.0)
- MCP server:
mcp-postgres-full-accessvia npm exec - Usage pattern: Agent tool spawning multiple concurrent subagents with MCP database access
Impact
- Memory: ~44 MB per orphaned process, 1+ GB after heavy sessions
- Connections: Each process holds an open PostgreSQL connection
- Accumulation: Processes never self-terminate; they persist until manual kill or system restart
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗