[CRITICAL] JavaScript heap out of memory crash during MCP operations
## Environment
- Platform: macOS (Darwin)
- Claude Code Version: Latest
- Working Directory: Large enterprise codebase
## Bug Description
Claude Code crashes with a fatal JavaScript heap out of memory error
during complex MCP operations involving MongoDB and agent tasks. The crash
appears to be related to large array operations during data processing.
## Crash Details
<--- Last few GCs --->
[32983:0x158008000] 42601003 ms: Mark-Compact 3993.5 (4138.2) -> 3982.2
(4142.7) MB, pooled: 0 MB, 901.75 / 0.00 ms (average mu = 0.179, current
mu = 0.020) allocation failure; scavenge might not succeed
[32983:0x158008000] 42602322 ms: Mark-Compact 3998.1 (4142.7) -> 3986.9
(4147.5) MB, pooled: 0 MB, 1302.79 / 0.00 ms (average mu = 0.089, current
mu = 0.012) allocation failure; scavenge might not succeed
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of
memory
----- Native stack trace -----
1: 0x104ee5cac node::OOMErrorHandler(char const*, v8::OOMDetails const&)
[/usr/local/bin/node]
2: 0x1050bb998
v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char
const*, v8::OOMDetails const&) [/usr/local/bin/node]
...
10: 0x105ba4bfc Builtins_ArrayPrototypeJoin [/usr/local/bin/node]
## Context Leading to Crash
The crash occurred while:
- Running data processing optimization tasks
- Using MongoDB MCP server to query large collections
- Operating with integration testing agents
- Processing large datasets with complex operations
## Reproduction Context
```bash
# Complex data optimization and testing workflow
# MongoDB queries on collections with substantial data
# Browser automation testing operations
# Large-scale data processing operations
Impact
- Severity: Critical - Complete Claude Code crash
- Recovery: Requires full restart of Claude Code
- Data Loss: Current session and context lost
- Frequency: Occurred during intensive MCP/MongoDB operations with large
datasets
Expected Behavior
Claude Code should handle large data processing operations without
exceeding Node.js heap limits, possibly through:
- Streaming/chunked data processing
- Memory management improvements
- Pagination for large result sets
- Garbage collection optimization
Suggested Investigation Areas
- Array operations - The stack trace shows ArrayPrototypeJoin operations
consuming excessive memory
- MongoDB result processing - Large query results may not be properly
streamed
- Agent memory management - MCP agents may be accumulating data without
cleanup
- Session context accumulation - Extended sessions may be building up
excessive context
Related Issues
This appears to be distinct from #5385 (context auto-compact issues) as
it's a fatal heap crash rather than a context management problem.
Environment Details
- Node.js heap reached: ~4GB before crash
- Session duration: Extended session with complex operations
- MCP operations: Multiple MongoDB queries and agent tasks
- MCP server: mongodb: npx mongo-mcp mongodb://admin:xxxxxxxx@localhost:27017/qc2?authSource=admin - ✓ Connected
- Data volume: Large collections being processed (enterprise-scale
dataset)
This crash suggests Claude Code may need better memory management for
intensive data processing operations, especially when working with large
datasets through MCP servers in enterprise environments.
## Labels to Apply:
bugmemoryperf:memoryarea:corearea:mcpplatform:macos
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗