CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH

環境変数

メイン会話の下に許可されるサブエージェントのレイヤー数(既定: 3)である。既定では、サブエージェントは自身のサブエージェントを生成でき、第 3 レイヤーのサブエージェントはさらに生成できない。1 を設定するとネストが無効になる。v2.1.217 から v2.1.218 では既定値は 1 で、上限を引き上げない限りサブエージェントは自身のサブエージェントを生成できず、v2.1.219 で既定値が 3 に引き上げられた。通常の数字で表された正の整数を受け付け、それ以外の値は無視されるため、上限は調整できるが撤廃はできない。Claude Code v2.1.217 以降が必要である

使い方・用途

  • サブエージェントのネストの深さを既定の 3 層から変えたい場合に、メイン会話の下に置けるサブエージェントの層数をこの値で指定する。
  • サブエージェントがさらに自分のサブエージェントを起動するのを禁止したい場合に、1 を設定してネストを無効にする。
  • SDK で runs の実行範囲を深さで制限したい場合に、並行数や支出上限と組み合わせて境界を設ける。
英語原文

Number of subagent layers allowed below the main conversation (default: 3). At the default, subagents can spawn their own subagents, and a subagent at the third layer can't spawn further; set 1 to turn nesting off. In v2.1.217 through v2.1.218, the default was 1, so a subagent couldn't spawn its own unless you raised the limit; v2.1.219 raised the default to 3. Accepts a positive whole number in plain digits; anything else is ignored, so the limit can be adjusted but not removed. Requires Claude Code v2.1.217 or later

関連ドキュメント

関連する変更履歴

v2.1.219(1件)

サブエージェントがネストされたサブエージェントを生成できる深さを、デフォルトで 1 から 3 に引き上げました。
英語原文を表示
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

変更後

より多段階で複雑なタスクの分解・実行を自動化できます。

関連ドキュメント

v2.1.217(1件)

サブエージェントのネスト生成をデフォルトで無効化しました。
英語原文を表示
Changed subagents to no longer spawn nested subagents by default; set CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH to allow deeper nesting

変更後

サブエージェントの階層が深まりすぎて、処理の追跡が困難になる状況を避けられます。