[BUG] Claude Code Fatal Memory Error - JavaScript Heap Out of Memory

Resolved 💬 2 comments Opened Jun 15, 2025 by naren200 Closed Jun 17, 2025

Environment

  • Platform (select one):
  • [ ] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [x] Other: Claude Code Terminal Application
  • Claude CLI version: 1.0.24 (Claude Code)
  • Operating System: Windows 10 (Build 26100.4351) with WSL 2
  • WSL version: 2.4.12.0
  • Kernel version: 5.15.167.4-1
  • WSLg version: 1.0.65
  • Terminal: WSL Command Prompt

Bug Description

Claude Code crashes with a fatal JavaScript heap out of memory error during file listing operations. The application reaches Node.js heap limit (~2GB) and terminates abruptly with error code "Aborted (core dumped)". This occurs when Claude attempts to process directory listings, particularly when dealing with large project directories (720 paths listed in this case).

Steps to Reproduce

  1. Launch Claude Code in WSL terminal environment
  2. Navigate to a Flutter project directory or any large codebase
  3. Ask Claude to perform file operations or directory analysis
  4. Claude executes List(../..) command showing "Listed 720 paths"
  5. System shows "Marinating..." status for ~10 seconds with increasing token count (↑ 2.9k tokens)
  6. Memory usage reaches critical levels (~2049MB)
  7. Fatal error occurs with heap allocation failure

Expected Behavior

Claude Code should handle large directory structures efficiently without running out of memory. The application should either:

  • Implement proper memory management for large file listings
  • Provide pagination or chunking for large directory operations
  • Display a graceful error message if memory limits are approached
  • Continue functioning normally after processing directory contents

Actual Behavior

Claude Code crashes completely with the following error sequence:

  1. Garbage collection attempts fail (Mark-Compact operations shown)
  2. Heap allocation fails at ~2049MB
  3. Fatal error: "Reached heap limit Allocation failed - JavaScript heap out of memory"
  4. Application terminates with "Aborted (core dumped)"
  5. Complete loss of session and conversation context

Additional Context

Complete Error Log:


● Flutter has line ending issues. Let me check if there's a build script available:
● List(../..)
  ⎿  Listed 720 paths (ctrl+r to expand)
✢ Marinating… (10s · ↑ 2.9k tokens · esc to interrupt)
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ >                                                                                                                                                                                       │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
  ? for shortcuts
<--- Last few GCs --->
[23704:0x39b3e000]  2022988 ms: Mark-Compact (reduce) 2036.3 (2048.2) -> 2035.8 (2040.7) MB, pooled: 0 MB, 6.39 / 0.01 ms  (+ 0.1 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 54 ms) (average mu = 0.988, curren[23704:0x39b3e000]  2023091 ms: Mark-Compact 2049.9 (2054.8) -> 2049.8 (2057.8) MB, pooled: 0 MB, 28.39 / 0.00 ms  (average mu = 0.955, current mu = 0.726) allocation failure; scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----
 1: 0xe13fde node::OOMErrorHandler(char const*, v8::OOMDetails const&) [claude]
 2: 0x11d5070 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [claude]
 3: 0x11d5347 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [claude]
 4: 0x1402c05  [claude]
 5: 0x141c499 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [claude]
 6: 0x13f0b48 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [claude]
 7: 0x13f1a75 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [claude]
 8: 0x13c9e6e v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [claude]
 9: 0x13b8f64 v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawWithImmortalMap(int, v8::internal::AllocationType, v8::internal::Tagged<v8::internal::Map>, v8::internal::AllocationAlignment) [claude]
10: 0x13bae6f v8::internal::FactoryBase<v8::internal::Factory>::NewRawTwoByteString(int, v8::internal::AllocationType) [claude]
11: 0x13d584a v8::internal::Factory::NewStringFromUtf8(v8::base::Vector<char const>, v8::internal::AllocationType) [claude]
12: 0x11f158d v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::NewStringType, int) [claude]
13: 0x10e17d9  [claude]
14: 0xf36bf0  [claude]
15: 0x7f62bfe0f745
Aborted (core dumped)

Key Observations:

  • Issue appears related to memory-intensive file system operations
  • Error consistently occurs around 2GB heap usage
  • Flutter projects may be particularly susceptible due to large dependency trees
  • No graceful degradation or error recovery mechanism
  • Session state is completely lost requiring restart

Potential Workarounds Needed:

  • Increase Node.js heap size limit
  • Implement streaming/chunked file processing
  • Add memory usage monitoring and warnings
  • Provide option to limit directory traversal depth

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗