Skip to content

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

Closed as not planned

Description

@thomascassidyzm

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

Activity

  1. github-actions commented on Jan 10, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. [BUG] Found 30+ "2.1.1" processes in my Activity Monitor, despite having 3 Terminals open. #17219
    2. [BUG] MCP servers not properly terminated when Claude Code exits, causing orphaned processes #1935
    3. [BUG] v2.0.76 on Apple Silicon: AVX warning + spawns 40+ zombie node processes causing OOM #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

  2. gabrielbryk commented on Jan 13, 2026

    @gabrielbryk

    Having same issue

  3. maxim-uvarov commented on Jan 17, 2026

    @maxim-uvarov

    I have orphaned processes in zellij inside of wezterm. #18752

  4. smconner commented on Jan 18, 2026

    @smconner

    🔗 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.

  5. PaulRBerg commented on Jan 18, 2026

    @PaulRBerg

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

    Image
  6. yowmamasita commented on Jan 18, 2026

    @yowmamasita
  7. AlexEzzeddine commented on Jan 19, 2026

    @AlexEzzeddine

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

  8. danneu commented on Jan 20, 2026

    @danneu

    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.

  9. PaulRBerg commented on Jan 20, 2026

    @PaulRBerg

    @danneu it also happens with the npm build

  10. Joowonoil commented on Jan 24, 2026

    @Joowonoil

    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.

  11. Joowonoil commented on Jan 24, 2026

    @Joowonoil

    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?

  12. PaulRBerg commented on Jan 24, 2026

    @PaulRBerg

    yeah it's fixed in v2.1.19

  13. jikuya commented on Jan 30, 2026

    @jikuya

    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
  14. github-actions commented on Feb 28, 2026

    @github-actions

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

  15. github-actions commented on Mar 8, 2026

    @github-actions

    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.

  16. locked as resolved and limited conversation to collaborators on Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions