[Bug] Memory Leak When Initializing Sub-Agent Orchestration
Bug Description
If I continue this session by issuing an instruction like "Continue as an orchestrator, directing sub-agents to perform the necessary work." claude code will start allocating memory until all system memory is exhausted and the process crashes. In a newly-launched claude session, Activity Monitor shows that the claude process has about 450MB allocated (once I resume the session); when I issue the command, I can watch it start allocating massive amounts of memory almost right away, growing to 500, 1GB, 1.5GB, 2GB, 4GB, 4.5GB, 6GB,....30GB, ...crash
It doesn't always begin the massive allocations immediately. Sometimes, it'll run a prompt for a while, seeming normal, but within a prompt or two it will innevitably get into the massive allocation state and crash.
Environment Info
- Platform: darwin
- Terminal: iTerm.app
- Version: 1.0.100
- Feedback ID: 5e71aaf2-81fd-47bb-b0a9-8a15b230127c
Errors
[]
18 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Here's an example of the crash:
Note: the crash seems to happen whether running under nodejs directly, under
bunx, and underbunx --bun. I've tried deleting ~/.claude.json and starting afresh - crash still happens.I'd ba happy to provide my settings.json, mcp.json etc if helpful.
Here's the crash running under
bunx --bun:Hitting what looks like the same issue on macOS with 1.0.115. I am developing some subagents for my workflows. When it didn't finish running over night I did a
pkill -9 claude. Didn't think to check memory usage first.After a
claude --resumeI did```> /context
⎿ ⛁ ⛀ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛀ ⛁
⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛶ Context Usage
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ claude-sonnet-4-20250514 • 35k/200k tokens (18%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ System prompt: 3.2k tokens (1.6%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ System tools: 12.0k tokens (6.0%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ Custom agents: 350 tokens (0.2%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ Memory files: 2.1k tokens (1.0%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛁ Messages: 17.6k tokens (8.8%)
⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ Free space: 164.9k (82.4%)
Custom agents · /agents
└ devenv-expert (User): 46 tokens
└ auto-fixer (User): 41 tokens
└ pre-commit-validator (User): 49 tokens
└ smart-committer (User): 39 tokens
└ documentation-generator (User): 25 tokens
└ agent-builder (User): 44 tokens
└ workflow-orchestrator (User): 30 tokens
└ code-reviewer (User): 51 tokens
└ domain-research-patterns (User): 25 tokens
Memory files · /memory
└ User (/Users/<elided>/.claude/CLAUDE.md): 64 tokens
└ Project (/Users/<elided>/Source/agent-forge/CLAUDE.md): 2.0k tokens
⏺ workflow-orchestrator(Test workflow orchestrator)
⎿ Done (38 tool uses · 46.4k tokens · 18m 8.8s)
⏺ Test 2.7 Results: ✅ SUCCESS
The workflow-orchestrator performed exceptionally:
Phase 2 Complete! 🎉
All 7 agents tested successfully:
Next: Phase 3 - Integration Testing (Test 3.1: Full Commit Workflow)
Ready to proceed with integration testing?
⏺ workflow-orchestrator(Query available workflows)
⎿ Done (19 tool uses · 35.8k tokens · 1m 7.8s)
⏺ The workflow-orchestrator has extensive capabilities! It can orchestrate:
Core Patterns:
Pre-built Workflows:
Available Agents:
Advanced Features:
Command Interface:
workflow_orchestrator --pattern=commit
workflow_orchestrator --workflow=parallel_validation
workflow-monitor status
The system is designed for comprehensive workflow automation with intelligent optimization!
⏺ workflow-orchestrator(Execute commit validation workflow)
⎿ Starting Commit Validation Workflow - Phase 1: Pre-commit Validation
+9 more tool uses
✶ Performing commit validation workflow… (esc to interrupt · ctrl+t to hide todos)
⎿ ☒ Execute Phase 1: Agent Availability Verification
☒ Check agent registration with /agents command
☒ Verify all 7 agents are visible
☒ Proceed to Phase 2: Individual Agent Functionality Tests
☒ Test 2.1: Agent Builder functionality
☒ Test 2.2: Pre-commit Validator functionality
☒ Test 2.3: Auto-fixer functionality
☒ Test 2.4: Smart Committer functionality
☒ Test 2.5: Documentation Generator functionality
☒ Test 2.6: Domain Research Patterns functionality
☒ Test 2.7: Workflow Orchestrator functionality
☐ Perform commit validation workflow
While writing the above, it looks to have gotten killed by the system.
Copied the same project to my much larger Linux system and it ran flawlessly never exceeding 200-300MB.
1.0.120 is killing Jetbrains
<img width="425" height="372" alt="Image" src="https://github.com/user-attachments/assets/6a4b3c21-2b70-4d4f-b981-0a398752f3b3" />
I'm experiencing this issue on Mac OS 15.6.1 (24G90).
This issue occurs every time and also appears on
As soon as my orchestrator agent A calls sub-agent B the memory usage blows up and I have have to kill claude code. According the my logs, the code that agent B was supposed to call first thing was not entered. This points to the agent blowing up during initialization.
Here's the memory blow up over time:
Time RSS(MB) %MEM State
────────────────────────────────────────
0:00 242 0.7% Starting
0:06 268 0.8% Normal operation
0:08 546 1.6% ⚠️ SPIKE BEGINS
0:11 1,130 3.4%
0:20 2,737 8.2% Exponential growth
0:40 5,595 16.7%
1:00 6,980 20.8%
1:30 9,131 27.2% Peak
2:15 8,168 24.3% 💥 CRASH
Here's The Stack Trace
<--- Last few GCs --->
[72406:0x138008000] 58025 ms: Mark-Compact 4003.5 (4113.2) -> 3994.1 (4120.2) MB, pooled: 0 MB, 855.54 / 0.00 ms (average mu = 0.194, current mu = 0.097) allocation failure; scavenge might not succeed
[72406:0x138008000] 58941 ms: Mark-Compact 4011.2 (4121.2) -> 4001.1 (4127.5) MB, pooled: 0 MB, 899.04 / 0.00 ms (average mu = 0.111, current mu = 0.019) allocation failure; scavenge might not succeed
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----
1: 0x10106f814 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
2: 0x1011ae97c v8::Utils::ReportOOMFailure(v8::internal::Isolate, char const, v8::OOMDetails const&) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
3: 0x1011ae934 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate, char const, v8::OOMDetails const&) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
4: 0x10138b550 v8::internal::Heap::stack() [/opt/homebrew/Cellar/node/24.7.0/bin/node]
5: 0x10138dc90 v8::internal::Heap::OldGenerationConsumedBytes() const [/opt/homebrew/Cellar/node/24.7.0/bin/node]
6: 0x10138db30 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector, v8::base::TimeTicks) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
7: 0x10139b4bc v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags)::$_1::operator()() const [/opt/homebrew/Cellar/node/24.7.0/bin/node]
8: 0x10139b160 void heap::base::Stack::SetMarkerAndCallbackImpl<v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags)::$_1>(heap::base::Stack, void, void const*) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
9: 0x101ae3658 PushAllRegistersAndIterateStack [/opt/homebrew/Cellar/node/24.7.0/bin/node]
10: 0x101389b10 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
11: 0x101381718 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
12: 0x1013693a4 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
13: 0x1016dbf78 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long, v8::internal::Isolate) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
14: 0x101ba5f74 Builtins_CEntry_Return1_ArgvOnStack_NoBuiltinExit [/opt/homebrew/Cellar/node/24.7.0/bin/node]
15: 0x1405782cc
16: 0x1404b3ab4
17: 0x1403bc524
18: 0x1404ba42c
19: 0x140262bac
20: 0x14061f0f4
21: 0x1405b8a50
22: 0x1404a0b88
23: 0x1401a75bc
24: 0x101b08bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.7.0/bin/node]
25: 0x1406246f4
26: 0x101b08bec Builtins_InterpreterEntryTrampoline [/opt/homebrew/Cellar/node/24.7.0/bin/node]
27: 0x101b47648 Builtins_AsyncFunctionAwaitResolveClosure [/opt/homebrew/Cellar/node/24.7.0/bin/node]
28: 0x101c1c5f8 Builtins_PromiseFulfillReactionJob [/opt/homebrew/Cellar/node/24.7.0/bin/node]
29: 0x101b36a50 Builtins_RunMicrotasks [/opt/homebrew/Cellar/node/24.7.0/bin/node]
30: 0x101b067b0 Builtins_JSRunMicrotasksEntry [/opt/homebrew/Cellar/node/24.7.0/bin/node]
31: 0x1012e37ac v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
32: 0x1012e3e58 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
33: 0x1012e3f48 v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate, v8::internal::MicrotaskQueue) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
34: 0x101308b44 v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
35: 0x101308960 v8::internal::MicrotaskQueue::PerformCheckpointInternal(v8::Isolate*) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
36: 0x101b0a94c Builtins_CallApiCallbackOptimizedNoProfiling [/opt/homebrew/Cellar/node/24.7.0/bin/node]
37: 0x1404a4804
38: 0x101b068cc Builtins_JSEntryTrampoline [/opt/homebrew/Cellar/node/24.7.0/bin/node]
39: 0x101b06570 Builtins_JSEntry [/opt/homebrew/Cellar/node/24.7.0/bin/node]
40: 0x1012e37dc v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
41: 0x1012e31cc v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::DirectHandle<v8::internal::Object>, v8::internal::DirectHandle<v8::internal::Object>, v8::base::Vector<v8::internal::DirectHandle<v8::internal::Object> const>) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
42: 0x1011bfe68 v8::Function::Call(v8::Isolate, v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
43: 0x100fbc960 node::InternalCallbackScope::Close() [/opt/homebrew/Cellar/node/24.7.0/bin/node]
44: 0x100fbcb98 node::InternalMakeCallback(node::Environment, v8::Local<v8::Object>, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>, node::async_context, v8::Local<v8::Value>) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
45: 0x100fcb684 node::AsyncWrap::MakeCallback(v8::Local<v8::Function>, int, v8::Local<v8::Value>*) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
46: 0x101130844 node::StreamBase::CallJSOnreadMethod(long, v8::Local<v8::ArrayBuffer>, unsigned long, node::StreamBase::StreamBaseJSChecks) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
47: 0x101131df4 node::EmitToJSStreamListener::OnStreamRead(long, uv_buf_t const&) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
48: 0x1011920b0 node::crypto::TLSWrap::ClearOut() [/opt/homebrew/Cellar/node/24.7.0/bin/node]
49: 0x101191548 node::crypto::TLSWrap::Cycle() [/opt/homebrew/Cellar/node/24.7.0/bin/node]
50: 0x101193d00 node::crypto::TLSWrap::OnStreamRead(long, uv_buf_t const&) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
51: 0x1011345c4 node::LibuvStreamWrap::OnUvRead(long, uv_buf_t const*) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
52: 0x101134a80 node::LibuvStreamWrap::ReadStart()::$_1::__invoke(uv_stream_s, long, uv_buf_t const) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
53: 0x10624baf0 uv__stream_io [/opt/homebrew/Cellar/libuv/1.51.0/lib/libuv.1.dylib]
54: 0x106252ca8 uv__io_poll [/opt/homebrew/Cellar/libuv/1.51.0/lib/libuv.1.dylib]
55: 0x106242b58 uv_run [/opt/homebrew/Cellar/libuv/1.51.0/lib/libuv.1.dylib]
56: 0x100fbd3cc node::SpinEventLoopInternal(node::Environment*) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
57: 0x10109ecfc node::NodeMainInstance::Run(node::ExitCode, node::Environment) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
58: 0x10109ea90 node::NodeMainInstance::Run() [/opt/homebrew/Cellar/node/24.7.0/bin/node]
59: 0x10104503c node::Start(int, char**) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
60: 0x18f18eb98 start [/usr/lib/dyld]
zsh: abort claude
I've done some additional debugging. I have not been able to resolve, but I have ruled out a number of potential causes.
Here's a summary prepared by Claude Code:
Summary
Claude Code crashes with a JavaScript heap out of memory error when an agent uses the Task tool to spawn a
sub-agent. The crash occurs during the initialization phase, before the sub-agent executes any tools or
performs any work.
Environment
Note: This issue affects all tested versions of Claude Code and all tested platforms, indicating a fundamental
issue in the agent orchestration system.
Reproduction Steps
Minimal Setup
Command That Triggers Crash
> run orchestrator for xxxxxx
Orchestrator successfully:
Error Output
<--- Last few GCs --->
[72406:0x138008000] 58025 ms: Mark-Compact 4003.5 (4113.2) -> 3994.1 (4120.2) MB, pooled: 0 MB, 855.54 / 0.00 ms
(average mu = 0.194, current mu = 0.097) allocation failure; scavenge might not succeed
[72406:0x138008000] 58941 ms: Mark-Compact 4011.2 (4121.2) -> 4001.1 (4127.5) MB, pooled: 0 MB, 899.04 / 0.00 ms
(average mu = 0.111, current mu = 0.019) allocation failure; scavenge might not succeed
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----
1: 0x10106f814 node::OOMErrorHandler(char const*, v8::OOMDetails const&)
[/opt/homebrew/Cellar/node/24.7.0/bin/node]
2: 0x1011ae97c v8::Utils::ReportOOMFailure(v8::internal::Isolate, char const, v8::OOMDetails const&)
[/opt/homebrew/Cellar/node/24.7.0/bin/node]
...
50: 0x101b36a50 Builtins_RunMicrotasks [/opt/homebrew/Cellar/node/24.7.0/bin/node]
51: 0x101b067b0 Builtins_JSRunMicrotasksEntry [/opt/homebrew/Cellar/node/24.7.0/bin/node]
52: 0x1012e37ac v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous
namespace)::InvokeParams const&) [/opt/homebrew/Cellar/node/24.7.0/bin/node]
The crash occurs in the microtask/promise fulfillment queue, suggesting an infinite or circular loading pattern
during agent initialization.
What Has Been Ruled Out
Through systematic debugging, we confirmed this is NOT caused by:
Critical Finding
The crash happens during sub-agent initialization ("Warping"), not during:
This suggests the issue is in Claude Code's agent metadata loading/preparation mechanism when spawning sub-agents
via the Task tool.
Hypothesis
When a sub-agent is spawned via Task:
Workarounds Attempted
❌ Increase Node.js heap limit (partial workaround)
export NODE_OPTIONS="--max-old-space-size=8192"
Result: May delay crash but doesn't fix root cause
❌ Reduce agent count/size
Result: Still crashes with 5 minimal agents (~45KB total)
❌ Avoid Task tool entirely
Result: Only workaround that works, but defeats purpose of agent orchestration
Expected Behavior
Sub-agent should initialize successfully and begin execution without memory issues.
Actual Behavior
Node.js heap overflow during sub-agent initialization, before any actual work is performed.
Impact
Additional Context
This affects production use of Claude Code's agent system. The orchestrator pattern (parent agent coordinating
multiple specialized sub-agents) is a documented feature but is currently completely unusable across all versions
and platforms due to this crash.
Project structure and agent definitions available upon request for reproduction.
It appears that this behavior is triggered whenever THINK Mode is active. Without it, everything works as expected.
#8836 #1421 #4953 #9690
Windows System Confirmation - Crashes at 8GB with 3 Sub-Agents
Confirming this issue affects Windows systems as well. Same memory leak behavior when spawning sub-agents for research tasks.
System Specs:
Behavior:
--max-old-space-size=8192(8GB)Error logs showing progression:
The memory leak appears to scale with the increased limit - suggesting something in the sub-agent initialization is consuming unbounded memory rather than hitting a reasonable ceiling. On a 32GB RAM system, 3 research agents should not require anywhere near 8GB of heap.
The issue is pretty easy to reproduce,
<img width="1100" height="342" alt="Image" src="https://github.com/user-attachments/assets/0b280625-eb9d-465c-b821-a7c028f0cec3" />
Instant crash 10gb of ram taken
same issue, happens a lot with latest claude
Any update on this issue? I paid for the Max subscription specifically to be able to handle a huge amount of agents working in tandem, yet turns out Claude Code can't handle running even one or two subagents without going down.
Here's output from Claude Code 2.0.75 running on Linux. My CLAUDE.md instructs the agent to always delegate tasks to project-manager agent which is supposed to delegate the tasks to further subagents. This is the FIRST task I've given to Claude in that session too, and I've done it right after clearing all Claude Code cache and conversation files to make sure it's a clean slate:
```● I'll delegate these bug fixes to the project manager agent who will coordinate the specialist agents to fix them.
project-manager(Fix 3 frontend UI bugs)
⎿ Waiting… > /home/[redacted]/.claude/state/progress-ledger.json << 'EOF'
(No content)
+17 more tool uses (ctrl+o to expand)
ctrl+b to run in background
· Elucidating… (esc to interrupt · 1m 34s · ↓ 678 tokens)
<--- Last few GCs --->
[570173:0x45355000] 143550 ms: Mark-Compact 4026.8 (4134.1) -> 4017.9 (4141.4) MB, pooled: 0 MB, 1454.21 / 0.00 ms (average mu = 0.288, current mu = 0.130) allocation failure; scavenge might not
succeed
[570173:0x45355000] 145613 ms: Mark-Compact 4034.1 (4141.6) -> 4024.4 (4147.9) MB, pooled: 0 MB, 2029.39 / 0.00 ms (average mu = 0.152, current mu = 0.017) allocation failure; scavenge might not
succeed
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----
1: 0xe1603a node::OOMErrorHandler(char const*, v8::OOMDetails const&) [claude]
2: 0x11e3540 v8::Utils::ReportOOMFailure(v8::internal::Isolate, char const, v8::OOMDetails const&) [claude]
3: 0x11e3817 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate, char const, v8::OOMDetails const&) [claude]
4: 0x14110f5 [claude]
5: 0x142a989 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [claude]
6: 0x13ff038 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [claude]
7: 0x13fff65 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [claude]
8: 0x13d8c3e v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [claude]
9: 0x183a25c v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long, v8::internal::Isolate) [claude]
10: 0x7f4aaf66c476```
Might or might not be related to #17835 but I've not seen a crash since I added instructions to CLAUDE.md instructing the orchestrator to explicitly forbid sub-agents from ever calling skills
My session 4bfc397a-6cc9-42d9-8617-6c1165a4d5e8 crashed because of this bug.
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.