Subagent processes not cleaned up after session ends

Resolved 💬 3 comments Opened Apr 14, 2026 by hmennen90 Closed Apr 17, 2026

Description

When using the Agent tool extensively (e.g., Explore, Plan subagents), the spawned subagent processes are not reliably cleaned up after they complete or when the parent session ends. Over multiple sessions, this leads to dozens or even hundreds of orphaned claude --resume processes accumulating.

Reproduction

  1. Start a Claude Code session
  2. Use Agent tool multiple times (Explore, Plan, etc.)
  3. End the session
  4. Start new sessions and repeat
  5. Run ps aux | grep 'claude.*--resume' | wc -l

After a day of normal usage, I had 97 orphaned subagent processes consuming significant CPU and memory.

Impact

  • High CPU usage from zombie processes (each process consumes ~10% CPU)
  • Memory pressure (each process ~60-200MB RSS)
  • On laptops: contributes to thermal throttling
  • Users may not notice until system becomes sluggish

Expected Behavior

Subagent processes should be terminated when:

  • The subagent task completes and results are returned
  • The parent session ends
  • The parent session is interrupted

Workaround

Adding a SessionStart hook to settings.json:

{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "pkill -f 'claude.*--resume' 2>/dev/null; exit 0"
          }
        ]
      }
    ]
  }
}

Environment

  • Claude Code: latest (installed via npm)
  • macOS 26.4.1 (Apple Silicon + Intel)
  • Heavy Agent tool usage (Explore, Plan subagents)

View original on GitHub ↗

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