til/applied-sciences/engineering/claude-code-subagents
claude-code-subagents.mdupdated 2026-07-163456 words
ダブルクリックで英日反転
Applied Sciences · Engineering

Claude Code Subagents: When Parallel Actually Means Parallel

EN

Calling multiple Agent tools in one assistant message runs them concurrently. Calling them one per turn is serial. That single distinction changes everything about how you design multi-agent workflows.

What a subagent is

  • Independent conversation instance with its own context window, system prompt, tools, and model.
  • Launched via the Agent tool (formerly Task, renamed in v2.1.63).
  • Defined as Markdown + YAML front matter in .claude/agents/ or ~/.claude/agents/.
  • A subagent cannot spawn further subagents — nesting is explicitly forbidden.

Parallelism conditions

  • Multiple Agent calls in one assistant reply → harness runs them simultaneously.
  • One Agent call per turn → serial execution, not parallel.
  • The only channel parent→subagent is the prompt string; no shared context.
  • No explicit numeric cap documented; rate limits and context windows are the practical bounds.

When parallel pays off

  • Mutually independent tasks (test runner + linter + security scanner at once).
  • Results are summaries only — keeps parent context from swelling.
  • File ownership is cleanly divided between agents.
  • Anthropic case study: parallelisation cut investigation time by up to 90%.

When parallel hurts

  • Same file edited by multiple agents → race condition, last writer wins.
  • Dependent tasks (B needs A's output) → launch sequentially instead.
  • Redundant exploration → 3 similar greps = 3× tokens for the same data.
  • Total tokens scale as N× even if wall-clock stays roughly flat.
Parallel subagents save wall-clock time, not compute — only worth it when sub-tasks are genuinely independent.
Applied Sciences · Engineering

Claude Code サブエージェント:​「並列」が​本当に​並列に​なる​条件

JP

1つの​アシスタントメッセージ内で​複数の​Agentツールを​呼び出すと​同時実行に​なる。​ターンを​またいで​1件ずつ呼ぶと​直列に​なる。​この​違いを​把握するだけで​マルチエージェント設計が​大きく​変わる。

サブエージェントとは

  • 親会話とは​独立した​コンテキストウィンドウ・システムプロンプト・ツール・モデルを​持つ別会話インスタンス。
  • Agentツール​(旧名Task、​v2.1.63で​リネーム)で​起動する。
  • .claude/agents/ または​ ~/.claude/agents/ に​Markdown+YAMLで​定義。
  • サブエージェントが​さらに​サブエージェントを​生成する​ネスト​(入れ子)は​明示的に​禁止。

並列実行の​条件

  • 1つの​アシスタント返信に​複数の​Agent呼び出しを​並べる​ → ハーネス​(実行基盤)が​同時実行。
  • ターンごとに​1件ずつ呼ぶ → 直列実行。
  • 親から​サブへ​渡せる​情報は​プロンプト文字列のみ。​コンテキストは​共有されない。
  • 同時実行の​上限値は​公式文書に​明記なし。​実際は​レート制限と​コンテキスト長が​上限。

並列が​有効な​ケース

  • 相互に​独立した​作業​(テスト・リンター・セキュリティスキャンを​同時実行など)。
  • 結果を​サマリーのみで​返し、​親コンテキストの​肥大化を​防ぎたい​場合。
  • エージェント間で​ファイルの​所有権が​明確に​分離されている​場合。
  • Anthropic事例:並列化で​調査時間を​最大90%短縮と​報告。

並列が​逆効果に​なる​ケース

  • 複数エージェントが​同一ファイルを​書き換える​ → 競合​(レースコンディション)で​最後の​書き込みだけ残る。
  • Bが​Aの​出力を​前提と​する​依存関係が​ある​場合 → 直列実行に​切り替える。
  • 同じ​探索を​重複実行 → 3つの​類似grepは​同じ情報を​トークン3倍で​読む。
  • 壁時計時間​(実経過時間)は​横ばいでも​トークン総量は​N倍。
並列サブエージェントが​節約するのは​壁時計時間であって​計算量ではない。​サブタスクが​本当に​独立している​場合に​のみ​有効。
148 notestil