Orphaned processes after terminal close cause runaway memory consumption (34GB+ per instance)

Status Closed — not planned
Maintainer reply None cached
Activity 15 comments · opened Jan 10, 2026 · closed Feb 28, 2026

Description

When closing iTerm2 (and likely other terminals) without explicitly exiting Claude Code first, the node processes become orphaned instead of terminating. These orphaned processes then experience runaway memory consumption, each ballooning to ~34GB of V8 heap before crashing with OOM.

Environment

  • OS: macOS 15.5 (24F74)
  • Architecture: ARM64 (Mac16,13 - MacBook Air)
  • Terminal: iTerm2

Reproduction

  1. Open multiple iTerm2 windows/tabs with Claude Code sessions running
  2. Close iTerm2 (Cmd+Q or close windows) without explicitly exiting Claude Code
  3. Observe orphaned node processes consuming increasing amounts of RAM
  4. Eventually each process crashes with V8 OOM at ~34GB

Evidence from Crash Reports

Crash 1 (orphaned)

"pid" : 52713
"parentProc" : "Exited process"
Memory Tag 255: 34.3G (16,444 regions)

Crash 2 (orphaned)

"pid" : 40417
"parentProc" : "Exited process"  
Memory Tag 255: 34.3G (16,424 regions)

Stack trace shows V8 OOM:

node::OOMErrorHandler
  → v8::internal::V8::FatalProcessOutOfMemory
    → v8::internal::Heap::FatalProcessOutOfMemory
      → v8::internal::Heap::CollectGarbage

Impact

In one incident, 8+ Claude Code instances went to ~4GB each simultaneously before crashing, causing system-wide memory pressure and requiring a restart.

A separate incident spawned 10 rapid-fire subagent processes that all crashed with OOM within 30 seconds.

Expected Behavior

Claude Code should:

  1. Properly handle SIGHUP signal when terminal closes
  2. Terminate gracefully instead of becoming an orphan
  3. Not experience runaway memory allocation if orphaned

Workaround

Explicitly exit Claude Code before closing terminal windows:

  • Ctrl+C to interrupt
  • Or type /exit

View original on GitHub ↗

15 Comments

github-actions[bot] · 7 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/17219
  2. https://github.com/anthropics/claude-code/issues/1935
  3. https://github.com/anthropics/claude-code/issues/15975

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

gabrielbryk · 7 months ago

Having same issue

maxim-uvarov · 7 months ago

I have orphaned processes in zellij inside of wezterm. https://github.com/anthropics/claude-code/issues/18752

smconner · 7 months ago

🔗 Related: New trigger scenario

Found another way to trigger orphaned processes: context limit reached (without terminal close or /exit).

See #18981 — when the context percentage mismatch bug (#18241) causes premature "Context limit reached", background agents aren't cleaned up. Same symptom (orphaned process at 100%+ CPU), different trigger.

This suggests the cleanup mechanism may need to listen for multiple session-end signals, not just terminal/exit events.

PaulRBerg · 7 months ago

Also encountering this. It started happening after a recent update.

<img width="1305" height="707" alt="Image" src="https://github.com/user-attachments/assets/5181278a-097b-469d-bc49-db40e595f53a" />

yowmamasita · 7 months ago
AlexEzzeddine · 7 months ago

Also happening for me. When I close terminal tab, I expect claude code process to be killed

danneu · 7 months ago

I came to report the same issue.

I think it's a new regression in the native build since I think I would have noticed it weeks ago otherwise.

It should exit on sighup.

PaulRBerg · 7 months ago

@danneu it also happens with the npm build

Joowonoil · 7 months ago

Additional case report

Experiencing the same issue on macOS with iTerm2 and PyCharm integrated terminal.

Observed behavior

After closing terminals without explicitly exiting Claude Code, found 22+ orphan processes accumulated over several days:

username  63707 100.2 10.1 515016720 3397904   ??  R    Fri07AM  43:07.66 claude
username  63462  10.2  0.6 509344192 204832   ??  S    Fri07AM  69:49.41 claude
username  73132   7.8  0.6 510144016 196144   ??  S    Fri09AM  59:50.86 claude
... (20+ more processes dating back several days)
  • Top process using 100% CPU and 3.4GB memory
  • Processes from Thursday and Friday still running on Saturday
  • Combined memory usage was several GB

Environment

  • macOS Darwin 25.2.0
  • iTerm2 + PyCharm terminal
  • preferredNotifChannel: "iterm2_with_bell"

Workaround

I created a simple cleanup tool for macOS users:

👉 claude-code-cleanup - Double-click to run, shows running processes, and kills orphaned ones.

Or use terminal:

# Kill all orphan Claude processes
pkill -9 claude

Prevention

Until this is fixed, exit Claude Code properly before closing terminal:

  • Type /exit
  • Or Ctrl+C then Ctrl+D

+1 for implementing proper SIGHUP handling.

Joowonoil · 7 months ago

Update: This issue appears to be fixed in v2.1.19.

I was on v2.1.15 and upgraded via brew upgrade claude. After the update, orphan processes no longer seem to persist when closing the terminal.

Can others confirm?

PaulRBerg · 7 months ago

yeah it's fixed in v2.1.19

jikuya · 7 months ago

Additional reproduction case: Subagents not terminated on Ctrl+C

Environment

  • OS: macOS 15.3.1 (Darwin 25.2.0)
  • Terminal: iTerm2
  • Claude Code: 2.1.x

Observation

Even when explicitly terminating Claude Code with Ctrl+C, subagent processes (spawned via the Task tool) are not terminated and become orphaned.

In my case, I found 154 orphaned Claude Code processes after several sessions were closed with Ctrl+C over the course of a day.

$ ps aux | grep -c "/Users/.../.local/bin/claude"
154

Breakdown:

  • ~120 processes with --output-format stream-json flags (subagents)
  • ~30 main session remnants

System Impact

  • Load Average: 140+ (normal: ~8)
  • CPU idle: 0.6%
  • Memory: 15GB used, only 76MB free
  • Compressor: 7.8GB (heavy swapping)

Root Cause

The issue appears to be that SIGINT (Ctrl+C) is not propagated to child processes spawned by the Task tool. When the parent process terminates, these subagents become orphaned instead of being cleaned up.

Suggested Fix

  1. Register signal handlers in the main process to forward SIGINT/SIGTERM/SIGHUP to all child processes
  2. Use process groups (setpgid) so the entire process tree can be terminated together
  3. Implement cleanup logic in the main process that tracks and terminates spawned subagents on exit

Workaround

Manual cleanup of orphaned processes:

pkill -f "claude.*stream-json"

Or periodic monitoring:

ps aux | grep claude | wc -l
github-actions[bot] · 6 months ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] · 5 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.