Bug Report: Uncontrolled Sub-Agent Recursive Loop Caused ~800k Token Consumption & $27.60 Unexpected Charge

Open 💬 8 comments Opened Jun 19, 2026 by xiaotian283829691-dotcom

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

  1. Use Claude Code with a skill that contains guidance to "use sub-agents for parallel tasks"
  2. Ask Claude to perform a multi-part research task
  3. Claude dispatches sub-agents with the full skill document injected
  4. Sub-agents read the skill's parallelization guidance and spawn their own child agents
  5. Recursive loop begins — observe token consumption spike with no useful output

---

Request

  1. Please investigate and confirm the recursive agent spawning bug
  2. Please consider a refund of the $27.60 Usage Credits charge caused by this system bug
  3. 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

View original on GitHub ↗

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