claude-code - 💡(How to fix) Fix [BUG] Memory leak, Claude Code CLI sessions persist for days in VSCode integrated terminal, each consuming up to 1.25 GB until host runs out of RAM [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56323Fetched 2026-05-06 06:31:11
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×6commented ×1

When running claude inside the VSCode integrated terminal across multiple project folders over time, CLI sessions are not cleaned up when their hosting terminal panel is closed or when the user walks away. Each session continues to grow in memory footprint, monotonically, until the system is exhausted.

On 2026-05-05 my Mac became completely unresponsive (WindowServer watchdog timeout) and required a hard reset. Forensic analysis of the macOS spin report (/Library/Logs/DiagnosticReports/WindowServer_2026-05-05-100644_MacBook-Air.userspace_watchdog_timeout.spin) revealed 23 zombie claude Node processes consuming a combined 19.47 GB of memory footprint on a 16 GB machine.


Error Message

Error Messages/Logs

Root Cause

When running claude inside the VSCode integrated terminal across multiple project folders over time, CLI sessions are not cleaned up when their hosting terminal panel is closed or when the user walks away. Each session continues to grow in memory footprint, monotonically, until the system is exhausted.

On 2026-05-05 my Mac became completely unresponsive (WindowServer watchdog timeout) and required a hard reset. Forensic analysis of the macOS spin report (/Library/Logs/DiagnosticReports/WindowServer_2026-05-05-100644_MacBook-Air.userspace_watchdog_timeout.spin) revealed 23 zombie claude Node processes consuming a combined 19.47 GB of memory footprint on a 16 GB machine.


Fix Action

Fix / Workaround

Workaround for affected users (in the meantime)

Adding this to a daily launchd job is a reasonable mitigation while the underlying issue is investigated.

Code Example

claude --output-format stream-json --verbose --input-format stream-json \
  --effort max --model claude-opus-4-7[1m] --permission-prompt-tool stdio \
  --allowedTools mcp__computer-use,mcp__ccd_session__spawn_task,...  \
  --setting-sources=user,project,local --permission-mode default \
  --allow-dangerously-skip-permissions --include-partial-messages \
  --plugin-dir ... --replay-user-messages --settings {}

---



---

ps aux | grep "claude.*stream-json" | grep -v grep

---

# Identify zombie sessions
ps -eo pid,etime,rss,command | grep "claude.*stream-json" | grep -v grep

# Kill all zombie Claude Code CLI sessions
pkill -f "claude.*--output-format stream-json"
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Environment

ComponentVersion
Claude Code CLI2.1.126 and 2.1.128 (both extensions installed concurrently in ~/.vscode/extensions/)
VSCode1.118.1
OSmacOS 26.4.1 (Build 25E253)
Architecturearm64e (Apple Silicon, Mac16,12)
RAM16 GB

CLI invocation (full args from ps):

claude --output-format stream-json --verbose --input-format stream-json \
  --effort max --model claude-opus-4-7[1m] --permission-prompt-tool stdio \
  --allowedTools mcp__computer-use,mcp__ccd_session__spawn_task,...  \
  --setting-sources=user,project,local --permission-mode default \
  --allow-dangerously-skip-permissions --include-partial-messages \
  --plugin-dir ... --replay-user-messages --settings {}

Summary

When running claude inside the VSCode integrated terminal across multiple project folders over time, CLI sessions are not cleaned up when their hosting terminal panel is closed or when the user walks away. Each session continues to grow in memory footprint, monotonically, until the system is exhausted.

On 2026-05-05 my Mac became completely unresponsive (WindowServer watchdog timeout) and required a hard reset. Forensic analysis of the macOS spin report (/Library/Logs/DiagnosticReports/WindowServer_2026-05-05-100644_MacBook-Air.userspace_watchdog_timeout.spin) revealed 23 zombie claude Node processes consuming a combined 19.47 GB of memory footprint on a 16 GB machine.


Evidence: full process table from spin report

Source: macOS userspace_watchdog_timeout spin report captured 2026-05-05 10:06:17 UTC-4, ~4 minutes before forced reboot at 10:10.

Filter: only node processes from /opt/homebrew/*/node with footprint > 100 MB. (All instances confirmed identical via UUID 4EC815EE-775A-3897-BA9A-A5C28EB9D16D and same Codesigning ID.)

PIDFootprintTime Since ForkNotes
51131444.4 MB584,578 s6.77 days old
51923443.0 MB584,524 s6.77 days old
53298443.5 MB584,401 s6.76 days old
54558441.4 MB584,318 s6.76 days old
56212416.3 MB584,216 s6.76 days old
293071250.7 MB81,053 s22.5 hours old
330901251.2 MB80,617 s22.4 hours old
343251250.5 MB80,515 s22.4 hours old
34941786.9 MB80,456 s22.3 hours old
354001142.0 MB80,408 s22.3 hours old
356441128.7 MB80,382 s22.3 hours old
363541253.2 MB80,300 s22.3 hours old
525181230.9 MB77,915 s21.6 hours old
669821251.8 MB76,805 s21.3 hours old
900051256.2 MB73,239 s20.3 hours old
50701233.4 MB72,026 s20.0 hours old
64071132.2 MB71,922 s20.0 hours old
134731255.2 MB71,305 s19.8 hours old
13753549.6 MB71,283 s19.8 hours old
200571252.8 MB70,672 s19.6 hours old
98887307.2 MB92 sfreshly spawned
98920115.9 MB85 sfreshly spawned
98983101.4 MB64 sfreshly spawned

Aggregate: 23 sessions, 19.47 GB total, average 866.9 MB/session, max 1256.2 MB.

What Should Happen?

The two critical observations

1. Sessions persist for days

Five sessions were running for 6.77 days continuously. These were started on 2026-04-28 and survived through:

  • Multiple VSCode window closes
  • VSCode itself restarting (the integrated terminals would have closed)
  • A laptop sleep/wake cycle

This indicates the CLI is not receiving or honoring SIGHUP when its parent terminal closes, OR is detaching from the parent.

2. Memory grows monotonically with time

Plotting footprint vs. uptime shows a clear correlation:

Age cohortAvg footprint
<2 minutes (3 procs)174.8 MB
~20 hours (15 procs)1149.1 MB
~6.8 days (5 procs)437.7 MB

The 6.8-day cohort is anomalously lower than the 20-hour cohort. One hypothesis: those older sessions were spawned by an older Claude Code version (2.1.126) which may have had different memory characteristics, while the newer 20-hour cohort uses 2.1.128. Still, the within-cohort consistency (all 20-hour sessions converge to ~1.1–1.25 GB regardless of actual usage) strongly suggests an internal cap or growth pattern that doesn't release.

Error Messages/Logs

Steps to Reproduce

Reproduction steps

  1. Install Claude Code extension in VSCode (anthropic.claude-code v2.1.128).
  2. Open a workspace, launch claude in the integrated terminal, have a brief conversation (does not need to be heavy).
  3. Open a different project in a new VSCode window. Repeat step 2.
  4. Continue this pattern across ~5–10 projects over a week of normal work.
  5. Periodically: close VSCode windows, switch projects, let the laptop sleep overnight.
  6. After several days, run:
    ps aux | grep "claude.*stream-json" | grep -v grep
    Observe many surviving sessions, each consuming hundreds of MB to >1 GB.

Claude Model

Opus

Is this a regression?

No, this never worked

Last Working Version

No response

Claude Code Version

2.1.126 and 2.1.128

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

VS Code integrated terminal

Additional Information

Expected behavior

  • When the hosting terminal panel/tab is closed, the claude process should receive SIGHUP and exit cleanly within a reasonable timeout.
  • Per-session memory should be bounded; an idle session should not grow over time.
  • If a session must persist across UI closures, there should be a clear mechanism to discover and terminate them (a claude --list-sessions / claude --kill-orphans would be ideal).

Actual behavior

  • Sessions survive for days regardless of UI state.
  • Memory grows from ~100 MB at fork time toward what appears to be a ~1.25 GB plateau within ~20 hours of being alive (even when idle / not in foreground).
  • No user-visible inventory of running sessions; the only way I discovered this was via post-mortem of a kernel watchdog timeout.

Impact

System hard-locked, requiring forced reboot. Lost in-flight work in multiple applications. Workflow on a 16 GB machine becomes essentially unsustainable: 23 idle Claude Code sessions consumed 122% of physical RAM, before counting VSCode itself (~9 GB across 37 helper processes), Chrome (~3 GB), and Podman/krunkit (3.9 GB).

This is not a "machine is underspecced" issue — 16 GB is the most common configuration for Apple Silicon Macs sold in 2024–2026 and a fully supported developer environment per Anthropic docs.


Suggested investigation paths

  1. Signal handling: verify the CLI's SIGHUP/SIGTERM behavior in stream-json mode — does the --input-format stream-json mode change parent-death handling?
  2. Detachment: check whether the CLI is calling setsid() or otherwise dissociating from its controlling terminal.
  3. Memory growth: profile a long-lived idle session (e.g., 24h) to identify what's growing — likely candidates are transcript buffers, MCP server response cache, or accumulating event listeners on the streaming JSON parser.
  4. Self-cleanup: consider an idle-timeout that terminates sessions inactive for >N hours, with a clear UX signal (banner / log line) before exit.

Workaround for affected users (in the meantime)

# Identify zombie sessions
ps -eo pid,etime,rss,command | grep "claude.*stream-json" | grep -v grep

# Kill all zombie Claude Code CLI sessions
pkill -f "claude.*--output-format stream-json"

Adding this to a daily launchd job is a reasonable mitigation while the underlying issue is investigated.

extent analysis

TL;DR

The most likely fix is to implement proper signal handling and detachment in the Claude Code CLI to ensure it exits cleanly when its parent terminal closes.

Guidance

  • Investigate the signal handling behavior of the Claude Code CLI in stream-json mode to verify if it properly handles SIGHUP and SIGTERM signals.
  • Check if the CLI is detaching from its controlling terminal using setsid() or similar methods, which could prevent it from receiving signals.
  • Profile a long-lived idle session to identify the cause of memory growth, focusing on potential issues like transcript buffers, MCP server response cache, or event listeners on the streaming JSON parser.
  • Consider implementing an idle-timeout mechanism that terminates inactive sessions after a certain period, providing a clear UX signal before exit.

Example

No specific code example is provided due to the lack of explicit code details in the issue. However, a potential solution might involve modifying the CLI's signal handling to properly exit when its parent terminal closes.

Notes

The provided workaround using pkill can help mitigate the issue temporarily, but a more robust solution requires addressing the underlying signal handling and detachment issues in the Claude Code CLI.

Recommendation

Apply the workaround using pkill as a temporary mitigation while investigating and implementing a proper fix for the signal handling and detachment issues in the Claude Code CLI. This will help prevent system crashes due to excessive memory consumption by idle Claude Code sessions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

  • When the hosting terminal panel/tab is closed, the claude process should receive SIGHUP and exit cleanly within a reasonable timeout.
  • Per-session memory should be bounded; an idle session should not grow over time.
  • If a session must persist across UI closures, there should be a clear mechanism to discover and terminate them (a claude --list-sessions / claude --kill-orphans would be ideal).

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING