[BUG] Claude code is killed by OOM killer due to subprocess issue
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?
When claude code is launching a program - it launches it in a way that Linux OOM killer targets claude code instead of subprocess. When claude code is working in tmux - session immediately terminates with "Pane is dead (signal 1" and it is getting not trivial to recover.
What Should Happen?
Subprocess is launched in a way that OOM killer only kills subprocess, and claude code correctly receives error message and can understand that process was killed by OOM killer.
Error Messages/Logs
No logs were generated.
tmux pane terminates with "Pane is dead (signal 1"...
Steps to Reproduce
- Make claude code write a C++ program that malloc's memory in infinite cycle and run it
- Wait
Claude Model
Opus
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.0.59 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
It might have worked sometimes in the past - I think I saw it noticing program termination and guessing it was killed by OOM killer. It is not unthinkable to get this error: if one runs 4 claude code's and they sometimes run heavy programs, one day you won't be lucky - they all will overlap and crash claude code. If it was gracefully failed - claude code would have been able to recover and proceed.
11 Comments
I've also been experiencing this issue. Seemingly randomly
claudewill be killed by the OOM killer. I've had claude investigate and here's what it's said: "Claude process grows from ~2.5GB to 24-26GB RSS over long sessions before getting OOM killed. On a 31GB RAM + 2GB swap system, dmesg shows repeated kills at anon-rss:24-26GB. Memory appears to accumulate during extended conversations with many tool calls/subagents."However, I can say that the sessions aren't necessarily long, because my most recent bout with this issue was only after 20 minutes of usage doing some git archaeology and light debugging.
Claude Code CLI Memory Leak - Complete Solution
TL;DR - Working Solution
Problem: Claude Code crashes with
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memoryRoot Cause: Accumulated cache in
~/.claude/directories (especiallyshell-snapshots/at 1.5GB+)What DOESN'T Work:
What DOES Work:
du -sh ~/.claude/before/after sessionsQuick Fix:
See [Prevention](#prevention) section for automated cleanup script and full solution.
---
Root Cause
The Claude Code CLI accumulated 1.7GB of cached data across shell-snapshots (1.5GB), conversation history JSONLs (77MB), todo stubs (11MB), and file-history (8MB), which the V8 JavaScript engine attempted to load or parse on startup and during operations, causing garbage collection to fail when heap exceeded 24GB and triggering an "Ineffective mark-compacts near heap limit" fatal error.
Trigger Patterns:
What We Missed
The shell-snapshots directory silently grew to 1.5GB without any visible warning or monitoring. Each shell environment capture stored approximately 244KB, and over extended usage, 28+ snapshots accumulated. The initial investigation focused on conversation JSONL files (the commonly reported culprit in community discussions) and missed checking
~/.claude/shell-snapshots/entirely during the first diagnostic pass. The early signal was the V8 garbage collection metrics in the crash log showingmu = 0.276(mutation rate), indicating the engine spent 72% of its time attempting garbage collection rather than executing work—a clear indicator of memory pressure from large cached objects rather than runtime agent spawning.Prevention
Immediate Actions (Under 30 Minutes)
~/.local/bin/claude-cleanup.sh:~/.bashrcor~/.zshrc:Session Hygiene Rules
claude-sizebefore starting intensive work sessions~/.claude/exceeds 500MB, run cleanup before continuing/resumesessions older than 24 hours without checking cache sizesWarning Thresholds
| Directory | Warning | Critical | Action |
|-----------|---------|----------|--------|
|
~/.claude/total | >500MB | >1GB | Run cleanup script ||
shell-snapshots/| >100MB | >500MB | Clear immediately ||
projects/| >50MB | >200MB | Clear conversation history || Single JSONL file | >1MB | >5MB | Session too long, restart |
Quick Reference
Location:
~/.claude/(primary),~/.cache/claude-cli-nodejs/(secondary)Symptom:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memoryv8::internal::Heap::CollectGarbageallocation failuremu < 0.3(mutation rate below 30%)Search:
Next steps:
claude-sizecheck to your pre-work routine when opening projects with heavy Claude Code usage---
Technical Details
Cache Directory Purposes
| Directory | Purpose | Regenerates? |
|-----------|---------|--------------|
|
projects/| Conversation history per project | Yes, on new session ||
todos/| Task tracking state | Yes, on new tasks ||
file-history/| Edit undo/redo snapshots | Yes, on file edits ||
shell-snapshots/| Shell environment captures | Yes, on shell commands ||
debug/| Debug logging output | Yes, on debug operations ||
local/| CLI binaries (DO NOT DELETE) | No - breaks CLI ||
plugins/| Skill definitions (DO NOT DELETE) | No - breaks skills |Memory Architecture
Claude Code runs on Node.js with V8 engine. Default heap limit scales with available RAM but can exceed safe thresholds. The CLI loads conversation history and cached state on startup, making accumulated cache a startup-time memory bomb rather than a runtime issue. This explains why OOM can occur even when idle—the damage happens during initialization.
Differentiation: Runtime vs Startup OOM
| Characteristic | Startup OOM | Runtime OOM | Agent-Accelerated OOM |
|----------------|-------------|-------------|----------------------|
| When | Immediately on
claudecommand | During active work | During/after agent spawning || Cause | Large cached files being parsed | Too many parallel agents | Rapid cache accumulation |
| Fix | Delete cache files | Limit agent count, /compact | Cache cleanup |
| GC Pattern | Aggressive from start | Gradual degradation | Faster accumulation |
| Session age | Irrelevant | Longer = worse | Can happen faster |
| Memory growth | Linear (cache size) | Linear (agent count) | Accelerated (agent usage) |
Compounding effect: Subagent/sub-subagent usage creates cache files faster, which can cause startup OOM on next launch if not cleaned. After cleanup, OOM crashes resolve regardless of agent architecture used.
Related GitHub Issues
This solution addresses memory issues reported in:
Recommended upstream improvements:
~/.claude/exceeds 500MB---
What Didn't Work
Failed Solution 1: Hardcoded Heap Limits in Alias (December 2025)
Attempted Fix:
Why it failed:
export NODE_OPTIONSin the shellFailed Solution 2: Global .claudeignore (December 2025)
Attempted Fix:
Why it failed:
~/.claude/directoriesFailed Solution 3: Weekly Cron Cleanup (December 2025)
Attempted Fix:
Why it failed:
Failed Solution 4: Agent Architecture Changes Without Cleanup (December 2025)
Attempted Fix:
Changed from 3-tier nested architecture to 2-tier flat architecture:
Why it failed:
Reference: See
/home/fivefingerdisco/.claude/docs/MEMORY_TROUBLESHOOTING.mdfor complete details of failed attempts.---
The Working Solution
The only approach that actually works is aggressive cache management combined with session hygiene.
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.
Still present
Not sure if related but having similar similar issues in Linux. Have to manually kill sessions to interact with the system
issue is still occurring in version 2.1.19
Agent Teams caused kernel panic (2x reboots) on 7.6GB server with no swap
Environment
What happened
Asked Claude Code to spawn an Agent Team with 4 subagents to test Playwright across multiple remote servers. Each subagent spawned its own set of MCP servers (Playwright, Slack, context7, sequential-thinking).
Result: Server kernel-panicked twice in a row.
Memory timeline from
sar -r| Time | Free (MB) | %Used | Note |
|------|-----------|-------|------|
| 14:30 | 3,091 | 11.3% | Normal |
| 14:40 | 3,006 | 12.3% | Team spawning |
| 14:50 | 1,581 | 34.8% | Rapidly increasing |
| ~14:55 | 0 | 100% | Kernel panic → reboot |
| 15:03 | LINUX RESTART | | 1st reboot |
| 15:07 | LINUX RESTART | | 2nd reboot (3 min after 1st!) |
~1.4GB consumed in just 10 minutes. The 2nd crash happened because the session auto-restored after boot and the processes tried to resume.
Memory breakdown (single Claude Code session)
From
ps auxafter recovery:| Process | RSS |
|---------|-----|
| intelephense (LSP) | 1.7 GB |
| claude (main) | 546 MB |
| playwright-mcp | 103 MB |
| context7-mcp | 84 MB |
| sequential-thinking | 68 MB |
| slack-mcp | 53 MB |
| Total per session | ~2.5-3 GB |
With 4 subagents, each spawning their own MCP stack: ~12-15 GB required on a 7.6 GB machine with no swap.
Suggestion
Agent Teams (and subagent spawning in general) should check available system memory before launching. Even a simple
free -mcheck with a warning/limit would prevent this class of crash. Currently there's zero resource checking — it just spawns everything and hopes for the best.Workaround
Added 20GB swap. Now it survives but gets sluggish when swapping.
Ok so it's not just me. Yeah I periodically get claude being killed by OOM killer and I'm not even a heavy user. I thought I was going crazy. Hopefully they can fix this sooner than later.
2.1.68 (Claude Code)running on Ubuntu 24.04 Gnome workstation.I hit this regularly on my Debian VM:
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
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.