[BUG] Severe Memory Leak (20GB+)
Status Closed — not planned
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 11 comments · opened Nov 25, 2025 · closed Feb 5, 2026
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?
cli using insane amount of memory
<img width="832" height="57" alt="Image" src="https://github.com/user-attachments/assets/1c278c0a-fde7-443c-bee9-6f7f00ee356b" />
Context Usage
Model: claude-opus-4-5-20251101
Tokens: 74.3k / 200.0k (37%)
Categories
Category Tokens Percentage
System prompt 3.0k 1.5%
System tools 13.5k 6.8%
Messages 12.8k 6.4%
Free space 125.7k 62.8%
Autocompact buffer 45.0k 22.5%
What Should Happen?
cli should not be using 20GB of RAM.
Error Messages/Logs
Steps to Reproduce
Don't know how to reproduce, it randomly happens - cant see any particular thing that causes
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.0.53
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
11 Comments
---
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
---
I actually will reopen this, as the others are saying after some time this happens, but for me, this is happening as soon as I open my project. Granted, it is a large project, but as soon as I open the project folder in VS Code, Instantly goes up to 20+ GB RAM, don't even have to type a message into the claude extention.
Memory Leak Analysis: 20GB RAM Usage
20GB for a CLI tool is absurd. Here's what's likely happening and how to fix/mitigate it.
Root Causes (Most Likely → Least Likely)
1. Conversation History Not Being Garbage Collected
Claude Code keeps entire conversation history in memory, including:
With Opus 4.5 and 74k tokens in context, if each message averages 2-3KB and you have images, this adds up fast.
Fix: Clear history periodically
2. Screenshot/Image Buffer Accumulation
Computer use tools take screenshots → base64 encode → store in memory. If you're using computer use heavily, each screenshot is ~1-2MB encoded.
Mitigation: Reduce screenshot quality in tools config
(Note: Check if Claude Code actually supports this config - it might not exist yet)
3. Node.js/Bun Memory Management
Check which runtime you're using:
If it's Bun: Bun's GC can be aggressive. Try:
If it's Node: Add memory limits:
Diagnostic Steps
1. Track memory over time:
Watch for steady increase → leak
Watch for spikes during specific actions → identify trigger
2. Profile with heap dump (advanced):
3. Check for zombie processes:
Sometimes tool executions (bash, python scripts) don't terminate properly.
Temporary Workarounds
Option A: Restart frequently
If memory hits 10GB, Ctrl+D and it auto-restarts.
Option B: Memory limit with Docker (extreme but works)
Option C: Run in VM with memory monitoring
What Data Would Help Debug This
If you can share:
kill -USR2 <pid>generates one/configoutput: Shows what's enabled (extended thinking, MCP servers, etc.)Long-term Fix (Needs Anthropic Team)
The proper fix is to:
--max-memoryflag: Let users cap memory usageThis needs core changes to how Claude Code manages state.
Immediate Action
Try this and report back:
If memory grows >500MB/hour without heavy usage, it's definitely a leak. Share the output curve and I can narrow down the cause further.
An AI generated response on a Github issue for an AI, because I can't use my AI, what a world.
@StuBedore Welcome to the Desert of the REAL. Its the agentic world now. Embrace it!
Still not fixed in 2.0.56 - here's my bug report:
Bug Report: Memory Leak in Claude Code v2.0.56 (Native Binary)
Title
Severe memory leak in Claude Code native binary - consumes all available RAM from startup (clean session, no messages)
Environment
| Component | Value |
|---------------------|---------------------------------------------------------|
| Claude Code Version | 2.0.56 |
| Installation Method | Native binary (ELF x86-64) |
| Binary Path | /home/worker/.local/share/claude/versions/2.0.56 |
| Binary MD5 | 0e1cf4775d5e2da4a4768436a23d9804 |
| Build ID | 3f1c142d4ee369512790723d9eb81539dcfdf9dd |
| OS | Ubuntu 22.04.5 LTS (Jammy Jellyfish) |
| Kernel | 6.8.0-87-generic #88~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC |
| Architecture | x86_64 |
| CPU | Intel Core i7-8650U @ 1.90GHz (8 cores, 2 threads/core) |
| Total RAM | 32 GB |
| Swap | 2 GB |
Shared Libraries
linux-vdso.so.1
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
/lib64/ld-linux-x86-64.so.2
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
Description
Starting Claude Code initiates a continuous memory leak that steadily consumes RAM regardless of conversation activity. The process will eventually exhaust all physical memory if left running.
Observed Behavior
After ~4 minutes of runtime with minimal conversation:
| Metric | Value |
|-------------------------|-------------------------|
| RSS (Resident Set Size) | 14.5 GB (and growing) |
| Virtual Memory Size | 74.7 GB |
| Peak Virtual Memory | 135.5 GB |
| VmData (heap/data) | 69.9 GB |
| Anonymous Memory | 15.3 GB |
| Private Dirty Pages | 15.3 GB |
| CPU Usage | 89-93% |
| Threads | 19 |
| Memory Mappings | 4,173 anonymous regions |
Key Observations
Steps to Reproduce
Expected Behavior
Memory usage should remain relatively stable during idle periods or scale modestly with conversation context size.
Actual Behavior
Memory grows continuously from ~500MB at startup to multiple gigabytes within minutes, eventually consuming all available RAM.
Configuration
~/.claude/settings.json:
{
"alwaysThinkingEnabled": false
}
Install stats (from ~/.claude.json):
Workarounds Attempted
None effective - the leak appears fundamental to the process execution.
Impact
Additional Context
The 4,173 anonymous memory mappings (vs 6 mappings each for shared libraries) strongly suggests unbounded heap allocation - possibly a loop creating objects without cleanup, or a growing data
structure that's never freed.
I think it might be the updater.
This is in a tiny VM so it fails fast.
Just starting c.c. and doing nothing, I get OOM in a few seconds. Note that I'm a couple of point versions out of date:
vs:
Disabling the autoupdater seems to fix.
Manually updating (still with autoupdates disabled) also dies fast:
So I suspect something is going haywire in the update process.
Edit: I mean to add this comment on #12987 - but it seems relevant here, too.
Not sure why, but i've also got massive issues with claude code consuming massive amounts of memory on my osx mac. started happening about 1-2 weeks ago
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
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.