Claude Code Caps Runaway Subagent Fan-Out and Enforces Budget Limits

Claude CodeView original changelog

Claude Code 2.1.217 introduces hard limits on how many subagents a single message can spawn: a default cap of 20 concurrently running subagents (adjustable via CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS), and a default block on subagents spawning further nested subagents (adjustable via CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH). The release also fixes --max-budget-usd so it actually halts background subagents once the spending cap is reached, closing a gap where the budget limit did not apply to background work. Together these changes protect developers from unbounded, unexpectedly expensive agent fan-out.

Key Takeaways

  • A default cap of 20 concurrent subagents now applies to any single message, preventing unbounded parallel fan-out; raise it with CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS if needed.
  • Subagents no longer spawn nested subagents by default, closing off a recursive fan-out path that could previously run unchecked; CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH opts back into deeper nesting.
  • --max-budget-usd now actually halts background subagents once the cap is hit, fixing a prior gap where budget limits didn't reliably stop in-flight background work.
  • The changes directly target the most common driver of runaway Claude Code billing incidents reported by users: hook recursion, retry storms, and subagent fan-out.
  • Anthropic's own data shows subagent-heavy workflows can consume roughly 7x the tokens of a single-thread session, making unmetered fan-out an outsized cost risk.
  • This is a safety-by-default change, not an opt-in feature, existing workflows that rely on high concurrency will need to explicitly raise the new limits.

Closing the Runaway-Cost Gap

Subagents in Claude Code let a single request fan out into many parallel workers, each consuming its own share of tokens. That power came with a risk: nothing previously stopped one message from spawning an effectively unlimited number of subagents, or those subagents from spawning further subagents recursively. Reports of Claude Code sessions burning through thousands of dollars in API spend overnight, often traced to exactly this kind of fan-out or hook recursion, have circulated among developers for months.

Claude Code 2.1.217 addresses this directly with two new limits and one important fix.

Concurrency and Depth Caps

A single message can now spawn at most 20 concurrently running subagents by default. Teams that need more parallelism can raise the ceiling with the CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS environment variable. Separately, subagents no longer spawn nested subagents of their own by default at all, a change from prior behavior, with CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH available for workflows that genuinely need deeper nesting.

Budget Enforcement That Actually Enforces

The release also fixes --max-budget-usd so that reaching the configured spend cap denies new subagent spawns and halts any background subagents still running, rather than letting them continue unmetered. Previously, the budget flag did not reliably stop background agent work once triggered, meaning a spend limit could be breached by agents that were already in flight.

Why It Matters

These changes shift responsibility for cost containment from the developer manually watching their spend dashboard to the tool itself. For anyone building multi-agent workflows or leaning on Claude Code's background agents view for longer-running work, this is a meaningful safety net against the exact failure mode, unbounded fan-out, that has produced some of the more expensive Claude Code cost surprises reported by users.


Mentioned onGitHubX (Twitter)
Claude Code Caps Subagent Fan-Out, Enforces Budgets | Yet Another Changelog