← Academy 日本語で学ぶ(一覧へ戻る)

introduction to subagents

Anthropic Academy コースの日本語ナレッジ(学習用)/ 全 5 項目

Anthropic Academy「Introduction to subagents」全文ナレッジノート

Claude Code のサブエージェント機能入門コース(全4レッスン)の日本語ナレッジ。英語コースを中嶋さんの学習用に日本語で読めるよう、各レッスンを3層構成(①日本語ナレッジ=要点整理/②日本語=本文の自然な全訳/③英語逐語=動画字幕+本文原文)で収録。

  • コース: Anthropic Academy / Introduction to subagents
  • ナレッジ化日: 2026-07-04
  • 構成: 4レッスン(テキストレッスン+各埋め込み動画)

目次

# ノート 動画ID 1行説明
1 01_what_are_subagents.md jKErNxuxPXg サブエージェント=独立コンテキストで動き要約だけ返す委任先。コンテキスト管理の仕組み・組み込み3種(General purpose / Explore / Plan)
2 02_creating_a_subagent.md arD6qEWa2Xc /agents での作成手順(スコープ→生成→ツール→モデル→色)。frontmatter 5フィールド(name/description/tools/model/color)と system prompt、"proactively" で自動委任
3 03_designing_effective_subagents.md WPxWKT_OaU4 効果的な4要素=具体的 description・出力フォーマット定義・障害報告・ツール制限。name/description がシステムプロンプトに入り起動と入力プロンプトの両方を操縦
4 04_using_subagents_effectively.md n5LoKZ8Oa-A 決定ルール「途中作業は重要か?」。使う=リサーチ/レビュー/カスタムプロンプト。避ける=専門家ペルソナ/逐次パイプライン/テストランナー

このコースの芯(4レッスン通しての結論)

  • サブエージェント=隔離スレッド:独立コンテキストで作業し、要約だけをメインに返す。途中のファイル読み・検索・ツール呼び出しはメインを汚さない。トレードオフは「どう至ったか」の可視性喪失。
  • 作成は /agents:YAML frontmatter(name / description / tools / model / color)+本文=system prompt の markdown を .claude/agents/ に保存。Claude に生成させるのが推奨。
  • 設計の要は description と出力フォーマットname/description はメインのシステムプロンプトに入り、起動タイミングと入力プロンプトの両方を決める。出力フォーマット定義は「走りすぎ防止」と「完了判定」の最重要改善。ツールは必要最小限(研究=read-only、レビュー=+bash、変更=+edit/write)。
  • 使い所の唯一の判断軸=「途中作業がメインスレッドにとって重要か?」:重要でない→委任、重要→メインに留める。適所=リサーチ/コードレビュー/カスタムシステムプロンプト。不適=専門家ペルソナ・逐次パイプライン・テストランナー(全構成中で最も成績が悪かった実測あり)。

ソース

  • 本文: scratchpad/cc_courses/subagents_text.md(4レッスン区切り)
  • 字幕: scratchpad/cc_courses/subs/<動画ID>.en.vtt
↑ 目次へ戻る

Introduction to subagents | Lesson 01「サブエージェントとは何か(What are subagents?)」

出典: Anthropic Academy / YouTube動画ID jKErNxuxPXg / 2026-07-04

日本語ナレッジ(要点整理)

  • サブエージェントとは:Claude Code がタスクを委任できる専門アシスタント。それぞれが独立したコンテキストウィンドウで動き、作業を終えると要約だけをメインスレッドに返す。途中のファイル読み込み・検索・ツール呼び出しはすべて隔離され、メイン会話を汚さない。
  • なぜ重要か(コンテキスト管理):Claude Code と話すたびに、すべてのツール呼び出しと結果がメインのコンテキストウィンドウに蓄積される。この領域は有限で、埋まると Claude は会話の前半を見失っていく。サブエージェントは別ウィンドウを立ち上げることでこれを解決する。
  • サブエージェントが受け取る2つの入力: 1. 設定ファイルで定義したカスタムシステムプロンプト(サブエージェントの役割と振る舞いを定義) 2. あなたの依頼に基づき親エージェントが書いたタスク説明
  • 動作:サブエージェントは自律的に作業(ファイル読み込み・検索・コード編集など)し、完了時に要約のみをメイン会話へ返す。サブエージェントの会話全体はその後破棄される。
  • トレードオフ:メインコンテキストはきれいに保たれる(=答えだけ得られ、探索の雑音は残らない)が、サブエージェントがどう結論に至ったか、途中で何を発見したかの可視性は失われる
  • 具体例:不慣れなコードベースで「どのサービスが返金(refunds)を処理するか」を知りたい場合。サブエージェントなしだと Claude は15ファイル読み・複数の検索・複数の関数呼び出しを辿り、たった1つの事実のためにコンテキストが埋まる。サブエージェントを使えば Explore サブエージェントが自分のコンテキストで掘り下げ、絞り込んだ答えを返すので、メインには「質問」と「要約」だけが記録される。
  • 組み込みサブエージェント(すぐ使える)
  • General purpose(汎用):探索と実行の両方を要する多段タスク向け
  • Explore:コードベースの高速検索・ナビゲーション向け
  • Plan:プランモード中に、プラン提示前のコードベース調査・分析に使う
  • カスタムサブエージェント:組み込み以外に、独自のシステムプロンプトとツールアクセスを持つ自作サブエージェントを作れる(コードレビュアー、テストライター、ドキュメント生成など)。
  • 3つの主要メリット:①作業を焦点の絞られた単位に分割 ②途中作業を隔離してメインコンテキストを清潔に保つ ③必要な情報だけを簡潔な要約として持ち帰る。メインコンテキストの雑音が少ないほど、長く効果的に作業できる。

日本語(本文の自然な全訳)

サブエージェントとは何か

サブエージェントは、Claude Code がタスクを委任できる専門アシスタントです。焦点を絞ったヘルパーだと考えてください。各サブエージェントは自分自身のコンテキストウィンドウの中で動き、自分の仕事をこなし、要約をメインスレッドに返します。途中のステップ——すべてのファイル読み込み、検索、ツール呼び出し——は隔離されたまま保たれ、メイン会話を散らかすことは決してありません。

なぜサブエージェントが重要か

Claude Code とチャットするたびに、あなたはメインのコンテキストウィンドウに情報を追加しています。すべてのツール呼び出し、すべてのファイル読み込み、すべての検索結果がそこに保存されます。その領域は有限であり、いったん埋まると、Claude は会話の前半部分を見失い始めます。

サブエージェントは、別個のコンテキストウィンドウを立ち上げることでこれを解決します。サブエージェントは2つのものを受け取ります:

  • サブエージェントの役割と振る舞いを定義する、あなたの設定ファイルからのカスタムシステムプロンプト
  • あなたが依頼した内容に基づいて親エージェントが書いたタスク説明

サブエージェントはその後、自分で作業します。ファイルを読み、検索を走らせ、コードを編集し——必要なことは何でもします。作業が終わると、要約だけがメイン会話に返ってきます。そしてサブエージェントの会話全体は破棄されます。

これはつまり、あなたのメインコンテキストがきれいなまま保たれるということです。答えを見つけるまでの道のりの雑音を一切伴わずに、答えだけが得られます。トレードオフは、サブエージェントがどのように結論に達したかについての可視性を失う点です。

実践的な例

たとえば、あなたが不慣れなコードベースを調べていて、どのサービスが返金を処理するのかを知りたいとします。サブエージェントがなければ、Claude は15ファイルを読み、いくつもの検索を走らせ、複数の関数呼び出しを辿るかもしれません。必要だったのはたった1つの事実だけなのに、そのすべてがあなたのコンテキストウィンドウを埋めてしまいます。

サブエージェントがあれば、体験はずっとクリーンになります。あなたが質問すると、Explore サブエージェントが立ち上がり、自分のコンテキストの中でその掘り下げをすべて行い、焦点を絞った答えを返します。

あなたのメインコンテキストウィンドウには、質問と要約だけが記録されます——道中で読まれた15ファイルは記録されません。

組み込みサブエージェント

Claude Code には、すぐに使えるいくつかの組み込みサブエージェントが同梱されています:

  • General purpose サブエージェント——探索と実行の両方を必要とする多段階タスク向け
  • Explore——コードベースの高速な検索とナビゲーション向け
  • Plan——プランモード中に、プランを提示する前のコードベースの調査・分析に使われる

カスタムサブエージェント

組み込みの選択肢に加えて、独自のシステムプロンプトとツールアクセスを持つ自作のサブエージェントを作成できます。これにより、あなたのワークフローに合わせた専門エージェント——コードレビュアー、テストライター、ドキュメント生成器、その他必要なものなら何でも——を定義できます。

キーテイクアウェイ

サブエージェントは3つの主要なメリットをもたらします:

  • 作業を焦点の絞られた単位に分割し、各サブエージェントが特定のタスクに集中できるようにする
  • すべての途中作業を隔離することで、メインのコンテキストウィンドウをきれいに保つ
  • 必要な情報だけを簡潔な要約として持ち帰る

組み込みのサブエージェントを使うにせよ、自作するにせよ、これらは長い Claude Code セッションをより活用するための実践的な方法です。メインコンテキストの雑音が少ないほど、より長く、より効果的に作業できます。

英語逐語(動画字幕 or 本文原文)

動画字幕(YouTube: jKErNxuxPXg・重複除去済み)

Sub-agents are specialized assistants that Claude can delegate tasks to. Each sub-agent runs in its own conversation context window with a custom system prompt that you define. When finished, it returns a summary to the main thread while all the intermediate work stays isolated.

One of the main advantages of sub-agents is that they help manage context window usage. When you chat with Claude Code, you're adding context to the main context window. Every tool call and its results get stored in this main context window.

And so, when Claude uses a sub-agent, a separate window starts. The sub-agent receives two inputs, a custom system prompt from your configuration file, and a task description written by the parent agent based on what you ask for.

The sub-agent then works autonomously. When it reads files, edits files, or uses tools, none of these will appear in the main conversation. Just a summary is returned back. The entire sub-agent conversation then gets completely discarded.

Consider a task like investigating how the payment system works in an unfamiliar code base. Maybe you're trying to use Claude Code to figure out which service handles refunds. Well, without a sub-agent, Claude might read 15 files, run several searches, and trace through multiple function calls. All of that context fills your context window, even if you only needed one single fact, which service handles refunds.

With a sub-agent, you get the answer without the journey. The sub-agent explores, discovers the answer, and returns a focused summary, keeping your main context clean. But, the main window loses visibility into how the sub-agent reaches its conclusions and what it discovered along the way.

Claude Code includes several built-in sub-agents that you can use immediately, like the general-purpose sub-agent, used for multi-step tasks that require both exploration and action. The explore sub-agent, used for fast searching of code bases. The plan sub-agent, used during plan mode for research and analysis of your code base before presenting a plan.

And you can also create your own sub-agents with custom system prompts and tool access.

Sub-agents like Claude Code break work into focused pieces, keep your main context window clean, and bring back just what you need, whether you're using the built-in ones or creating your own. They're a practical way to get more out of longer Claude Code sessions.

本文原文(テキストレッスン)

What are subagents?

Subagents are specialized assistants that Claude Code can delegate tasks to. Think of them as focused helpers: each one runs in its own conversation context window, does its work, and returns a summary to the main thread. The intermediate steps -- all the file reads, searches, and tool calls -- stay isolated and never clutter your main conversation.

Why Subagents Matter

Every time you chat with Claude Code, you're adding to the main context window. Every tool call, every file read, every search result gets stored there. That space is finite, and once it fills up, Claude starts losing track of earlier parts of the conversation.

Subagents solve this by spinning up a separate context window. The subagent receives two things:

A custom system prompt from your configuration file that defines the subagent's role and behavior
A task description written by the parent agent based on what you asked for

The subagent then works on its own. It reads files, runs searches, edits code -- whatever it needs to do. When it's done, only a summary comes back to your main conversation. The entire subagent conversation is then discarded.

This means your main context stays clean. You get the answer without all the noise of the journey it took to find it. The tradeoff is that you lose visibility into how the subagent reached its conclusions.

A Practical Example

Say you're exploring an unfamiliar codebase and you want to know which service handles refunds. Without a subagent, Claude might read 15 files, run several searches, and trace through multiple function calls. All of that fills your context window, even though you only needed one fact.

With a subagent, the experience is much cleaner. You ask the question, the Explore subagent spins up, does all that digging in its own context, and hands back a focused answer.

Your main context window only records the question and the summary -- not the 15 files that were read along the way.

Built-in Subagents

Claude Code ships with several built-in subagents you can use right away:

General purpose subagent -- for multi-step tasks that require both exploration and action
Explore -- for fast searching and navigation of codebases
Plan -- used during plan mode for research and analysis of your codebase before presenting a plan

Custom Subagents

Beyond the built-in options, you can create your own subagents with custom system prompts and tool access. This lets you define specialized agents tailored to your workflow -- a code reviewer, a test writer, a documentation generator, or anything else you need.

Key Takeaways

Subagents give you three main benefits:

They break work into focused pieces, letting each subagent concentrate on a specific task
They keep your main context window clean by isolating all the intermediate work
They bring back just the information you need as a concise summary

Whether you're using the built-in subagents or creating your own, they're a practical way to get more out of longer Claude Code sessions. The less noise in your main context, the longer and more effectively you can work.
↑ 目次へ戻る

Introduction to subagents | Lesson 02「サブエージェントを作る(Creating a subagent)」

出典: Anthropic Academy / YouTube動画ID arD6qEWa2Xc / 2026-07-04

日本語ナレッジ(要点整理)

  • カスタムサブエージェントの正体:YAML frontmatter を持つ markdown ファイル。frontmatter が「いつ使うか(when)」を Claude に伝え、本文が「どう振る舞うか(how)」の指示を与える。
  • 作成手段は /agents スラッシュコマンド:サブエージェント管理のメインインターフェースが開く。そこで Create new agent を選ぶ。
  • ① スコープの選択
  • Project-level:現在のプロジェクトでのみ利用可能
  • User-level:マシン上のすべてのプロジェクトで共有
  • ② 作成方法の選択:手動で書くこともできるが、推奨は Claude に生成させる方法。やりたいことを説明すると、Claude が namedescription・system prompt を生成する。
  • ③ ツールのカスタマイズ:サブエージェントがアクセスできるツールを選ぶ。カテゴリは Read-only tools/Edit tools/Execution tools/MCP tools/Other tools。本当に必要なものだけ与える。例:コードレビュアーは Edit tools 不要(読んで分析するだけで変更しない)。ただし Execution tools は残して、保留中の変更を把握しやすくするのはあり。
  • ④ モデルの選択
  • Haiku——速く軽いタスク向け
  • Sonnet——速度と深さの中間、バランス型
  • Opus——複雑な分析向け
  • Inherit——メイン会話が使っているモデルをそのまま使う
  • ⑤ 色(color)の選択:UI 上でどのサブエージェントがアクティブか一目で分かるようにする。複数サブエージェントを走らせる時に役立つ。
  • 設定ファイルの保存先:作成完了後、.claude/agents/your-agent-name.md に保存される(プロジェクト内が典型)。
  • frontmatter の各フィールド
  • name——サブエージェントの一意の識別子。@agent code-quality-reviewer のように参照する。
  • description——Claude がいつこのサブエージェントを使うか判断する材料。1行でなければならない(改行が必要なら \n などエスケープ改行を使う)。委任が適切な場面の例示会話を含めてもよい。
  • tools——アクセス可能なツールのリスト。生成時に選んだものが入るが、後からこのファイルで編集できる。
  • model——sonnet / opus / haiku / inherit を指定。
  • color——UI 識別用の色。
  • システムプロンプト=本文:YAML frontmatter より下のすべてがシステムプロンプト。何に注目し、どう分析し、どう結果をメインエージェントに報告するかを書く。よく書けたシステムプロンプトが、使えるサブエージェントと的外れなサブエージェントの分かれ目
  • 自動委任させるコツ:Claude に明示的に頼まなくても委任させたいなら、description"proactively" という語を含める(例:description: Proactively suggest running this agent after major code changes...)。加えて例示会話を入れると、Claude が委任すべき具体シナリオを理解しやすくなる。
  • テスト方法:作成後、実際にコードを変更して Claude にレビューを頼む。期待通りに使われない場合は description を見直し、より具体的な例やトリガーシナリオを追加する。

日本語(本文の自然な全訳)

Claude Code には組み込みのサブエージェントが付属していますが、自分で作ることもできます。カスタムサブエージェントは特定のタスク——コードのレビュー、テストの作成、ドキュメントのチェックなど——を専門とします。それらは YAML frontmatter を持つ markdown ファイルとして定義され、この frontmatter が Claude に「いつそのサブエージェントを使うか」「そのサブエージェントがどう振る舞うべきか」を伝えます。

サブエージェントを作る

サブエージェントを作る最も簡単な方法は /agents スラッシュコマンドです。これはサブエージェントを管理するためのメインインターフェースを開きます。そこから Create new agent(新規エージェント作成)を選びます。

まず、サブエージェントのスコープを選ぶよう求められます:

  • Project-level(プロジェクトレベル)——現在のプロジェクトでのみ利用可能
  • User-level(ユーザーレベル)——あなたのマシン上のすべてのプロジェクトで共有される

次に、どうやって作るかを選べます。設定を手動で書くこともできますが、推奨されるアプローチは Claude に生成させることです。作りたいものを説明するだけで、Claude はあなたの入力に基づいて namedescription、システムプロンプトを生成します。

ツールのカスタマイズ

作成中に、サブエージェントがアクセスできるツールをカスタマイズする機会が与えられます。ツールのカテゴリには次のものがあります:

  • Read-only tools(読み取り専用ツール)
  • Edit tools(編集ツール)
  • Execution tools(実行ツール)
  • MCP tools(MCP ツール)
  • Other tools(その他のツール)

サブエージェントが実際に必要とするものを考えてください。コードレビュアーはおそらく編集ツールを必要としません——コードを読んで分析すべきであって、変更すべきではないからです。ただし、保留中の変更をより簡単に特定できるように、実行ツールは有効にしておきたいかもしれません。

モデルと色を選ぶ

ツールを設定した後、サブエージェントを動かす Claude モデルを選びます。モデルピッカーは4つの選択肢を提供します:

  • Haiku——速く軽量なタスクに最適
  • Sonnet——速度と深さの良いバランス
  • Opus——複雑な分析に最適
  • Inherit——メイン会話が動いているモデルをそのまま使う

最後に、色を選びます。これは UI に表示され、どのサブエージェントがアクティブかを素早く見分けられるようにします。ささやかな要素ですが、複数のサブエージェントを走らせている時に役立ちます。

設定ファイル

作成が完了すると、サブエージェントの設定ファイルがあなたのプロジェクトに保存されます(典型的には .claude/agents/your-agent-name.md)。典型的なサブエージェント設定は次のようになります:

---
name: code-quality-reviewer
description: Use this agent when you need to review recently written or modified code for quality, security, and best practice compliance.
tools: Bash, Glob, Grep, Read, WebFetch, WebSearch
model: sonnet
color: purple
---

You are an expert code reviewer specializing in quality assurance, security best practices, and
adherence to project standards. Your role is to thoroughly examine recently written or modified code
and identify issues that could impact reliability, security, maintainability, or performance.

各フィールドを分解してみましょう:

  • name——サブエージェントの一意の識別子。これを使って参照します。Claude に直接頼むか、メッセージ内で @agent code-quality-reviewer とタイプします。
  • description——Claude がいつこのサブエージェントを使うか決める材料をコントロールします。これは1行でなければなりません(改行が必要な場合はエスケープした改行文字 \n を使います)。委任が適切な場面を Claude が理解しやすくなるよう、例示会話をここに含めることができます。
  • tools——サブエージェントがアクセスできるツールをリストします。これは生成中に選んだものと一致しますが、ここでいつでもリストを編集できます。
  • model——どの Claude モデルを使うかを指定します:sonnetopushaiku、または inherit
  • color——サブエージェントを識別するための UI 上の色。

システムプロンプト

markdown ファイルの本文(YAML frontmatter より下のすべて)がシステムプロンプトです。ここでサブエージェントに指示を与えます:何に集中すべきか、どのように物事を分析すべきか、どのように発見をメインエージェントに報告すべきか。

よく書けたシステムプロンプトは、役に立つサブエージェントと的外れなサブエージェントの分かれ目になります。サブエージェントが何を探すべきか、そしてどのように出力を構造化すべきかについて、具体的であってください。

Claude に自動でサブエージェントを使わせる

あなたが明示的に頼まなくても Claude にタスクを委任させたいなら、description フィールドに "proactively" という語を含めます。たとえば:

description: Proactively suggest running this agent after major code changes...

また、description に例示会話を追加することで、サブエージェントを使うべき具体的なシナリオを Claude が理解しやすくなります。例が具体的であるほど、いつ委任すべきかを Claude はうまく判断できるようになります。

サブエージェントをテストする

サブエージェントを作成したら、いくつかコードを変更して Claude にレビューを頼み、テストしてください。

期待した時にサブエージェントが使われない場合は、description に戻って確認しましょう。より具体的な例とトリガーシナリオを追加することで、いつあなたのサブエージェントに作業を委任すべきかを Claude が理解しやすくなります。

英語逐語(動画字幕 or 本文原文)

動画字幕(YouTube: arD6qEWa2Xc・重複除去済み)

In the previous video, we covered what sub agents are and how they work. Claude Code includes built-in sub agents, but you can also create your own sub agents that specialize in certain tasks. Custom sub agents are markdown files with YAML front matter. These markdown files contain configuration that helps Claude understand when to use a sub agent and provides directions to the sub agent itself.

Now, the easiest way to create a sub agent is with the /agents command. This panel is the main interface for managing your sub agents. Once here, select create new agent.

You'll then be asked if you want to create a sub agent for the current project or a sub agent that will be shared between all of the projects on your machine. Next, you can create a sub agent manually, but we recommend using Claude Code to automatically generate it for you.

Our first sub agent will be a code reviewer. I'll ask Claude to make a sub agent that reviews code quality and security issues. Claude will use your input to generate a name, description, and system prompt for the sub agent. We'll see those in a moment, but before we do, we get the opportunity to customize the tools that this sub agent has access to. Now, given that our sub agent is only responsible for reviewing code, you might decide to disallow tools for editing, but I'll leave in execution to allow the sub agent to more easily identify pending changes.

Next, you'll be prompted to select the model that powers the sub agent. And finally, a color. This color is used in the UI to help you better identify the sub agent, and it also just adds a little bit of personal flair. Now, at the summary window, we see that the sub agent config file will be saved into my current project at this path. Now, let's open up that file to get a better idea of what's going on.

The name field is a unique identifier. This is how you reference the sub agent either by asking Claude directly or using @agent code-reviewer in your message.

The description controls when Claude decides to use the sub agent. The description must be on a single line. Notice that there are escaped new line characters in there. If you want Claude to use the sub agent automatically more often, add in the word proactively to the description. You can also add example conversations to help Claude understand when it should be using the sub agent.

The tools field lists which tools the sub agent can access. The list of tools will match the tools we granted access to during the agent generation, but you can further edit the list of tools in this file if you want.

The model field specifies which Claude model to use. Sonnet, Opus, Haiku, or inherit. Use Haiku for fast tasks, Opus for complex analysis, and Sonnet if you need something between the two. Inherit will use the same model as your main conversation.

The body of the file contains the system prompt that is given to the sub agent. The system prompt will provide guidance to the sub agent helping it understand how to complete its tasks and how it should return information back to the main agent.

Now, for the fun part. After creating your sub agent, test it by making some code changes and asking Claude to review them. If the sub agent isn't being used when you expect, check your description. Adding more specific examples helps Claude understand when to delegate.

本文原文(テキストレッスン)

Creating a subagent

Claude Code comes with built-in subagents, but you can also create your own. Custom subagents specialize in specific tasks -- like reviewing code, writing tests, or checking documentation. They are defined as markdown files with YAML frontmatter that tell Claude when to use the subagent and how the subagent should behave.

Creating a Subagent

The easiest way to create a subagent is with the /agents slash command. This opens the main interface for managing your subagents. From there, select Create new agent.

You will first be asked to choose the scope of your subagent:

Project-level -- available only in the current project
User-level -- shared across all projects on your machine

Next, you can choose how to create it. You can write the configuration manually, but the recommended approach is to let Claude generate it for you. Just describe what you want the subagent to do, and Claude will produce a name, description, and system prompt based on your input.

Customizing Tools

During creation, you get the chance to customize which tools the subagent can access. The tool categories include:

Read-only tools
Edit tools
Execution tools
MCP tools
Other tools

Think about what your subagent actually needs. A code reviewer probably does not need edit tools -- it should read and analyze code, not change it. However, you might want to keep execution tools enabled so it can more easily identify pending changes.

Choosing a Model and Color

After configuring tools, you select which Claude model powers the subagent. The model picker offers four options:

Haiku -- best for fast, lightweight tasks
Sonnet -- a good middle ground between speed and depth
Opus -- best for complex analysis
Inherit -- uses whatever model your main conversation is running

Finally, you pick a color. This shows up in the UI so you can quickly tell which subagent is active. It is a small touch, but it helps when you have multiple subagents running.

The Config File

Once creation is complete, the subagent config file is saved into your project (typically at .claude/agents/your-agent-name.md). Here is what a typical subagent config looks like:

---
name: code-quality-reviewer
description: Use this agent when you need to review recently written or modified code for quality, security, and best practice compliance.
tools: Bash, Glob, Grep, Read, WebFetch, WebSearch
model: sonnet
color: purple
---

You are an expert code reviewer specializing in quality assurance, security best practices, and
adherence to project standards. Your role is to thoroughly examine recently written or modified code
and identify issues that could impact reliability, security, maintainability, or performance.

Let's break down each field:

name -- A unique identifier for the subagent. This is how you reference it, either by asking Claude directly or by typing @agent code-quality-reviewer in your message.
description -- Controls when Claude decides to use the subagent. This must be a single line (use escaped newline characters \n if you need breaks). You can include example conversations here to help Claude understand when delegation is appropriate.
tools -- Lists which tools the subagent can access. This matches whatever you selected during generation, but you can edit the list here at any time.
model -- Specifies which Claude model to use: sonnet, opus, haiku, or inherit.
color -- The UI color for identifying the subagent.

System Prompts

The body of the markdown file (everything below the YAML frontmatter) is the system prompt. This is where you give the subagent its instructions: what it should focus on, how it should analyze things, and how it should report findings back to the main agent.

A well-written system prompt is the difference between a useful subagent and one that misses the point. Be specific about what the subagent should look for and how it should structure its output.

Making Claude Use Your Subagent Automatically

If you want Claude to delegate tasks to the subagent without you explicitly asking, include the word "proactively" in the description field. For example:
description: Proactively suggest running this agent after major code changes...

You can also add example conversations to the description to help Claude understand specific scenarios where the subagent should be used. The more concrete your examples, the better Claude gets at knowing when to delegate.

Testing Your Subagent

After creating your subagent, test it by making some code changes and asking Claude to review them.

If the subagent is not being used when you expect it to be, go back and check the description. Adding more specific examples and trigger scenarios helps Claude understand when to delegate work to your subagent.
↑ 目次へ戻る

Introduction to subagents | Lesson 03「効果的なサブエージェントの設計(Designing effective subagents)」

出典: Anthropic Academy / YouTube動画ID WPxWKT_OaU4 / 2026-07-04

日本語ナレッジ(要点整理)

  • 効果的なサブエージェントの4要素:①よい description を書く ②出力フォーマットを定義する ③障害(obstacles)を報告させる ④ツールアクセスを制限する。設定が悪いサブエージェントは、あてもなく彷徨い、走りすぎ、メインエージェントが使えない出力を出す。
  • 設定データがどう使われるか(超重要):メインコンテキストのエージェントにメッセージを送ると、利用可能な全サブエージェントの namedescription がシステムプロンプトに含まれる。メインエージェントはこれを見て、どのサブエージェントをいつ起動するか判断する。自動起動のコントロールを改善したければ、namedescription を調整する。
  • description の第2の役割:メインエージェントがサブエージェントを起動する際、タスク開始用の入力プロンプトを書くが、その際 description をガイドにする。つまり description は「いつ走るか」だけでなく「サブエージェントに何を指示するか」も形づくる。
  • 入力プロンプトを形づくる description の書き方(例:コードレビュー)
  • 汎用的な description → メインエージェントは「use get diff to find the current changes」のような曖昧な入力プロンプトを書く。どのファイルが重要かをサブエージェント自身が推測する羽目になる。
  • description に「You must tell the agent precisely which files you want it to review.」を加える → メインエージェントは実際のファイル名を列挙した、はるかに具体的な入力プロンプトを書くようになる。
  • 同じ手法は他タイプにも効く。例:Web検索サブエージェントの description に「return sources that can be cited」を加えると、委任時にその指示が含まれる。
  • 最重要の改善=出力フォーマットの定義:システムプロンプトに出力フォーマットを定義するのが単一で最も重要な改善。効果は2つ: 1. 自然な停止点を作る——各セクションを埋め終われば「完了」と分かる。 2. 走りすぎを防ぐ——出力の定義がないと、サブエージェントは「どこまで調べれば十分か」を決めきれず、必要以上に長く走りがち。
  • コードレビューの構造化出力フォーマット例: 1. Summary:何をレビューし、全体評価はどうか 2. Critical Issues:即修正必須のセキュリティ脆弱性・データ整合性リスク・ロジックエラー 3. Major Issues:品質問題・アーキテクチャ不整合・重大なパフォーマンス懸念 4. Minor Issues:スタイルの不統一・ドキュメント欠落・軽微な最適化 5. Recommendations:改善提案・リファクタリング機会・適用すべきベストプラクティス 6. Approval Status:マージ/デプロイ可能か、変更要かの明確な表明
  • 障害(Obstacles)の報告:サブエージェントが作業中に見つけた回避策(依存関係の解決、特定フラグが必要なコマンド等)は、返す要約に含めないと、メインスレッドが同じ解決策を再発見する羽目になり、時間とトークンを浪費する。浮かび上がらせたい情報:セットアップ問題・環境のクセ/作業中に見つけた回避策/特別なフラグや設定が必要だったコマンド/問題を起こした依存関係やインポート。出力フォーマットに "Obstacles Encountered" セクションを明示的に追加すると確実に拾える。
  • ツールアクセスの制限:サブエージェントが実際に必要とするツールだけを与える。効果は2つ:意図しない副作用を防ぐ/複数運用時に各サブエージェントの役割が明確になる。
  • Research / read-only——Glob, Grep, Read だけでよい。ファイルを誤って変更できない。
  • Code reviewer——git diff を走らせるため Bash は必要だが、Edit / Write は不要。
  • Styling / code modification——ここで初めて Edit / Write を与える(仕事が実際にコードを変えることだから)。
  • まとめ(4特性):Specific descriptions(起動タイミングと受け取る指示の両方を操縦)/Structured output(完了判定と使える情報の担保)/Obstacle reporting(再発見の防止)/Limited tool access(研究は read-only、レビュアーは bash、コード変更するものだけ edit/write)。それぞれは単純だが、合わさると「なんとなく手伝おうとする存在」が「時間内に終わり、明確に報告する、焦点の定まった予測可能なワーカー」に変わる。

日本語(本文の自然な全訳)

サブエージェントの作り方が分かったところで、次はそれらを実際に効果的にするパターンを見ていきましょう。設定がまずいサブエージェントは、あてもなく彷徨い、長く走りすぎ、メインエージェントが使えない出力を生み出します。その解決策は4つに集約されます:よい description を書くこと、出力フォーマットを定義すること、障害を報告させること、そしてツールアクセスを制限することです。

サブエージェントの設定データがどう使われるか

メインのコンテキストウィンドウエージェントにメッセージを送ると、利用可能なすべてのサブエージェントの namedescription がシステムプロンプトに含まれます。これがメインエージェントが「どのサブエージェントを、いつ起動するか」を判断する仕組みです。サブエージェントがいつ自動的に起動されるかをもっとうまくコントロールしたいなら、調整すべきは namedescription です。

description にはもう1つの役割があります。メインエージェントがサブエージェントを起動する時、タスクを始動させるための入力プロンプトを書きます。その入力プロンプトを書く際のガイドとして description を使います。つまり description は、サブエージェントがいつ走るかをコントロールするだけでなく——サブエージェントが何をするよう指示されるかも形づくるのです。

入力プロンプトを形づくる description を書く

コードレビューのサブエージェントを考えてみましょう。汎用的な description だと、メインエージェントは「use get diff to find the current changes(get diff を使って現在の変更を見つけて)」のような入力プロンプトを書くかもしれません。これは曖昧です。どのファイルが重要かをサブエージェント自身が判断しなければなりません。

description を「You must tell the agent precisely which files you want it to review.(レビューしてほしいファイルを正確にエージェントに伝えなければならない)」のような内容に更新すると、メインエージェントは今度は実際にレビューすべきファイルを列挙した、はるかに具体的な入力プロンプトを書くようになります。

この同じ手法は、異なるタイプのサブエージェントでも通用します。たとえば、Web検索サブエージェントの description に「return sources that can be cited(引用可能な出典を返す)」を加えると、メインエージェントはタスクを委任する時にその指示を含めるようになります。

出力フォーマットを定義する

サブエージェントに対してできる最も重要な改善は、そのシステムプロンプトに出力フォーマットを定義することです。これは2つの働きをします:

  • 自然な停止点を作る——サブエージェントは、フォーマットの各セクションを埋め終わった時に「完了した」と分かる。
  • サブエージェントが長く走りすぎるのを防ぐ——定義された出力がないと、サブエージェントは「どれだけ調査すれば十分か」を決めきれず、必要以上にずっと長く走る傾向がある。

以下は、コードレビューサブエージェント向けの構造化された出力フォーマットの例です:

Provide your review in a structured format:

1. Summary: Brief overview of what you reviewed and overall assessment
2. Critical Issues: Any security vulnerabilities, data integrity risks,
   or logic errors that must be fixed immediately
3. Major Issues: Quality problems, architecture misalignment, or
   significant performance concerns
4. Minor Issues: Style inconsistencies, documentation gaps, or
   minor optimizations
5. Recommendations: Suggestions for improvement, refactoring
   opportunities, or best practices to apply
6. Approval Status: Clear statement of whether the code is ready
   to merge/deploy or requires changes

このフォーマットは、サブエージェントに取り組むべき明確なチェックリストを与えます。すべてのセクションが埋まったら、サブエージェントは止まってよいと分かります。

障害を報告する

サブエージェントが作業中に回避策を発見した時——依存関係の問題を解決したり、あるコマンドに特定のフラグが必要だと分かったり——それらの詳細は、返す要約の中に現れる必要があります。もしそうしなければ、メインスレッドは同じ解決策を自分で再発見しなければならず、時間とトークンを浪費します。

浮かび上がらせたいのは、次のような種類のものです:

  • セットアップの問題や環境のクセ
  • タスク中に発見した回避策
  • 特別なフラグや設定が必要だったコマンド
  • 問題を引き起こした依存関係やインポート

この情報を得る方法は、出力フォーマットの中でそれを明示的に要求することです。出力テンプレートに「Obstacles Encountered(遭遇した障害)」セクションを追加すると、この情報が確実に表面化します。

7. Obstacles Encountered: Report any obstacles encountered during the
   review process. This can be: setup issues, workarounds discovered or
   environment quirks. Report commands that needed a special flag or
   configuration. Report dependencies or imports that caused problems.

ツールアクセスを制限する

すべてのサブエージェントがすべてのツールへのアクセスを必要とするわけではありません。サブエージェントが実際に何をする必要があるかを考え、その仕事に必要なツールだけを与えましょう。これは2つの働きをします:意図しない副作用を防ぎ、複数のサブエージェントがある時に各々の役割をより明確にします。

一般的なサブエージェントのタイプごとに、ツールアクセスをどう考えるかは次の通りです:

  • Research / read-only サブエージェント——GlobGrepRead だけが必要。ファイルを誤って変更することはできない。
  • Code reviewer——git diff を走らせて何が変わったかを見るために Bash アクセスが必要だが、それでも EditWrite は不要。
  • Styling / code modification エージェント——ここで EditWrite のアクセスを与える。サブエージェントの仕事が実際にコードを変更することだから。

すべてを組み合わせる

効果的なサブエージェントは4つの特性を共有します:

  • Specific descriptions(具体的な description)——description は、サブエージェントがいつ起動されるか、そしてどんな指示を受け取るかをコントロールする。両方を操縦するように書く。
  • Structured output(構造化された出力)——システムプロンプトに出力フォーマットを定義し、サブエージェントが「いつ完了したか」を分かり、メインスレッドが使える情報を返すようにする。
  • Obstacle reporting(障害の報告)——回避策・クセ・問題のためのセクションを出力フォーマットに含め、メインスレッドが再発見せずに済むようにする。
  • Limited tool access(限定されたツールアクセス)——サブエージェントに実際に必要なツールだけを与える。研究には read-only、レビュアーには bash、コードを変更すべきエージェントにだけ edit/write。

これらのパターンはそれぞれ単純ですが、合わさることで、サブエージェントを「漠然と役立とうとする何か」から「時間通りに終わり、明確に報告する、焦点の定まった予測可能なワーカー」へと変えます。

英語逐語(動画字幕 or 本文原文)

動画字幕(YouTube: WPxWKT_OaU4・重複除去済み)

Now that you know how to create sub agents, let's look at patterns that lead to effective sub agents. First, let's get a better idea of how some of the data in the sub agent config file is used.

Whenever you send a message to the main context window agent, the name and description of each sub agent is included in the system prompt. So, if you want to better control when the main agent launches a sub agent automatically, you should modify the name description.

Next, remember that when a sub agent is launched, the main agent writes an input prompt. When writing this input prompt, it uses the description as guidance. So, if you want to better control when the main agent launches a sub agent automatically, you should modify the name and description.

Let's consider our review sub agent again. Right now, when the main agent runs the sub agent, the sub agent is given an input prompt telling it to use get diff to find the current changes. If we wanted the main agent to more reliably tell the sub agent exactly which files to review, we would update the description. "You must tell the agent precisely which files you want it to review." Now, if we ask Claude to run the code reviewer agent, we'll see a different input.

You can also influence what the main thread tells a sub agent through the description. So, adding "return sources that can be cited" to a web search sub agent's description causes the main thread to include that instruction when delegating the task.

The most important improvement that you can make is defining an output format in the system prompt. This creates natural stopping points for the sub agent. Without a defined output format, sub agents struggle to decide when enough research has been done and they tend to run much much longer than sub agents that are given an output format.

When a sub agent discovers a workaround to some issue like solving a dependency issue or finding that a certain command needs particular flags, these details should appear in the summary. Otherwise, the main thread has to rediscover the same solutions. Obstacles encountered, any setup issues, workarounds discovered, or environment quirks, commands that needed special flags or configuration, dependencies or imports that cause problems. Explicitly asking for obstacle reporting in the output format surfaces this information.

A read-only sub agent using just glob, grep, read cannot accidentally modify files. This constraint clarifies the sub agent's role and prevents unintended side effects. So, think about what sub agents actually needs to do. If it's just researching, it only needs to read files, so keep it read-only. That way it can't accidentally modify anything while exploring. A reviewer needs to run get diff to see what changed, so give it bash access, but it still doesn't need to edit files. Only give edit and write to sub agents that should actually change your code like a styling agent applying CSS updates. This also helps clarify what each sub agent is for when you have several of them.

So, effective sub agents use structured output, report obstacles, have specific descriptions, and limit tool access.

本文原文(テキストレッスン)

Designing effective subagents

Now that you know how to create subagents, let's look at the patterns that make them actually effective. A subagent that's poorly configured will wander, run too long, or produce output the main agent can't use. The fixes come down to four things: writing good descriptions, defining an output format, reporting obstacles, and limiting tool access.

How Subagent Config Data Gets Used

When you send a message to the main context window agent, the name and description of every available subagent are included in the system prompt. This is how the main agent decides which subagent to launch and when. If you want better control over when a subagent gets triggered automatically, the name and description are what you should tweak.

The description also plays a second role. When the main agent launches a subagent, it writes an input prompt to kick off the task. It uses the description as guidance for writing that prompt. So the description doesn't just control when a subagent runs -- it shapes what the subagent is told to do.

Writing Descriptions That Shape Input Prompts

Consider a code review subagent. With a generic description, the main agent might write an input prompt like "use get diff to find the current changes." That's vague. The subagent has to figure out which files matter on its own.

If you update the description to include something like "You must tell the agent precisely which files you want it to review," the main agent will now write a much more specific input prompt that lists the actual files to review.

This same technique works across different types of subagents. For example, adding "return sources that can be cited" to a web search subagent's description causes the main agent to include that instruction when delegating the task.

Defining an Output Format

The single most important improvement you can make to a subagent is defining an output format in its system prompt. This does two things:

It creates natural stopping points -- the subagent knows it's done when it has filled in each section of the format.
It prevents the subagent from running too long. Without a defined output, subagents struggle to decide when enough research has been done and tend to run much longer than necessary.

Here's an example of a structured output format for a code review subagent:
Provide your review in a structured format:

1. Summary: Brief overview of what you reviewed and overall assessment
2. Critical Issues: Any security vulnerabilities, data integrity risks,
   or logic errors that must be fixed immediately
3. Major Issues: Quality problems, architecture misalignment, or
   significant performance concerns
4. Minor Issues: Style inconsistencies, documentation gaps, or
   minor optimizations
5. Recommendations: Suggestions for improvement, refactoring
   opportunities, or best practices to apply
6. Approval Status: Clear statement of whether the code is ready
   to merge/deploy or requires changes

This format gives the subagent a clear checklist to work through. Once every section is filled in, the subagent knows it can stop.

Reporting Obstacles

When a subagent discovers a workaround during its work -- like solving a dependency issue or finding that a certain command needs particular flags -- those details need to appear in the summary it returns. If they don't, the main thread has to rediscover the same solutions on its own, which wastes time and tokens.

The kinds of things you want surfaced include:

Setup issues or environment quirks
Workarounds discovered during the task
Commands that needed special flags or configuration
Dependencies or imports that caused problems

The way to get this information is to explicitly ask for it in the output format. Adding an "Obstacles Encountered" section to your output template surfaces this information reliably.
7. Obstacles Encountered: Report any obstacles encountered during the
   review process. This can be: setup issues, workarounds discovered or
   environment quirks. Report commands that needed a special flag or
   configuration. Report dependencies or imports that caused problems.

Limiting Tool Access

Not every subagent needs access to every tool. Think about what a subagent actually needs to do, and only give it the tools required for that job. This does two things: it prevents unintended side effects, and it makes each subagent's role clearer when you have several of them.

Here's how to think about tool access for common subagent types:

Research / read-only subagent -- Only needs Glob, Grep, and Read. Cannot accidentally modify files.
Code reviewer -- Needs Bash access to run git diff and see what changed, but still doesn't need Edit or Write.
Styling / code modification agent -- This is where you give Edit and Write access, because the subagent's job is to actually change your code.

Putting It All Together

Effective subagents share four characteristics:

Specific descriptions -- The description controls when the subagent is launched and what instructions it receives. Write it to steer both.
Structured output -- Define an output format in the system prompt so the subagent knows when it's done and returns information the main thread can use.
Obstacle reporting -- Include a section in the output format for workarounds, quirks, and problems so the main thread doesn't have to rediscover them.
Limited tool access -- Only give a subagent the tools it actually needs. Read-only for research, bash for reviewers, edit/write only for agents that should change code.

Each of these patterns is simple on its own, but together they turn a subagent from something that vaguely tries to help into a focused, predictable worker that finishes on time and reports back clearly.
↑ 目次へ戻る

Introduction to subagents | Lesson 04「サブエージェントを効果的に使う(Using subagents effectively)」

出典: Anthropic Academy / YouTube動画ID n5LoKZ8Oa-A / 2026-07-04

日本語ナレッジ(要点整理)

  • 判断の核=「途中作業がメインスレッドにとって重要か?」:重要でない(最終結果だけ欲しい)なら委任する。重要(途中を見て反応する必要がある)ならメインスレッドに留める。これがサブエージェントを使うかどうかの唯一の決定ルール。
  • サブエージェントが輝く条件:探索(exploration)が実行(execution)から分離できる時。各ステップが前ステップの発見に依存する場合は、その作業はメインスレッドに置くべき(ハンドオフで情報が失われる)。
  • サブエージェントが得意なタスク
  • 結果が欲しいだけで、それがどう見つかったかの実況は不要
  • 探索作業がメインスレッドのコンテキストを散らかす
  • 新鮮な視点やカスタムシステムプロンプトから恩恵を受けるタスク
  • ① リサーチ(定番ユースケース):例:不慣れなコードベースで認証の仕組みを調べる。メインスレッドは「JWT がどこで検証されるか」を知る必要はあるが、辿った全ファイルを見る必要はない。リサーチサブエージェントが何十ファイルも読み、関数呼び出しを辿り、複数のコードパスを探索し、探索は全部サブエージェント側に留まる。メインには「JWT validation happens in middleware/auth.js line 42, called from the Express router in route/api.js」のようなクリーンな要約が返る。
  • ② コードレビューClaude は、コードが「他人が書いたもの」として提示された方がレビューが上手い。メインスレッドで何ターンもかけて機能を作った後、同じスレッドにレビューを頼むと弱いフィードバックになりがち(自分が作ったものを新鮮な目で見づらい)。レビュアーサブエージェントは別コンテキストで変更を見て、git diff を走らせ、変更ファイルを読み、「どう書かれたか」の履歴なしに専門のレビュー基準を適用する。加えて、プロジェクト固有のレビュー基準をシステムプロンプトに埋め込め、チーム全体で一貫した基準を保てる。
  • ③ カスタムシステムプロンプト:Claude Code のデフォルトシステムプロンプトは簡潔でコード中心の応答を重視する。コーディングには最適だが、すべてには向かない。
  • Copywriting サブエージェント——トーン・オーディエンス・スタイルの指示を与える。デフォルトの簡潔な技術文章は、ランディングページやメールキャンペーンには向かない。声とストラクチャについて全く別の指示を持たせられる。
  • Styling サブエージェント——デザインシステムのファイルを指し示しておく。サブエージェント起動時にそれらが自動でコンテキストにロードされ、CSS を書き始める前にカラー変数・スペーシング規約・コンポーネントパターンを把握できる。
  • サブエージェントが害になる3つのアンチパターン(起動のオーバーヘッド=可視性喪失+要約への圧縮が正当化されるのは、メインスレッドにできないことをする時だけ):
  • Expert Claims(専門家を名乗らせる):「You are a Python expert」「You are a Kubernetes specialist」は無価値。Claude は既にその知識を持っており、専門家サブエージェントがメインスレッドにできないことは何もない。
  • Sequential Pipelines(逐次パイプライン):例「バグ再現→デバッグ→修正」の3エージェント連結。タスクが真に独立している時は機能するが、各ステップが前ステップの発見に依存する時は失敗する。バグ修正はほぼ常に依存するので、ハンドオフで情報が失われる。
  • Test Runners(テスト実行):テストが失敗した時は診断のため全出力が欲しいのに、「tests failed」しか返さないサブエージェントは、詳細を得るための追加デバッグスクリプトを作る羽目にさせる。テストの結果、テストランナーパターンは全構成の中で最も成績が悪かった。
  • 使うべき用途:リサーチと探索/コードレビュー/カスタムシステムプロンプトを要するタスク。
  • 避けるべき用途:実質的な能力を足さない「専門家」ペルソナ/各ステップが前に依存する多段パイプライン/デバッグに全出力が必要なテスト実行。

日本語(本文の自然な全訳)

サブエージェントの作り方も、うまく設計する方法も分かりました。次の問いはこうです:それらは実際にいつ役立ち、いつ邪魔になるのか? 違いは1つに集約されます——途中作業があなたのメインスレッドにとって重要かどうか、です。

サブエージェントが輝く時

サブエージェントは、探索が実行から分離されている時に最も力を発揮します。タスクの各ステップが前のステップで発見したことに依存するなら、その作業はメインスレッドに置きたいところです。しかし、答えさえ得られればよく、道のりはどうでもよいなら、委任しましょう。

サブエージェントは次のようなタスクで真価を発揮します:

  • どう見つかったかの一部始終ではなく、結果が必要
  • 探索作業がメインスレッドのコンテキストを散らかしてしまう
  • 新鮮な視点、あるいはカスタムシステムプロンプトから恩恵を受けるタスク

リサーチタスク

リサーチは、サブエージェントの典型的なユースケースです。不慣れなコードベースで認証がどう動くかを調べる場合を考えてみましょう。あなたのメインスレッドは JWT がどこで検証されるかを知る必要はありますが、その過程で検索されたすべてのファイルを見る必要はありません。

リサーチサブエージェントは、何十ものファイルを読み、関数呼び出しを辿り、さまざまなコードパスを探索できます。その探索はすべてサブエージェントのコンテキストに留まります。あなたのメインスレッドは、次のようなクリーンな要約を受け取ります:

JWT validation happens in middleware/auth.js line 42,
called from the Express router in route/api.js

サブエージェントが重い作業をやってくれました。あなたのメインスレッドは、前に進むために必要なものだけを、ちょうど得るのです。

コードレビュー

Claude は、コードが誰か他の人によって書かれたものとして提示された時、より効果的にレビューします。もしあなたがメインスレッドで何ターンもかけて機能を作り上げた後、その同じスレッドにレビューを頼むと、しばしば弱いフィードバックになります。Claude はその作成に関与していたので、新鮮な目でそれを見るのが難しいのです。

レビュアーサブエージェントは、別個のコンテキストで変更を見ます。git diff を走らせ、変更されたファイルを読み、そのコードがどのように書かれたかの履歴なしに、専門のレビュー基準を適用します。この分離はまた、プロジェクト固有のレビュー基準をサブエージェントのシステムプロンプトに埋め込むことを可能にし、チーム全体で一貫したレビュー基準を保証します。

カスタムシステムプロンプト

Claude Code のデフォルトのシステムプロンプトは、簡潔でコード中心の応答を重視します。それはコーディングには非常にうまく機能しますが、すべてに対してではありません。

カスタムシステムプロンプトがサブエージェントをメインスレッドより本当に優れたものにする2つのケースを挙げます:

  • Copywriting サブエージェント——トーン、オーディエンス、スタイルについての指示を与えます。Claude Code のデフォルトプロンプトは簡潔な技術文章に傾きがちで、それはランディングページやメールキャンペーンに本当に欲しいものではありません。コピーライティングサブエージェントは、声とストラクチャについてまったく異なる指示を持てます。
  • Styling サブエージェント——あなたのデザインシステムのファイルを指し示します。サブエージェントが走る時、それらのファイルは自動的にそのコンテキストにロードされるので、CSS を書き始める前から、あなたのカラー変数、スペーシング規約、コンポーネントパターンを把握しています。

サブエージェントが害になる時

サブエージェントを起動するオーバーヘッド——その作業の可視性を失い、その発見を要約に圧縮すること——が意味を持つのは、サブエージェントがメインスレッドにはできない何かをする時だけです。気をつけるべき一般的なアンチパターンが3つあります。

専門家の主張(Expert Claims)

専門性を主張するサブエージェントはめったに役立ちません。「you are a Python expert」や「you are a Kubernetes specialist」のようなプロンプトは価値を足しません。なぜなら Claude はすでにその知識を持っているからです。いわゆる専門家サブエージェントにできて、あなたのメインスレッドが直接できないことは何もありません。

逐次パイプライン(Sequential Pipelines)

逐次的なサブエージェントのパイプラインは問題を生みます。3エージェントのフローを考えてみましょう:1つはバグを再現し、1つはそれをデバッグし、1つはそれを修正する。パイプラインは、タスクが本当に独立している時には機能します。各ステップが前のステップの発見に依存する時には失敗します——そしてバグ修正はほぼ常にそうです。エージェント間のハンドオフで情報が失われるのです。

テストランナー(Test Runners)

テストランナーサブエージェントは、あなたが必要とする情報を隠してしまいがちです。テストが失敗した時、あなたは問題を診断するために完全な出力が欲しいはずです。「tests failed(テスト失敗)」だけを返すサブエージェントは、直接の出力なら見えていたはずの詳細を得るために、追加のデバッグスクリプトを作らせる羽目にします。テストの結果、テストランナーパターンは全構成の中で最も成績が悪いことが示されました。

決定ルール

サブエージェントを使うべきか判断する時、自分にこう問いかけてください:途中作業は重要か?

答えが「いいえ」——最終結果だけが必要——なら、サブエージェントに委任しましょう。答えが「はい」——道中で何が起きているかを見て反応する必要がある——なら、メインスレッドに留めましょう。

サブエージェントを使うべき用途:

  • リサーチと探索
  • コードレビュー
  • カスタムシステムプロンプトを必要とするタスク

サブエージェントを避けるべき用途:

  • 実質的な能力を足さない「専門家」ペルソナ
  • 各ステップが前のステップに依存する多段パイプライン
  • デバッグのために完全な出力が必要なテスト実行

英語逐語(動画字幕 or 本文原文)

動画字幕(YouTube: n5LoKZ8Oa-A・重複除去済み)

You know how to create sub agents and design them well. Now, let's cover when they actually help and when they get in the way. Simply put, the difference comes down to whether the intermediate work matters to your main thread.

When exploration is separate from execution, sub agents shine. When each step depends on what the previous step discovered, well, information gets lost in the handoff process. Sub agents excel at research tasks where you just need an answer, not the journey.

Consider investigating how authentication works in an unfamiliar code base. Well, the main thread might need to know where is the JWT validated, but doesn't need to see every file that was searched. A research sub agent can read dozens of files, trace through function calls, and explore different code paths. All that exploration stays in the sub agent's context. Your main thread receives "JWT validation happens in middleware/auth.js at line 42, called from the Express router and route/api.js," or something like that.

Claude reviews work more effectively when the code is presented as being authored by someone else. If you build a feature over many turns with your main thread, asking the main thread to then review it often doesn't give the best feedback. Claude was involved in creating it, so it has trouble seeing it with fresh eyes. A reviewer sub agent sees the changes in a separate context. It runs get diff, reads the modified files, and applies its specialized review criteria without the history of how the code was written. And this separation also lets you encode project-specific review standards in the sub agent system prompt, ensuring consistent review criteria across the team.

Claude Code's default system prompt emphasizes concise, code-focused response. And this works great for coding, but not for everything. So, one is a copywriting sub-agent with instructions about tone, audience, and style. This will produce better marketing text than the main thread would. Claude Code's default prompt tends towards concise, technical writing, which really isn't what you want for a landing page or email campaign, unless you want to put your customers to sleep. A copywriting sub-agent can have completely different instructions about voice and structure.

A styling sub-agent that @ mentions your design system files will apply consistent CSS patterns. When the sub-agent runs, those files load into the context automatically, so it knows your color variables, spacing conventions, and component patterns before it even starts writing any CSS.

Sub-agents that claim expertise rarely help. Prompts like, "You are a Python expert." or "You are a Kubernetes specialist." add no value because Claude already has that knowledge. The overhead of launching a sub-agent, losing visibility into its work, and compressing its findings into a summary only makes sense when the sub-agent does something that the main thread can't. Like applying a custom system prompt or keeping exploratory work isolated.

Sequential sub-agent pipelines create problems. Consider a three-agent flow. One to reproduce a bug, one to debug it, and one to fix it. Pipelines work when tasks are truly independent. They fail when each step depends on discoveries from the previous step.

Test runner sub-agents tend to hide information you need. When tests fail, you want the full output to diagnose issues. A sub-agent that returns a test failed forces you to create additional debug scripts to get details that would have been visible in direct output. Testing has showed that the test runner pattern performed worse among all configurations.

Across the series, we covered how sub-agents work as isolated threads that return summaries. How to create them with the /agents command, and how to design them with structured outputs and specific descriptions. Use them for research, reviews, and tasks needing custom system prompts. But, avoid them for expert claims, multi-step pipelines, and test runners. The key question, does the intermediate work matter? If not, then delegate it.

本文原文(テキストレッスン)

Using subagents effectively

You know how to create subagents and design them well. Now the question is: when do they actually help, and when do they get in the way? The difference comes down to one thing -- whether the intermediate work matters to your main thread.

When subagents shine

Subagents work best when the exploration is separate from the execution. If each step in a task depends on what the previous step discovered, you want that work in your main thread. But if you just need an answer and don't care about the journey, delegate it.

Subagents excel at tasks where:

You need a result, not a play-by-play of how it was found
The exploratory work would clutter your main thread's context
The task benefits from a fresh perspective or a custom system prompt

Research tasks

Research is the classic subagent use case. Consider investigating how authentication works in an unfamiliar codebase. Your main thread needs to know where the JWT is validated, but it doesn't need to see every file that was searched along the way.

A research subagent can read dozens of files, trace through function calls, and explore different code paths. All that exploration stays in the subagent's context. Your main thread receives a clean summary like:
JWT validation happens in middleware/auth.js line 42,
called from the Express router in route/api.js
The subagent did the heavy lifting. Your main thread gets exactly what it needs to move forward.

Code Reviews

Claude reviews code more effectively when the code is presented as being authored by someone else. If you built a feature over many turns with your main thread, asking that same thread to review it often produces weak feedback. Claude was involved in creating it, so it has trouble seeing it with fresh eyes.

A reviewer subagent sees the changes in a separate context. It runs git diff, reads the modified files, and applies its specialized review criteria without the history of how the code was written. This separation also lets you encode project-specific review standards in the subagent's system prompt, ensuring consistent review criteria across the team.

Custom System Prompts

Claude Code's default system prompt emphasizes concise, code-focused responses. That works great for coding, but not for everything.

Here are two cases where a custom system prompt makes the subagent genuinely better than the main thread:

Copywriting subagent -- Give it instructions about tone, audience, and style. Claude Code's default prompt tends toward concise technical writing, which really isn't what you want for a landing page or email campaign. A copywriting subagent can have completely different instructions about voice and structure.
Styling subagent -- Point it at your design system files. When the subagent runs, those files load into its context automatically, so it knows your color variables, spacing conventions, and component patterns before it even starts writing any CSS.

When Subagents Hurt

The overhead of launching a subagent -- losing visibility into its work and compressing its findings into a summary -- only makes sense when the subagent does something the main thread can't. There are three common anti-patterns to watch out for.

Expert Claims

Subagents that claim expertise rarely help. Prompts like "you are a Python expert" or "you are a Kubernetes specialist" add no value because Claude already has that knowledge. There's nothing a so-called expert subagent can do that your main thread can't do directly.

Sequential Pipelines

Sequential subagent pipelines create problems. Consider a three-agent flow: one to reproduce a bug, one to debug it, and one to fix it. Pipelines work when tasks are truly independent. They fail when each step depends on discoveries from the previous step -- and bug fixing almost always does. Information gets lost in the handoff between agents.

Test Runners

Test runner subagents tend to hide information you need. When tests fail, you want the full output to diagnose issues. A subagent that returns "tests failed" forces you to create additional debug scripts to get details that would have been visible in direct output. Testing has shown that the test runner pattern performed worse among all configurations.

The Decision Rule

When you're deciding whether to use a subagent, ask yourself one question: does the intermediate work matter?

If the answer is no -- you just need the final result -- delegate it to a subagent. If the answer is yes -- you need to see and react to what's happening along the way -- keep it in your main thread.

Use subagents for:

Research and exploration
Code reviews
Tasks that need a custom system prompt

Avoid subagents for:

"Expert" personas that don't add real capability
Multi-step pipelines where each step depends on the last
Running tests where you need full output for debugging
↑ 目次へ戻る