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

  1. Start a Claude Code session with multiple MCP servers configured
  2. Run several tasks that spawn subagents
  3. After tasks complete, check process list (tasklist | grep node on Windows, ps aux | grep node on Unix)
  4. 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

View original on GitHub ↗

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