Task tool subagents become orphans when parent session crashes

Resolved 💬 3 comments Opened Jan 25, 2026 by MrSaneApps Closed Jan 29, 2026

Problem

When a Claude Code session crashes (OOM, network timeout, user interrupt), subagent processes spawned by the Task tool become orphaned and continue running indefinitely, consuming memory.

Reproduction

  1. Start a Claude Code session
  2. Use the Task tool to spawn a subagent
  3. Kill the parent session (e.g., kill -9 or let it OOM)
  4. Observe the --resume process still running:

``
ps aux | grep 'claude.*--resume'
``

Example orphaned process

/Users/user/.local/bin/claude --output-format stream-json --verbose \
  --input-format stream-json --model claude-sonnet-4-5 \
  --resume 9c33ca78-1244-4e57-8cc8-184e144261c7 \
  --disallowedTools Bash,Read,Write,Edit,... \
  --permission-mode default

Impact

  • Each orphaned subagent holds ~300-400MB RAM
  • Multiple crashed sessions compound the leak
  • Users hit OOM conditions, causing more crashes, spawning more orphans
  • Workaround requires manual cleanup: pkill -f 'claude.*--resume'

Suggested fixes

  1. Process groups: Spawn subagents in the same process group as parent so SIGHUP propagates on parent death
  1. Heartbeat/watchdog: Subagents periodically check if parent is alive (e.g., via parent PID or IPC), self-terminate if not
  1. Cleanup on startup: Claude Code could kill stale --resume processes from previous sessions on startup (with appropriate staleness check)

Environment

  • macOS 15 (Darwin 25.2.0)
  • Claude Code CLI
  • Apple Silicon

View original on GitHub ↗

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