[BUG] Fatal Memory Allocation Failure
Resolved 💬 1 comment Opened Jul 18, 2025 by Bryan-Nsoh Closed Jul 27, 2025
Claude CLI (claude-code) Fatal Memory Allocation Failure
Summary
Claude CLI consistently crashes with "JavaScript heap out of memory" error across multiple environments, regardless of available system memory or configured heap size.
Affected Version
- claude-code: v1.0.55 (latest as of report)
- Also affects: v1.0.54
Reproduction Rate
100% - Crashes every time on command execution
Environments Tested
Environment 1: Linux Server (Hetzner VPS)
OS: Ubuntu 22.04 LTS
Architecture: x86_64
Total RAM: 2GB
Available RAM: 1.6GB
Node: v18.19.1
npm: 9.2.0
Installation method: npm install -g @anthropic-ai/claude-code
Environment 2: Windows Desktop
OS: Windows 11
Architecture: x64
Total RAM: 32GB (33,525,028 KB)
Available RAM: 21GB (22,145,240 KB)
Node: v20.19.4
npm: (included with Node)
Installation method: npm install -g @anthropic-ai/claude-code
Error Details
Stack Trace (Linux):
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 0x7df054a0633c node::Abort() [/lib/x86_64-linux-gnu/libnode.so.109]
2: 0x7df0548fa5db [/lib/x86_64-linux-gnu/libnode.so.109]
3: 0x7df054dec544 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool)
4: 0x7df054dec938 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool)
[... truncated for brevity ...]
Stack Trace (Windows):
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----
1: 00007FF75EF80CD7 node::SetCppgcReference+16599
2: 00007FF75EEE4568 v8::base::CPU::num_virtual_address_bits+103336
[... truncated for brevity ...]
Command Used
claude --dangerously-skip-permissions --model claude-opus-4-20250514
Heap Limit Observations
Linux Default:
- Without NODE_OPTIONS: 984 MB
- With NODE_OPTIONS="--max-old-space-size=1536": Still crashes
- System has 1.6GB available but crashes at <1GB heap
Windows Default:
- Without NODE_OPTIONS: 4.05 GB
- With NODE_OPTIONS="--max-old-space-size=8192": 8.05 GB (still crashes)
- With NODE_OPTIONS="--max-old-space-size=16384": Not tested yet
- System has 21GB available but crashes at 4GB heap
Diagnostic Commands Run
Linux Diagnostics:
node -e "console.log(require('v8').getHeapStatistics().heap_size_limit / 1024 / 1024 + ' MB')"
# Output: 984 MB
echo $NODE_OPTIONS
# Output: (empty initially)
which claude
# Output: /home/claude/.npm-global/bin/claude
npm list -g | grep claude
# Output: └── @anthropic-ai/claude-code@1.0.55
Windows Diagnostics:
node -e "console.log((require('v8').getHeapStatistics().heap_size_limit / 1024 / 1024 / 1024).toFixed(2) + ' GB')"
# Output: 4.05 GB
$env:NODE_OPTIONS="--max-old-space-size=8192"
npx node -e "console.log(process.env.NODE_OPTIONS)"
# Output: --max-old-space-size=8192 (confirms NODE_OPTIONS is passed correctly)
Key Findings
- Not a simple memory limit issue: Crashes occur well before system memory limits
- NODE_OPTIONS is respected: Heap limits increase as expected, but crashes still occur
- Cross-platform: Identical behavior on Linux (2GB) and Windows (32GB)
- Happens immediately: Crashes during startup/initialization, not during operation
- npx vs direct execution: Same result both ways
Attempted Solutions (All Failed)
- ✗ Increasing NODE_OPTIONS heap size
- ✗ Running with direct node command instead of wrapper
- ✗ Using npx vs global installation
- ✗ Adding swap space (Linux)
- ✗ Different Node versions (18.x vs 20.x)
Expected Behavior
CLI should start and accept commands without crashing, especially on a system with 32GB RAM
Actual Behavior
Immediate crash with heap allocation failure
Additional Context
- No large files being processed
- No previous state/cache that could be corrupted
- Fresh installations on both systems
- Other Node applications work fine on both systems
Questions This Preemptively Answers
- Q: Is NODE_OPTIONS being passed? A: Yes, verified via diagnostics
- Q: Is it system memory? A: No, happens on 32GB system with 21GB free
- Q: Is it Node version specific? A: No, happens on v18.19.1 and v20.19.4
- Q: Is it OS specific? A: No, happens on Ubuntu 22.04 and Windows 11
- Q: Could it be npx? A: No, direct execution also fails
- Q: Is the installation corrupted? A: No, fresh installs on both systems
Suspected Root Cause
The CLI appears to be attempting to allocate massive amounts of memory during initialization, possibly:
- Loading large model files into memory
- Memory leak in initialization code
- Inefficient memory allocation pattern that fragments heap
Impact
Complete inability to use Claude CLI on any system, regardless of specifications
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗