Claude Code CLI: Orphaned processes cause unbounded memory growth (10GB+ on macOS)
Summary
Claude Code CLI processes launched with --resume in interactive terminal mode become orphaned when their parent shell exits. These orphaned processes continue running indefinitely with PPID=1 (adopted by launchd), accumulating memory without bound. One process reached 10.24 GB of memory on a 16GB M4 MacBook Air, causing significant system heat and performance degradation.
Environment
- OS: macOS 15 (Darwin 25.2.0)
- Hardware: Apple M4 Air, 16GB RAM
- Claude Code Version: 2.1.15
- Claude Desktop App: 1.1.886
- Shell: zsh
- Terminal: macOS Terminal.app
Steps to Reproduce
- Open a terminal and start Claude Code:
``bash``
claude --model claude-opus-4-5-20251101
- Use the session, note the session ID.
- Open additional terminal tabs and resume the same session:
``bash``
claude --resume <session-id> --model claude-opus-4-5-20251101
- Close the terminal windows/tabs (Cmd+W or close Terminal app) without explicitly exiting the
claudeprocess (Ctrl+C or/exit). - Observe that the
claudeprocesses continue running as orphans.
Observed Behavior
Three orphaned Claude Code processes were found running, all resuming the same session:
| PID | PPID | RSS | Terminal | CPU Time |
|-----|------|-----|----------|----------|
| 16234 | 1 | ~3.0 GB (Activity Monitor: 10.24 GB) | s005 | 111 min |
| 47609 | 1 | ~390 MB | s007 | 29 min |
| 98485 | 1 | ~77 MB | s008 | 17 min |
All three had PPID=1 (launchd), confirming their parent shells had exited.
PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
16234 49.8 11.2 521416592 1886208 s005 Rs+ 12:36AM 111:21.35 claude --resume 27033d6e-... --model claude-opus-4-5-20251101
47609 0.1 2.3 509698480 388688 s007 Rs+ 9:39PM 29:18.43 claude --resume 27033d6e-... --model claude-opus-4-5-20251101
98485 0.0 0.5 510105968 76736 s008 Ss+ Mon09PM 17:39.44 claude --resume 27033d6e-... --model claude-opus-4-5-20251101
Key observations:
- PID 16234 was consuming 49.8% CPU continuously
- Memory was actively growing — RSS increased from 1.8 GB to 3.0 GB within minutes of observation
- The process had been running for ~23 hours
- Activity Monitor reported 10.24 GB for the largest process
Expected Behavior
When a parent terminal/shell exits, the Claude Code CLI process should:
- Detect that stdin/the controlling terminal is gone (SIGHUP)
- Gracefully shut down and release all resources
- Not continue running as an orphan accumulating memory indefinitely
Root Cause Analysis
The Claude Code CLI (Node.js binary) does not properly handle:
- SIGHUP signal — When the parent terminal closes, the shell sends SIGHUP to its child processes. The
claudeprocess either ignores SIGHUP or doesn't have a handler that triggers shutdown.
- Detached stdin — When the controlling terminal is gone, stdin becomes invalid. The process should detect this and exit, but instead continues running.
- Memory leak in long-running sessions — Even if orphaning were intended, the process exhibits unbounded memory growth (76 MB → 390 MB → 3+ GB over time), suggesting a memory leak in the Node.js runtime.
Impact
- Memory exhaustion: 10.24 GB consumed (64% of 16GB total RAM)
- CPU waste: 49.8% CPU consumed continuously with no purpose
- Thermal throttling: MacBook Air M4 noticeably hot
- Silent failure: No user-visible indication; only discoverable via Activity Monitor or
ps
Workaround
# Find orphaned claude processes
ps -eo pid,ppid,rss,command | grep "claude" | awk '$2 == 1' | grep -v "Claude.app"
# Kill them
kill <PID>This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗