Skip to content

Instantly share code, notes, and snippets.

@kju4q
Created August 6, 2026 16:56
Show Gist options
  • Select an option

  • Save kju4q/23a8219feecb887c2b9eab9247ce7804 to your computer and use it in GitHub Desktop.

Select an option

Save kju4q/23a8219feecb887c2b9eab9247ce7804 to your computer and use it in GitHub Desktop.
Nested agents in Claude Code: the three limits, the depth math, and how to not get cut off mid-run.

Nested Agents: the limits, the math, and the settings

Three things changed in Claude Code between July 1 and July 24, 2026. Agents can hire their own agents again, there is a hard ceiling on how many, and they all run in the background by default.

Everything below is quoted from the official changelog with version numbers, so you can verify any of it at code.claude.com/docs/en/changelog.

What actually changed

Nesting is back on, at depth 3 (v2.1.219, July 24)

Subagents can now spawn nested subagents up to depth 3 by default (was 1); set CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH=1 to disable nesting

The "was 1" only tells part of the story. Nesting originally shipped at five levels on June 10 (v2.1.172), was switched off by default on July 21 (v2.1.217), and came back at three on July 24. If you read something older that says five levels deep, that is why.

A per-session ceiling of 200 (v2.1.212, July 17)

Added a per-session cap on subagent spawns (default 200, override with CLAUDE_CODE_MAX_SUBAGENTS_PER_SESSION) to stop runaway delegation loops; /clear resets the budget

A concurrency cap of 20 (v2.1.217, July 21)

Added a cap on concurrently-running subagents (default 20, override with CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS) so one message can't fan out unbounded background agents

Background by default (v2.1.198, July 1)

Subagents now run in the background by default, so Claude keeps working while they run and is notified when they finish

The three limits, and how they interact

This is the part that catches people, because the three numbers do different jobs and only one of them is about parallelism.

Setting Default What it bounds
CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH 3 How many levels deep the tree goes
CLAUDE_CODE_MAX_SUBAGENTS_PER_SESSION 200 Total spawns across the whole session
CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS 20 How many run at the same moment

Depth controls shape, 200 controls budget, 20 controls throughput. Two hundred agents on one problem is real, but only twenty are working at any given second and the rest are queued behind them. If you have seen someone claim they ran hundreds in parallel, that is the misreading.

The session budget is cumulative rather than per message, and /clear resets it.

The depth math

Every agent can hire more agents, so your total is not the number you picked, it is that number compounding. At depth 3 with a branching factor of b, the total is b + b² + b³.

Agents per level Total spawned Against the 200 cap
3 39 fine
4 84 fine
5 155 fine
6 258 over
7 399 over

Five per level is the practical ceiling at full depth. Six puts you 58 over, and the run gets cut off partway through, which is worse than never starting it because you still pay for everything that ran before the cut.

If you need to cover more ground, go wider and shallower instead. At depth 2 the total is b + b².

Agents per level Total at depth 2
10 110
12 156
13 182
14 210 (over)

Thirteen wide across two levels reaches more than five wide across three, and it costs you less visibility.

Wall clock

With twenty running at once, 155 agents is roughly eight waves. If a single agent takes about a minute, that is eight minutes of real time rather than 155. Plan a big run against waves, not against the total.

When depth earns its cost

Use depth when you do not know the shape of the work yet. Migrating off an old API, auditing a codebase you have never opened, finding every place a pattern appears. The top agent surveys first, discovers the real breakdown, and builds the tree to fit what it found. You could not have specified that fan-out in advance because you did not know the number.

Use a flat fan-out when you already know the breakdown. One agent per file, one per project, one per test suite. Depth buys you nothing there, and it costs you the thing below.

What depth costs you

A parent only ever receives its child's final report, never the work. At three levels, something that goes wrong at the bottom reaches you as one confident sentence, three summaries removed from what actually happened. The deeper the tree, the more compression sits between you and the evidence.

Two things follow from that. Ask for specifics in the leaf prompts, file paths and line numbers rather than conclusions, so the compression has something concrete to carry upward. And treat a clean report from a deep tree with more suspicion than a clean report from a flat one.

The panel also caps at five rows with a scroll hint, and idle agents auto-hide after thirty seconds (v2.1.181), so what you can see is never the whole tree.

Cost control

Two hundred agents is real money, and the budget flag is the honest guard:

claude --max-budget-usd 5

Once the cap is reached, new spawns are denied and running background agents are halted (v2.1.217). Set it before a wide run rather than after one surprises you.

Notifications

An agent finishing or getting stuck fires the Notification hook with agent_needs_input or agent_completed (v2.1.198). You can route that anywhere, including your phone, which is what makes long runs practical to walk away from.

Run /hooks to wire it up. The config shape is easier to get right from the built-in editor than from a pasted snippet.

Check your own setup

claude --version

You need 2.1.219 or later for depth 3. Below that, nesting is off by default and none of the above applies.

env | grep SUBAGENT

Empty output means the defaults are in effect. Anything listed is overriding them, which is worth knowing before you blame the model for a run that stopped early.


Depth is for when you do not know the number. Width is for when you do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment