[BUG] JavaScript heap out of memory crash when running parallel Explore subagents
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?
Claude Code crashes with a "JavaScript heap out of memory" fatal error when running multiple Explore subagents in parallel. The crash occurs during normal operation while the subagents are processing their tasks.
The parent Claude Code process runs out of memory (reaching ~4GB) and terminates abruptly with:
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
The crash appears to happen during an Array.prototype.join operation based on the stack trace, suggesting the issue may be related to accumulating/joining large result sets from subagent output.
What Should Happen?
Claude Code should:
- Complete all subagent tasks without crashing
- Handle memory efficiently when running parallel subagents
- If memory pressure is high, gracefully degrade (e.g., run agents sequentially) rather than crash
Error Messages/Logs
<--- Last few GCs --->
[95727:0x820400000] 296897 ms: Mark-Compact 4082.5 (4163.4) -> 4027.7 (4108.5) MB, pooled: 1 MB, 1540.08 / 0.00 ms (average mu = 0.229, current mu = 0.030) allocation failure; scavenge might not succeed
[95727:0x820400000] 298584 ms: Mark-Compact 4151.1 (4231.9) -> 4068.8 (4149.7) MB, pooled: 1 MB, 1569.88 / 0.00 ms (average mu = 0.150, current mu = 0.070) allocation failure; scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----
1: 0x1003d625c node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/Users/user/.pocket-server/bin/node]
2: 0x1005ac4fc v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/Users/user/.pocket-server/bin/node]
3: 0x1007bbc24 v8::internal::Heap::stack() [/Users/user/.pocket-server/bin/node]
4: 0x1007b9fc4 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/user/.pocket-server/bin/node]
5: 0x1007ae5ac v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/user/.pocket-server/bin/node]
6: 0x1007aede4 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/user/.pocket-server/bin/node]
7: 0x100792104 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Users/user/.pocket-server/bin/node]
8: 0x100badbb4 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Users/user/.pocket-server/bin/node]
9: 0x101071af4 Builtins_CEntry_Return1_ArgvOnStack_NoBuiltinExit [/Users/user/.pocket-server/bin/node]
10: 0x1010987e8 Builtins_ArrayPrototypeJoin [/Users/user/.pocket-server/bin/node]
Steps to Reproduce
- Start Claude Code in a directory with access to session files (e.g., home directory)
- Enter plan mode
- Issue a prompt that causes Claude to launch 3 Explore subagents in parallel, where at least one agent processes a large amount of data (e.g., searching through many session files)
Example prompt that triggered the crash:
look at session id [session-id]. use session troubleshooting guidelines. basically my workflow is
to work on some project in a git worktree, and then merge the worktree into the main branch
and delete the worktree. but i have a hook that blocks dangerous commands. [...]
This caused Claude to launch 3 parallel Explore agents:
- Agent 1: "Analyze successful worktree session" - completed
- Agent 2: "Find dangerous command hook" - completed
- Agent 3: "Find blocked worktree sessions" - crashed during execution
The third agent was searching through /Users/user/.claude/projects/-Users-user/ which contains ~900 session files totaling ~565MB.
Session file for investigation: /Users/user/.claude/projects/-Users-user/cdaddfc7-2d95-4af4-848a-6dac8a64b176.jsonl
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.12
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
Memory Analysis
The garbage collection logs show:
- Memory peaked at ~4.1GB before crash
- GC was taking 1.5+ seconds per cycle
- Average mutation utilization (mu) dropped to 0.03-0.07, indicating severe memory pressure
Potential Root Causes
- Subagent output accumulation: The crash occurred in
Builtins_ArrayPrototypeJoin, suggesting large arrays being joined (possibly tool outputs or search results)
- Session directory size: The
/Users/user/.claude/projects/-Users-user/directory contains ~900 session files. Searching through these may generate excessive intermediate results
- No backpressure on parallel agents: Running 3 agents simultaneously, each potentially processing large amounts of data, with no memory limits
Suggested Mitigations
- Implement memory limits or monitoring for subagents
- Stream/chunk large search results instead of accumulating in memory
- Add backpressure when running parallel agents (e.g., limit concurrent agents based on memory usage)
- Consider garbage collection hints between large operations
Environment Details
- Node binary:
/Users/user/.pocket-server/bin/node - Session had 88 entries before crash
- Plan mode was active
- Multiple SessionStart hooks were running
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗