Bug Report: Uncontrolled Sub-Agent Recursive Loop Caused ~800k Token Consumption & $27.60 Unexpected Charge
Summary
A critical bug in Claude Code caused sub-agents to recursively spawn child agents without any depth limit, consuming approximately 800,000+ tokens in a single session with nearly zero useful output. This also triggered an unintended $27.60 Usage Credits charge beyond my Max Plan (5x) subscription.
---
Environment
- Product: Claude Code (CLI)
- Model: claude-sonnet-4-6
- Plan: Claude Max (5x)
- Date: June 19, 2026
- Account: xiao75981@gmail.com
---
What Happened
I asked Claude to conduct competitive research and Claude autonomously dispatched multiple sub-agents, each injected with the full web-access skill document. That skill document contains the following guidance:
"When tasks contain multiple independent research targets, it is encouraged to decompose and assign them to sub-agents for parallel execution."
Sub-agents read this instruction and interpreted their own subtasks as "multiple independent targets," causing them to spawn grandchild agents — which in turn spawned more agents. This created an infinite recursive loop running silently in the background.
---
Timeline
| Round | Agents Spawned | Result | Useful Output |
|-------|---------------|--------|---------------|
| Round 1 | 4 sub-agents | All failed (session limit) | None |
| Round 2 | 3 sub-agents | All failed (monthly spend limit / rate limited) | None |
| Round 3 | 2 sub-agents + recursive grandchild agents | All failed (process exit) | None |
| Total | 10+ agents | ~800k+ tokens consumed | Nearly zero |
Session usage went from ~46% → 88% during Round 3 alone. After the session limit was hit, Usage Credits were triggered — I did not intentionally enable this feature and was not clearly warned before the $27.60 charge occurred.
---
Root Cause Analysis
Bug 1 — No recursion depth limit for sub-agents [Critical]
Sub-agents are permitted to spawn their own sub-agents without any maximum depth restriction. A sub-agent should never be allowed to spawn further agents by default.
Suggested fix: Enforce a maximum agent recursion depth of 1 (sub-agents cannot spawn further agents) or at minimum add a hard cap at depth 2.
Bug 2 — Skill document "sub-agent" instructions apply to sub-agents unintentionally [Critical]
The web-access skill's guidance to "use sub-agents for parallel tasks" was intended for the top-level Claude instance only. Sub-agents load the same skill document and follow the same instruction, creating a recursive trigger.
Suggested fix: Add explicit context to skill documents: "This guidance applies to the top-level agent only. Sub-agents must not spawn further agents." Or strip agent-spawning guidance from skill documents before injecting into sub-agent contexts.
Bug 3 — No real-time token consumption visibility during agent execution [High]
Users cannot monitor sub-agent token consumption while agents run. The only way to check is manually visiting claude.ai/settings/usage — by which point significant damage may already be done.
Suggested fix: Show live token consumption in the Claude Code terminal UI while agents are running.
Bug 4 — Usage Credits triggered without prominent confirmation [High]
Usage Credits appear to have activated when the plan limit was reached. There was no prominent confirmation dialog or warning at the moment of activation. This resulted in a $27.60 charge the user did not explicitly authorize.
Suggested fix: Require explicit user confirmation (not just a pre-existing toggle) before Usage Credits are charged. Show a blocking prompt: "You've reached your plan limit. Enable Usage Credits to continue? This will charge your payment method."
Bug 5 — No mechanism to force-stop running background agents [Medium]
Once abnormal consumption was detected, there was no command or UI option to immediately terminate all running background agents.
Suggested fix: Add a /stop-agents command or a keyboard shortcut to immediately terminate all background agents.
---
Impact
- ~800,000+ tokens consumed with nearly zero useful output
- $27.60 charged beyond Max Plan subscription without clear user consent
- Session fully depleted, blocking productive work for the remainder of the billing period
---
Steps to Reproduce
- Use Claude Code with a skill that contains guidance to "use sub-agents for parallel tasks"
- Ask Claude to perform a multi-part research task
- Claude dispatches sub-agents with the full skill document injected
- Sub-agents read the skill's parallelization guidance and spawn their own child agents
- Recursive loop begins — observe token consumption spike with no useful output
---
Request
- Please investigate and confirm the recursive agent spawning bug
- Please consider a refund of the $27.60 Usage Credits charge caused by this system bug
- Please prioritize fixes for Bugs 1 and 2 above as they represent a critical safety/cost risk for all Claude Code users
---
Reporter: Yuan Xiaotian (袁啸天)
Contact: xiao75981@gmail.com
Showing cached comments. Read the full discussion on GitHub ↗
8 Comments
Additional Evidence — Screenshot of Usage Page
Attaching a description of the usage screenshot taken immediately after the incident (screenshot will be uploaded manually):
Settings → Usage page shows:
| Metric | Value |
|--------|-------|
| Current session | 90% used (resets in 3h 33min) |
| Weekly — All models | 25% used |
| Weekly — Sonnet only | 12% used |
| Usage Credits spent | $27.60 — 100% used |
| Usage Credits reset | July 1 |
| Monthly spend limit | $0.00 (was not set by user) |
| Usage Credits toggle | OFF (currently disabled — user turned it off after discovering the charge) |
Key Points from Screenshot
Additional UX Issue Identified
The Usage Credits monthly spend limit defaults to $0.00 with no cap. Users are not guided to set a spending limit during onboarding. Combined with the lack of a confirmation dialog before Usage Credits are first triggered, this creates a situation where a single bug or accidental action can result in unbounded charges.
Suggested improvement: Set a default monthly spend cap (e.g., $10) for new users, with a clear prompt to adjust it. Require explicit confirmation the first time Usage Credits would be charged.
---
Screenshot to be attached manually to this issue.
<img width="1910" height="1416" alt="Image" src="https://github.com/user-attachments/assets/e4459ffc-d843-42f3-bec9-0620cd582021" />
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
The root cause you're hitting -- agents recursively spawning with no depth cap -- is a known gap in Claude Code's built-in supervision. What makes it expensive is that there's no ambient monitoring layer watching token burn across sessions before the damage is done. I've been building Claudiverse (https://claudiverse.ai) as a Mac-native control plane for exactly this: it wraps local Claude Code sessions and surfaces real-time spend + agent activity so you can catch runaway subagent trees before the bill hits. Disclosure: I'm the founder. No fix for the underlying bug here, but wanted to surface it since your report describes the gap pretty precisely.
Confirming this is a system design issue, not user error.
The root cause is skill document scope bleeding: when a sub-agent receives a skill that says "decompose multi-target tasks by spawning sub-agents," the sub-agent has no way to know that instruction was meant for the top-level orchestrator only. Every agent in the tree acts as if it is the root.
A few things that would have contained this without waiting on a platform fix:
AGENT_DEPTH=1passed at spawn time, with skill documents checkingif AGENT_DEPTH > 0: do not spawn additional agents. Clunky, but it works today with hooks.Agent(orTask) that fires when agent count in the current session exceeds N, requiring an explicit user approval before continuing.The Usage Credits trigger without real-time blocking confirmation is the sharpest edge here. A vague past toggle should not constitute consent for a $27 charge. That part needs a platform-level fix, not a workaround.
Worth cross-referencing #69635 (ultra workflow auto-scaling to 130 agents triggering IP blocks) and #69732 (notification routing bugs that cause stalled chains to silently retry). These seem to share a root of "the system makes resource decisions the user cannot observe or interrupt in real time."
The missing depth limit is the scary part — a flat token cap doesn't really save you because the spawn tree explodes faster than you'd notice. I hit the OS-level version of this: an agent stuck re-spawning subprocesses took my Mac to load average 307 before I caught it. A dollar/token cap was always too late, so I ended up killing the process tree on the "high resource use + no output progress" signal instead. Doesn't patch the depth-limit gap in the harness, but it stops the machine going down with the run: https://github.com/IgorGanapolsky/mac-yolo-safeguards
On recursive sub-agent depth / token burns: an outer watchdog that kills the session when tool thrash produces no new progress has been more reliable for me than hoping the model self-stops. Open-source sketch: https://github.com/IgorGanapolsky/mac-yolo-safeguards
Not a Claude Code fix — just an operator-side belt if others are still getting $20+ no-output loops.
The recursive subagent loop that burned 800k tokens with almost zero output is exactly why we need a real control layer.
MartinLoop adds hard budget caps, verification before apply, rollback on failure, and full audit receipts. No more silent explosions or lost intermediate work.
This pattern is showing up everywhere right now. Repo if you want to see the direction: https://github.com/keesan12/martin-loop