[BUG] Task tool subagent processes not terminated after parent session ends (Linux)
Description
Task tool subagent processes (claude --resume <session-id>) are not terminated when the parent Claude Code session ends (via crash, Ctrl+C, timeout, or normal exit). These orphaned processes accumulate over time and consume significant RAM.
Environment
- Claude Code version: Latest (via
~/.local/bin/claude) - OS: Linux Mint 22 / Ubuntu 24.04 (kernel 6.14.0-37-generic)
- RAM: 16 GB
- Shell: Bash
Steps to Reproduce
- Start a Claude Code session
- Use the Task tool multiple times (e.g.,
subagent_type=Explore,subagent_type=Plan) - End the session (Ctrl+C,
/exit, or let it crash/timeout) - Check running processes:
ps aux | grep "claude.*--resume"
Expected Behavior
All subagent processes should be terminated when the parent session ends.
Actual Behavior
Subagent processes persist as orphans with this signature:
/home/user/.local/bin/claude --output-format stream-json --verbose --input-format stream-json --model claude-sonnet-4-5 --resume <SESSION-ID> --disallowedTools Bash,Read,Write,Edit,Grep,Glob,WebFetch,WebSearch,Task,NotebookEdit,AskUserQuestion,TodoWrite --setting-sources --permission-mode default
In my case, after ~1 hour of active use, I had 20+ orphaned subagent processes, each consuming ~400 MB RAM (total ~8 GB).
Evidence
$ ps aux --sort=-%mem | grep claude | head -20
# Output showed 20+ processes with --resume flag, ~400MB RSS each
$ free -h
# Before cleanup: 9.6 GB used, 1.3 GB swap
# After pkill -f "claude.*--resume": 3.4 GB used, 643 MB swap
# ~6 GB RAM freed
Workaround
# Kill all orphaned subagents manually
pkill -f "claude.*--resume"
Root Cause Hypothesis
The parent Claude Code process spawns subagents via spawn() but there's no cleanup mechanism when:
- Parent session crashes
- User exits with Ctrl+C
- Session times out
- Normal
/exitcommand
Subagents should be tracked and terminated when parent exits (e.g., via process group, or explicit cleanup on SIGINT/SIGTERM).
Related Issues
- #15975 - Zombie node processes on macOS (similar but different process type)
- #7020 - Memory leak during subagent orchestration (memory during session, not after)
- #8382 - Parallel Task() memory issues (closed as duplicate)
Impact
- Memory exhaustion over extended use
- System instability (swap thrashing, OOM kills)
- Users unaware of accumulating processes
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗