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
- Start a Claude Code session
- Use the
Tasktool to spawn a subagent - Kill the parent session (e.g.,
kill -9or let it OOM) - Observe the
--resumeprocess 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
- Process groups: Spawn subagents in the same process group as parent so
SIGHUPpropagates on parent death
- Heartbeat/watchdog: Subagents periodically check if parent is alive (e.g., via parent PID or IPC), self-terminate if not
- Cleanup on startup: Claude Code could kill stale
--resumeprocesses from previous sessions on startup (with appropriate staleness check)
Environment
- macOS 15 (Darwin 25.2.0)
- Claude Code CLI
- Apple Silicon
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗