[Bug] Background general-purpose sub-agents recursively self-spawn causing exponential fan-out and usage limit exhaustion
Bug Description
Title: Background general-purpose sub-agents recursively self-spawn → exponential fan-out → exhausts usage limit
Severity: High — silently burned the entire usage limit; runaway continued after the host session exited.
Environment: Claude Code CLI, model Opus 4.8 (1M context), macOS (darwin 24.6).
What happened:
Parent session made 2 Agent calls with subagent_type: general-purpose, model: sonnet, run_in_background: true (two web-research tasks: "BASE24" and "PowerZaC"). Instead of researching, each root agent
spawned 5 sub-agents. Because spawned children defaulted to general-purpose (which retains access to the Agent tool), they recursively spawned more — exponential growth.
Forensic evidence (from ~/.claude/projects/<proj>/<session>/subagents/):
- ~242 agent transcripts, 83 MB, 226 of them >50 KB (real token spend).
- 251 total Agent/Task spawn calls; 49 agents spawned children. Each root made 5 spawn calls.
- Timeline: 13:30 (2) → 13:32 (17) → 13:34 (16) → 13:35: 188 agents in a single minute before crash.
- 192/242 transcripts reference the original task topic → confirmed descendants.
Expected behavior:
- A research sub-agent should not be able to trigger unbounded recursive self-spawning.
- general-purpose sub-agents arguably should not retain the Agent tool by default (recursion vector), or recursion depth should be hard-capped low (the 1000-agent backstop is far too high to prevent
limit exhaustion).
- run_in_background agents orphaned by a host /exit should be terminated, not keep spawning.
Impact: Entire usage limit consumed with no user-visible warning; no way to stop it once the session exited.
Environment Info
- Platform: darwin
- Terminal: ghostty
- Version: 2.1.181
- Feedback ID: 9c4e88e4-f4f0-4e16-a996-5184cd76e402
Errors
[]This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗