Repository navigation
Description
Claude Code CLI - Memory Leak Critical Bug Report
Date: 2026-01-28 04:45 UTC
Reporter: Rickard Wilhelmsson (wilhelmsson424@gmail.com)
Claude Code Version: Latest (2.1.21)
OS: Linux 6.6.87.2-microsoft-standard-WSL2 (WSL2)
RAM: 16GB total
🚨 CRITICAL: Claude process freezes after 20+ minutes, consuming 15GB RAM
Incident Summary
11th occurrence of Claude process completely freezing, requiring force kill (kill -9).
Symptom: Claude CLI becomes unresponsive, consuming 90%+ of system RAM, making entire system unusable.
Technical Details
Process Analysis (PID 718 - frozen instance):
VmSize: 89738368 kB (87.6 GB virtual memory)
VmRSS: 15024756 kB (14.7 GB resident memory)
Threads: 20
Open files: 371
Runtime: 40 minutes (frozen at 04:05-04:45)
CPU: 46.6% (stuck in processing loop)
Memory State at Freeze:
Total RAM: 15Gi
Used: 15Gi (100%)
Available: 46Mi (0.3%)
Swap: 2.8Gi used of 4.0Gi
Root Cause Analysis
Evidence from ~/.claude.json (project config):
{
"numStartups": 303,
"lastTotalCacheReadInputTokens": 9656824, // 9.6 MILLION tokens
"lastTotalCacheCreationInputTokens": 367980,
"lastTotalInputTokens": 187950,
"lastCost": 4.7301332
}Findings:
-
Unbounded cache growth:
- Claude reads 9.6M tokens from conversation cache
- ~35 MB raw text → 15GB in-memory after parsing/compilation
- No garbage collection implemented
- No cache size limits enforced
-
Memory leak pattern:
- Each session accumulates conversation history
- After 303 startups, cache grows to critical size
- Process never releases memory
- Leads to swap thrashing → I/O bottleneck → freeze
-
No recovery mechanism:
- Once frozen, process cannot self-recover
- Requires manual kill -9
- Other Claude windows also affected (shared memory?)
Reproduction Steps
- Use Claude Code CLI extensively over weeks (300+ sessions)
- Work on complex tasks with long conversations
- Let conversation history accumulate (9M+ tokens cached)
- Start new session → Memory usage spikes to 15GB
- After 20-40 minutes → Complete freeze
Impact
User Impact:
- Work interruption every ~30 minutes
- Data loss if unsaved work in frozen window
- System becomes unresponsive (swap thrashing)
- Requires force kill, losing context
Frequency: 11 occurrences reported by user, likely more unreported
Attempted Workarounds
What DOESN'T work:
- MCP server optimization (reduced startup from 28s to 6s, but freeze persists)
- Direct SSH database access (bypassing MCP)
- Reducing number of MCP servers
What DOES work (temporarily):
- kill -9 (loses all context)
- Manual cache cleanup (not user-friendly)
Proposed Fixes
Immediate (Hot-fix)
- Implement cache size limits:
const MAX_CACHE_TOKENS = 1_000_000; // 1M token limit
const MAX_HISTORY_LENGTH = 100; // Keep last 100 messages-
Add garbage collection:
- Prune old conversation turns after threshold
- Release memory for messages older than N hours
- Implement LRU eviction for cached contexts
-
Add memory monitoring:
- Detect when process uses >8GB RAM
- Warn user before freeze
- Auto-cleanup if memory exceeds threshold
Long-term (Architecture)
-
Streaming cache architecture:
- Don't load entire conversation history into RAM
- Stream from disk on-demand
- Use memory-mapped files for large contexts
-
Conversation chunking:
- Split long conversations into chunks
- Load only relevant chunks for current context
- Implement smart context window management
-
User-visible controls:
claude config set max-cache-size 1000000
claude cache clear
claude cache statusDiagnostic Data
System Info:
# Memory at freeze
$ free -h
total used free shared buff/cache available
Mem: 15Gi 15Gi 46Mi 2.0Mi 76Mi 46Mi
Swap: 4.0Gi 2.8Gi 1.2Gi
# Process state
$ ps aux | grep claude
rickard 718 46.6 94.5 91180160 15370036 pts/0 Rl+ 04:05 19:09 claude
# Cache stats from config
lastTotalCacheReadInputTokens: 9,656,824
lastTotalCacheCreationInputTokens: 367,980MCP Servers Running (not the cause):
- grokipedia (45MB RAM)
- n8n-mcp (43MB RAM)
- github (12MB RAM)
- postgres (removed, was causing ECONNREFUSED but not freeze)
Total MCP overhead: ~100MB RAM (negligible)
Files for Investigation
Config:
~/.claude.json(conversation cache metadata)~/.cache/claude-cli-nodejs/-home-rickard/(cache files)
Logs:
~/.cache/claude-cli-nodejs/-home-rickard/mcp-logs-*/
Example affected session:
- Session ID:
7d66760d-6f8e-45eb-a0e1-bc99532b3576 - Cost: $4.73
- Cache read: 9.6M tokens
Workaround for Users (until fixed)
Emergency recovery:
# Find frozen Claude processes
ps aux | grep claude | grep -v grep
# Kill frozen process
kill -9 <pid>
# Clear cache manually (nuclear option)
rm -rf ~/.cache/claude-cli-nodejs/*/mcp-logs-*/*.jsonlPrevention:
# Restart Claude daily to prevent cache buildup
# (Not ideal, loses context)Request to Claude Team
Priority: CRITICAL (P0)
Ask:
- Implement hard limits on cache token count (1M tokens max)
- Add memory-aware garbage collection
- Provide user-facing cache management commands
- Document expected memory usage for long-running sessions
Contact:
- Email: wilhelmsson424@gmail.com
- GitHub: wilhelmsson424-jpg/restaurangai_sync
Willing to provide:
- Anonymized cache dumps
- Memory profiling data
- Beta testing of fixes
Generated: 2026-01-28 04:45 UTC
Status: Awaiting Claude Engineering review
Activity
github-actions commentedon Jan 28, 2026
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
wilhelmsson424-jpg commentedon Jan 29, 2026
Additional Critical Data Point - OOM Kill at 15 Minutes Runtime
Timestamp: 2026-01-29 07:20:47 (just occurred)
OOM-killer log:
Escalation:
This is now the 12th confirmed OOM kill of Claude Code in production use. The memory leak is:
Business Impact:
Request:
Please prioritize this for next release. The issue makes Claude Code unusable for serious development work on Linux.
Environment:
wilhelmsson424-jpg commentedon Jan 29, 2026
Update 2026-01-29 09:00 UTC: New Critical Bug - Agent Hang on Tool Confusion
Summary
Discovered a SECOND, SEPARATE bug that also causes memory leak + OOM-kill, distinct from the cache overflow issue.
What Happened Today (Crash #13)
Timeline:
a5ae718startedSkill("n8n-workflow-expert")Unknown skill: n8n-workflow-expertTotal hang time: 4 minutes
Memory leak rate: ~5GB/min (10x faster than cache leak)
Evidence: Agent transcript
agent-a5ae718.jsonlhas only 7 lines, ending at the error with no recovery attemptRoot Cause: Agent Error-Handling Failure
Skill("n8n-workflow-expert")(which doesn't exist)Unknown skill: n8n-workflow-expertNote:
n8n-workflow-expertexists as an agent (used withTasktool), not a skill (used withSkilltool). The agent confused the two tool types.Comparison: Two Separate Bugs
SkillvsTask)Impact on Production Work
Technical Details
Agent transcript evidence:
Memory monitor log:
Recommended Fix (Claude Team)
Immediate: Agent error-handling needs try/catch recovery:
Long-term protection:
Workaround (User Side)
Temporarily disabled agent system entirely to avoid both bugs:
Task()callsSkill()callsThis is not sustainable for complex work but necessary until fix deployed.
Request
Please prioritize BOTH bugs:
Both make Claude Code unusable for serious development on Linux. Combined, they cause crashes every 20-40 minutes.
Full technical analysis available if needed.
carpcarp commentedon Jan 31, 2026
I'm having the same issue except it rises about 5gb per 5 seconds and then crashes down to 7gb before climbing back to 20gb

I'm happy to share nay logging if there's anything specific you'd like me to run. I tried filing a bug but the claude code freezes when running the report a bug command.
cowwoc commentedon Feb 3, 2026
Here is a way to reproduce the crash immediately. Open claude code and paste the following:
Please update the title of this bug report to reflect the fact that a crash happens immediately, not after 20 minutes.
michelesant82-beep commentedon Feb 7, 2026
Additional data point: Windows native (WinGet) install - same memory leak pattern
Environment:
Anthropic.ClaudeCode) - native binary, no Node.js involvedObservation:
A session running for ~115 minutes accumulated 2.7 GB of resident memory before becoming completely unresponsive (frozen for 30+ minutes, no input accepted). No crash or OOM-kill occurred - the process stayed alive but non-functional.
For comparison, a fresh session launched on the same machine uses ~690 MB, meaning the frozen session grew to ~4x its initial memory footprint.
Process details (frozen session):
Key difference from original report:
node.exeprocesses involved - the leak is in the nativeclaude.exebinary itselfConfirms: The memory leak is not Node.js-specific - it also affects the native Windows binary distributed via WinGet. This suggests the root cause is in shared application logic (conversation cache management), not in the Node.js runtime or Ink rendering layer.
rafa-lopes-pt commentedon Feb 15, 2026
UPDATE: RESOLVED
Updating from Claude Code version 2.1.41 to 2.1.42 solved the memory leak problem. The issue no longer occurs with the latest version.
System Details:
Issue:
Experiencing severe memory leak in Claude Code that occurs even in brand new, empty project directories. Memory grows at approximately 50-60 MB/second during active conversation, leading to OOM kill within 5-15 minutes.
Reproduction:
mkdir ~/test-memory-leak && cd ~/test-memory-leakclaudewatch -n 2 "ps aux | grep claude | grep -v grep"Observed Memory Growth:
Key Findings:
Critical Note:
This is NOT a cache accumulation issue. The leak occurs in fresh projects with no accumulated cache, during runtime. The process heap grows unbounded during active conversation regardless of project history.
Impact:
Claude Code is currently unusable for any conversation lasting more than 5-10 minutes on a 16GB system. Multiple reproductions across different directories confirmed the same behavior.
UPDATE add cpu and RAM usage after encountering the following issue a…
hirehamir commentedon Aug 5, 2026
Still-standing data point (Aug 04, 18:33 PDT): VS Code extension anthropic.claude-code 2.1.221 on Ubuntu 24.04 native (not WSL), 32 GB RAM + 24 GB swap.
The extension's bundled binary (2.1.221) reached 11,867 MiB RSS and earlyoom killed it, plus 63 browser and 4 VS Code processes:
That session's transcript contains zero Grep tool calls and the process tree was ~3.5 h old, so this is consistent with a gradual heap leak as described in this issue.
gboeer commentedon Aug 19, 2026
I am using the vscode extension in a dev container and in my case the container crashes with an oom after only 2 minutes.
If i deinstall the extension, the crash doesnt happen.
This is the error message:
"The window terminated unexpectedly (reason: 'oom', code: '-536870904')