[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
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Environment
| Component | Version |
|---|---|
| Claude Code CLI | 2.1.126 and 2.1.128 (both extensions installed concurrently in ~/.vscode/extensions/) |
| VSCode | 1.118.1 |
| OS | macOS 26.4.1 (Build 25E253) |
| Architecture | arm64e (Apple Silicon, Mac16,12) |
| RAM | 16 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.)
| PID | Footprint | Time Since Fork | Notes |
|---:|---:|---:|---|
| 51131 | 444.4 MB | 584,578 s | 6.77 days old |
| 51923 | 443.0 MB | 584,524 s | 6.77 days old |
| 53298 | 443.5 MB | 584,401 s | 6.76 days old |
| 54558 | 441.4 MB | 584,318 s | 6.76 days old |
| 56212 | 416.3 MB | 584,216 s | 6.76 days old |
| 29307 | 1250.7 MB | 81,053 s | 22.5 hours old |
| 33090 | 1251.2 MB | 80,617 s | 22.4 hours old |
| 34325 | 1250.5 MB | 80,515 s | 22.4 hours old |
| 34941 | 786.9 MB | 80,456 s | 22.3 hours old |
| 35400 | 1142.0 MB | 80,408 s | 22.3 hours old |
| 35644 | 1128.7 MB | 80,382 s | 22.3 hours old |
| 36354 | 1253.2 MB | 80,300 s | 22.3 hours old |
| 52518 | 1230.9 MB | 77,915 s | 21.6 hours old |
| 66982 | 1251.8 MB | 76,805 s | 21.3 hours old |
| 90005 | 1256.2 MB | 73,239 s | 20.3 hours old |
| 5070 | 1233.4 MB | 72,026 s | 20.0 hours old |
| 6407 | 1132.2 MB | 71,922 s | 20.0 hours old |
| 13473 | 1255.2 MB | 71,305 s | 19.8 hours old |
| 13753 | 549.6 MB | 71,283 s | 19.8 hours old |
| 20057 | 1252.8 MB | 70,672 s | 19.6 hours old |
| 98887 | 307.2 MB | 92 s | freshly spawned |
| 98920 | 115.9 MB | 85 s | freshly spawned |
| 98983 | 101.4 MB | 64 s | freshly 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 cohort | Avg 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
- Install Claude Code extension in VSCode (
anthropic.claude-codev2.1.128). - Open a workspace, launch
claudein the integrated terminal, have a brief conversation (does not need to be heavy). - Open a different project in a new VSCode window. Repeat step 2.
- Continue this pattern across ~5–10 projects over a week of normal work.
- Periodically: close VSCode windows, switch projects, let the laptop sleep overnight.
- After several days, run:
``bash``
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
claudeprocess 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-orphanswould 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
- Signal handling: verify the CLI's SIGHUP/SIGTERM behavior in
stream-jsonmode — does the--input-format stream-jsonmode change parent-death handling? - Detachment: check whether the CLI is calling
setsid()or otherwise dissociating from its controlling terminal. - 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.
- 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗