Subagent and MCP server processes are not reclaimed after task completion, causing high memory usage
Resolved 💬 3 comments Opened Mar 27, 2026 by Platanus-max Closed Mar 27, 2026
Problem
Claude Code maintains multiple Node.js child processes (subagents, MCP servers) throughout a session's lifetime, even after the corresponding tasks have completed. These idle processes continue to consume memory unnecessarily.
Observed Behavior
- When subagents finish their tasks, the spawned Node.js processes remain alive instead of being terminated
- MCP server processes are started at session init and persist until session end, regardless of whether they are actively being used
- Over the course of a long session, memory usage grows significantly due to accumulated idle processes
- Each Node.js process carries ~30-50MB of baseline overhead (V8 heap, loaded modules, event loop), so a handful of orphaned processes can easily add hundreds of MB
Expected Behavior
- Subagent processes should be terminated promptly after their task completes
- MCP server processes should support idle timeout — spin up on demand, shut down after a configurable period of inactivity
- Overall process lifecycle should be actively managed to prevent unnecessary memory accumulation
Reproduction
- Start a Claude Code session with multiple MCP servers configured
- Run several tasks that spawn subagents
- After tasks complete, check process list (
tasklist | grep nodeon Windows,ps aux | grep nodeon Unix) - Observe that completed subagent processes and unused MCP server processes are still running
Suggestion
- Implement process cleanup for subagents upon task completion
- Add idle timeout mechanism for MCP servers (e.g., terminate after N minutes of no tool calls, restart on next invocation)
- Consider a process pool with an upper bound to cap total memory usage
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗