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
/exit command
Subagents should be tracked and terminated when parent exits (e.g., via process group, or explicit cleanup on SIGINT/SIGTERM).
Related Issues
Impact
- Memory exhaustion over extended use
- System instability (swap thrashing, OOM kills)
- Users unaware of accumulating processes
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
~/.local/bin/claude)Steps to Reproduce
subagent_type=Explore,subagent_type=Plan)/exit, or let it crash/timeout)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:
In my case, after ~1 hour of active use, I had 20+ orphaned subagent processes, each consuming ~400 MB RAM (total ~8 GB).
Evidence
Workaround
Root Cause Hypothesis
The parent Claude Code process spawns subagents via
spawn()but there's no cleanup mechanism when:/exitcommandSubagents should be tracked and terminated when parent exits (e.g., via process group, or explicit cleanup on SIGINT/SIGTERM).
Related Issues
Impact