AIToday
Large Language ModelsAI Coding AssistantsZenn AI/MLPublished: Oct 7, 2026, 22:00 JST

Claude Code subagents spawn grandchildren, depth set by env var CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH

Claude Code subagents spawn grandchildren, depth set by env var CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH

3 Key Points

  1. What happened

    In Claude Code 2.1.285, a chain of four layers stopped at max_depth=3 and spawned_by_subagents=2, meaning grandchildren and great-grandchildren ran; setting CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH to 1, 2, 3, 4, or 5 matched the requested tier in all 13 runs.

  2. Why it matters

    Since 3 is the default and not a ceiling, teams building multi-step agent workflows seem unable to rely on the default depth staying put.

  3. What to watch

    When the depth limit is hit, the run stops quietly — refused.depth_limit stayed 0 across all 39 runs, so the blockage shows up as 'no grandchild,' not as an error. Make depth explicit rather than trusting the default.

WHO IT HITSDevelopers and teams who build multi-step agent workflows in Claude Code and rely on subagents to delegate tasks. Because the default effective depth shifted from 1 to 3 within a single session, workflows that depend on the default depth look unreliable, and those who need a fixed depth may need the environment variable set explicitly.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, in your inbox every morning.

Context & Analysis

The test used a four-layer chain in which each layer was told to delegate to the next, and the last layer was told to answer itself. The JSON output's subagent_stats field, rather than the AI's narration, provided the count: spawned=3, max_depth=3, spawned_by_subagents=2, completed=3, failed=0, with by_type showing layer1, layer2, and layer3. The prepared layer4 did not appear. This pattern held across three runs with no byte-level differences, which is why the author concluded that grandchildren were reached but a fourth layer was not.

Setting the environment variable changed the picture. With values 1, 2, 3, 4, and 5, all 13 runs matched the requested depth, and the author notes that raising the value also takes effect, so 3 is not a ceiling. A related observation concerns visibility: refused.depth_limit was 0 in all 39 runs, and a subagent at the nesting limit is normally not offered the tool itself. The search for a grandchild that is not running therefore returns no error, which the author says caused confusion.

The most difficult part was the first four runs, which stalled at one tier despite the same settings later reaching three. A remote feature flag name, maxSubagentSpawnDepthFromGrowthBook, appeared in the executable alongside other remotely fixed values, but the flag's value is not externally visible, so the cause remains unverifiable. Hooks also could not distinguish child from grandchild: across 175 logged lines, no key contained depth or parent information. For practitioners, the practical reading is that depth-sensitive designs may be safer with an explicit environment variable rather than relying on the default.

FAQ
Can subagents in Claude Code create their own subagents?
Yes. In Claude Code 2.1.285, a test with a four-layer chain returned spawned_by_subagents=2, meaning grandchildren and great-grandchildren ran. A fourth layer prepared for the test did not appear in the output, so the chain stopped at 3 tiers.
Is 3 the maximum depth for Claude Code subagents?
No. When CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH was set to 1, 2, 3, 4, and 5, all 13 runs matched the specified tier. Three is the default, not a ceiling.
Why does the depth limit not appear in the logs?
refused.depth_limit stayed 0 across all 39 runs. A subagent at the nesting limit is normally not offered the tool at all, so it stops quietly at a shallow level instead of recording a refusal.
Does the default depth stay the same every time?
No. In the first four runs of the session, the depth stopped at 1 tier even without a cap; later runs reached 3 tiers with the same settings and no file changes. The cause was not determined.

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Related Articles

Next articleopenTPU uses AI to design AI chips, runs Qwen3 on FPGA