AIニュース最前線
最新ニュースAI日報Hacker日報週報動画AIツールトレンド企業

AIニュース最前線

世界中のAI最新情報を日本語で毎時更新

最新ニュース日報トレンド企業プレミアムRSS
© 2026 ainew.jp特定商取引法に基づく表記
ニュース一覧元記事を開く
Claude Blog·2026年4月7日 09:00·約25分で読める

Claude Codeにおけるサブエージェントの使用方法と適切なタイミング

#AI支援開発#コード生成#コンテキスト管理#Claude#エージェントアーキテクチャ#開発者ツール
TL;DR

Claude Codeのサブエージェント機能は、複雑なコーディングプロジェクトにおいて、コンテキストウィンドウの肥大化を防ぎ、並列タスク処理を可能にする実用的な手法を提供する。

AI深層分析2026年4月8日 07:42
3
注目/ 5段階
深度40%
4
関連度30%
4
実用性20%
5
革新性10%
2

キーポイント

1

サブエージェントの基本概念

サブエージェントは独立したコンテキストウィンドウを持つClaudeインスタンスで、メインセッションから分離してタスクを実行し、結果のみを返す仕組みである。

2

使用すべき状況の判断基準

リサーチ集約型タスクや複数のファイルを読む必要がある場合など、コンテキストの肥大化が懸念される作業にサブエージェントの使用が推奨される。

3

実装上の利点

並列処理が可能で、各サブエージェントに異なる権限(読み取り専用、編集権限など)を設定できる柔軟性がある。

4

組み込みサブエージェントの種類

Claude Codeには汎用エージェント、計画エージェント、探索エージェントなど、特定の用途に最適化された複数のサブエージェントタイプが用意されている。

5

サブエージェントの具体的な使用方法

会話形式で自然言語を使ってサブエージェントを起動でき、VS CodeやターミナルなどすべてのClaude Codeインターフェースで動作する。明確な指示と出力形式の指定が重要。

6

効果的なプロンプト構造

サブエージェントの使用を明示的に指示し、スコープを指定し、タスクが独立している場合は並列実行を要求し、望ましい出力を記述することが効果的。

7

カスタムサブエージェントの作成と活用

繰り返し使用する特定のタスク(セキュリティレビュー、テスト作成など)に対してカスタムサブエージェントを定義でき、Claudeはタスクが一致すると自動的に委譲する。カスタムサブエージェントは.markdownファイルとして.claude/agents/ディレクトリに保存される。

影響分析・編集コメントを表示

影響分析

この記事は、大規模コードベースでのAI支援開発における実践的な課題(コンテキスト管理、コスト最適化)に対する具体的な解決策を提示しており、開発者向けの実用性が高い。ただし、これは特定製品の機能紹介であり、業界全体を変革するような技術的革新ではない。

編集コメント

製品機能の実用的な解説記事であり、開発者にとっては具体的な活用方法が理解できる内容。業界全体の動向というよりは、特定プラットフォームのベストプラクティス紹介に焦点を当てている。

Claude Codeでサブエージェントをどのように、いつ使用するか

Claude Codeサブエージェントの実践ガイド:役立つ場面、指示方法、委任が価値があることを示すサイン

カテゴリーClaude Code

製品Claude Code

日付2026年4月7日

読了時間5分

共有リンクをコピーhttps://claude.com/blog/how-and-when-to-use-subagents-in-claude-code

Claude Codeは複雑な多段階プロジェクトをうまく処理しますが、長時間のセッションは重くなります。読み込まれたすべてのファイル、探索されたすべての余談、未完成のすべての思考がコンテキストウィンドウに残り、応答を遅くし、トークンコストを押し上げます。

大規模なTypeScriptモノレポで新機能を構築することを考えてみてください。主な作業は実装ですが、副次的なタスクが次々と現れます:既存サービスが認証をどのように処理するかを追跡する、日付フォーマット用の共有ユーティリティを見つける、デザインシステムに必要なものに近いコンポーネントがすでにあるか確認する。これらはいずれもプロジェクト全体のコンテキストを必要とせず、メインセッション内で実行するとノイズが増えます。これらを並行して実行できたらどうでしょうか?

そこでサブエージェントです。サブエージェントは独自のコンテキストウィンドウを持つ分離されたClaudeインスタンスです。タスクを受け取り、作業を行い、結果のみを返します。サブエージェントをClaude Codeセッションのブラウザタブと考えてください:メインの流れを失うことなく余談を追いかける場所です。

この記事では、サブエージェントを使用することが理にかなう場合、それらを呼び出す方法、そしてオーバーヘッドが価値がない場合について議論します。

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

サブエージェントは独自のコンテキストウィンドウで動作する自己完結型エージェントです。Claudeがサブエージェントを生成すると、そのアシスタントは独立してファイルを読み、コードを探索し、変更を加えます。タスクを完了すると、サブエージェントは関連する結果のみをメイン会話に返します。

各サブエージェントは新しく開始され、会話の履歴や呼び出されたスキルの負担を受けません。複数のサブエージェントを並行して実行でき、それぞれに異なる権限を設定できます:調査用サブエージェントは読み取り専用アクセスを持つかもしれませんが、実装用サブエージェントは完全な編集権限を得ます。

Claude Codeにはいくつかの組み込みサブエージェントタイプが含まれています:

複雑な多段階タスクのための汎用エージェント

実装戦略を提示する前にコードベースを調査する計画エージェント

高速で読み取り専用のコード検索に最適化された探索エージェント

Claude Codeは多くの場合、割り当てられたタスクを処理するために独自にサブエージェントを生成します。その動作を明示的に指示したり、Claudeが自動的に委任する再利用可能な専門家を定義することも可能です。いつサブエージェントを使用するかを知ることが、この機能を有用にする鍵です。

いつサブエージェントを使用すべきか?

特定のカテゴリーの作業は、サブエージェント委任から明らかに利益を得ます。それらを認識できるようになると、この機能ははるかに効果的になります。

調査が中心のタスク

何かを変更する前にその仕組みを理解することが前提条件である場合、サブエージェントはコードベースを探索し、要約を返すことができます。会話に数十のファイルをダンプする代わりに。

サイン:コンテキスト収集には数十のファイルを読む必要がある。

利点:メイン会話はクリーンなまま保たれ、生のコンテンツではなく統合された発見が届く。

複数の独立したタスク

複数のファイルにわたるエラーの修正、複数のコンポーネントでのパターンの更新、互いに依存しない変更を行う場合、並行サブエージェントはタスクをより速く完了します。

サイン:サブタスク間に依存関係がない。

利点:3つのサブエージェントが同時に作業することで、一般的にタスクをより短時間で終える。

新鮮な視点が必要な場合

実装の偏りのないレビューが目的である場合、サブエージェントはクリーンスレートを提供します。なぜなら、プライマリー会話からの仮定、コンテキスト、盲点を継承しないからです。

サイン:会話履歴が分析に影響を与えない検証が必要。

利点:よりクリーンで客観的なフィードバック。

プロのヒント:/clearコマンドもコンテキストと会話履歴をリセットし、同様に偏りのない状態を提供しますが、その履歴を完全に失う代償があります。サブエージェントはメイン会話をそのまま保ちながら、同じ新鮮な視点を達成します。

コミット前の検証

変更を確定する前に、独立したサブエージェントが実装がテストに過剰適合していないか、エッジケースを見逃していないかを検証できます。

サイン:コードをコミットする前に第二の意見が必要。

利点:コードに慣れていることで見えなくなるかもしれない問題を捕捉。

パイプラインワークフロー

タスクに明確なフェーズ(例:設計、実装、テスト)がある場合、各段階は集中した注意を払うことで利益を得ます。

サイン:明確な引き継ぎのある連続的な段階。

利点:各サブエージェントはそのフェーズに集中し、他の段階からのコンテキストがノイズを作らない。

プロのヒント:タスクが10以上のファイルの探索を必要とする場合、または3つ以上の独立した作業を含む場合、それはClaudeにサブエージェントを使用するよう指示する強いサインです。

サブエージェント使用を指示する方法

サブエージェントを呼び出すためのいくつかの方法があり、単純な会話から自動化されたワークフローまで幅があります。適切な出発点はワークフローによって異なり、パターンが現れるにつれて洗練度を重ねることができます。

会話による呼び出し

最も柔軟なアプローチは、単にClaudeに会話でサブエージェントを使用するよう依頼することです。これはすべてのClaude Codeインターフェースで動作します:ターミナル、VS Code、JetBrains、ウェブ、デスクトップアプリケーション。

サブエージェントを確実に呼び出す自然言語パターンには以下が含まれます:

「サブエージェントを使用して、このコードベースで認証がどのように機能するかを探索してください」

「別のエージェントにこのコードをセキュリティ問題についてレビューさせてください」

「これを並行して調査してください。APIルート、データベースモデル、フロントエンドコンポーネントを同時にチェックしてください」

「サブエージェントを起動して、これらの異なるパッケージにわたるTypeScriptエラーを修正してください」

明確であることが重要です。スコープを指定し、タスクが独立している場合は並行実行を要求し、望ましい出力を記述してください。

効果的なプロンプト構造の例:

サブエージェントを使用してこのコードベースを並行して探索してください:1. すべてのAPIエンドポイントを見つけ、その目的を要約する 2. データベーススキーマと関係を特定する 3. 認証フローをマッピングする 各々の要約を返し、完全なファイル内容は返さないでください。

このプロンプトが機能する理由は、3つの独立したタスクを明確に定義し、並行実行を明示的に要求し、出力形式を指定しているからです。Claudeは意図を理解し、適切なサブエージェントを生成します。

効果的な会話呼び出しのヒント:

タスクを明確にスコープする。「支払いがどのように機能するかを探索する」は「すべてを探索する」よりも良い。

並列化を明示的に要求する。「これらは並行して実行できます」または「3つすべてを同時に作業してください」と言う。

何を返すべきかを指定する。要約、特定の発見、または推奨事項。出力形式を命名することでClaudeがそれを提供しやすくなる。

偏りのない分析が重要な場合は新鮮なコンテキストを要求する。「私たちの以前の議論を見ないサブエージェントを使用してください」と依頼することでクリーンな評価が保証される。

プロのヒント:サブエージェントに時間がかかっている場合、Ctrl+Bでバックグラウンドに送信できます。それが実行されている間も会話を続けることができ、完了時に結果が自動的に表示されます。/tasksコマンドはバックグラウンドで実行されているものを表示します。

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

同じ種類のサブエージェントが繰り返し要求される場合(セキュリティレビュアー、テスト作成者、ドキュメント校正者)、一度カスタムサブエージェントとして定義できます。

Claudeはその後、タスクがその説明に一致するたびに自動的に委任します。プロンプトは必要ありません。

カスタムサブエージェントは.claude/agents/ディレクトリにマークダウンファイルとして保存されます。

~/.claude/agents/

作成する最も簡単な方法は/agentsコマンドで、インタラクティブにセットアップを案内し、説明から最初のドラフトを生成できます。ファイルは手書きでも作成できます。例:


name: security-reviewer

description: コード変更をセキュリティ脆弱性、インジェクションリスク、認証問題、機密データ漏洩についてレビューします。認証、支払い、ユーザーデータに触れるコミット前には積極的に使用してください。

tools: Read, Grep, Glob

model: sonnet


あなたはセキュリティに焦点を当てたコードレビュアーです。提供された変更を分析してください:

  • SQLインジェクション、XSS、コマンドインジェクションリスク
  • 認証と認可のギャップ
  • ログ、エラー、レスポンス内の機密データ
  • 安全でない依存関係や設定

ファイル:行参照とそれぞれに対する推奨修正を含む優先順位付けされた発見のリストを返してください。批判的であってください。何も見つからない場合は、問題をでっち上げるのではなく、明示的にそう言ってください。

これが設定されると、Claudeは一致する作業を自動的にサブエージェントにルーティングします。名前で呼び出すこともできます:「security-reviewerにステージングされた変更を見させてください。」

カスタムサブエージェントは以下の場合に最適です:

タスクが一致したときにClaudeが自動的に委任する専門家を利用可能にすべき場合

作業が厳密にスコープされたシステムプロンプトと制限されたツールから利益を得る場合

設定がチーム全体で共有されるべき、またはプロジェクト間で再利用されるべき場合

プロのヒント:説明フィールドは、Claudeがいつ委任するかを決定するために使用します。能力だけでなく、トリガー条件について具体的に記述してください。「コミット前にコードをセキュリティ問題についてレビューする」は「セキュリティ専門家」よりもルーティングが良くなります。

権限モードやプロジェクトとユーザーサブエージェントの相互作用を含む完全な設定リファレンスについては、Claude Codeサブエージェントドキュメントを参照してください。

CLAUDE.md指示

カスタムサブエージェントは専門家が誰であるかを定義します。CLAUDE.mdファイルは、Claudeがいつそれらを使用すべきかのルールを定義します。すべてのコードレビューが読み取り専用サブエージェントを通るべきである場合、またはすべてのアーキテクチャ質問が最初に調査パスをトリガーすべきである場合、CLAUDE.mdはそのポリシーが存在する場所です。Claudeはすべての会話の開始時にそれを読み取るので、誰も依頼することを覚えておく必要なく、セッションやチームメイト全体で一貫した動作が保たれます。

CLAUDE.mdは以下の場合にサブエージェント指示に適しています:

コードレビューは常に読み取り専用サブエージェントを使用すべき

プロジェクトにClaudeが従うべき特定の調査パターンがある

チームメンバーとセッション全体で一貫した動作が必要

特定の条件でサブエージェントをトリガーする単純なCLAUDE.mdファイルの例:

コードレビュー基準 コードレビューを依頼されたときは、常に読み取り専用アクセス(Glob、Grep、読み取り専用)のサブエージェントを使用してください。レビューでは常に以下を確認する必要があります:

  • セキュリティの脆弱性
  • パフォーマンスの問題
  • /docs/architecture.md に記載されたプロジェクトパターンへの準拠

発見事項は、ファイル:行番号の参照付きで優先順位付けされたリストとして返してください。

上記のCLAUDE.mdファイルがあれば、すべてのコードレビューリクエストが自動的に定義されたパターンを使用するため、毎回指定する必要がなくなります。

CLAUDE.mdファイルの詳細については、「コードベース用にClaude Codeをカスタマイズする:CLAUDE.mdファイルの設定」および「Claude Code CLAUDE.mdファイルドキュメント」を参照してください。

繰り返し実行される複雑な多段階ワークフローには、スキルが再利用可能なインターフェースを提供します。.claude/skills/で一度スキルを定義すると、/skill-nameで呼び出したり、タスクがその説明と一致したときにClaudeが自動的に読み込んだりできます。

スキルはCLAUDE.mdファイルと範囲が異なります。CLAUDE.mdファイルは常に読み込まれ、すべてのやり取りを形成します。スキルはオンデマンドで読み込まれます。明示的に呼び出された場合、またはClaudeが現在のタスクをスキルの説明フィールドと一致させた場合です。これにより、スキルは、利用可能であるべきだがすべてのプロンプトに適用されるべきではないワークフローに適した場所となります。

スキルは以下の場合に適しています:

  • 特定のアクションが定期的に実行される
  • 異なるチームメンバーが同じ複雑な操作にアクセスする必要がある
  • 特定のタスクの実行方法をチーム全体で標準化することが重要である

以下は、包括的なコードレビューのためのディープレビュースキルの例です:

.claude/skills/deep-review/SKILL.md


name: deep-review

description: セキュリティ、パフォーマンス、スタイルを並行してチェックする包括的なコードレビュー。コミットやPRの前にステージングされた変更をレビューするときに使用します。


ステージングされた変更に対して3つの並列サブエージェントレビューを実行します:

  1. セキュリティレビュー - 脆弱性、インジェクションリスク、認証問題、機密データの露出をチェック
  2. パフォーマンスレビュー - N+1クエリ、不要な反復、メモリリーク、ブロッキング操作をチェック
  3. スタイルレビュー - /docs/style-guide.md に記載されたプロジェクトパターンとの一貫性をチェック

発見事項を単一の要約に統合し、優先順位付けされた問題を含めます。各問題には、ファイル、行番号、推奨修正を含めてください。

上記のコードスニペットでは、/deep-reviewがオンデマンドで3つの部分からなるサブエージェント分析をトリガーします。説明にコミット前のステージングされた変更のレビューが言及されているため、Claudeはそのコンテキストが現れたときにもこのスキルを自動的に選択できます。

スキルは単一のファイルではなくディレクトリです。SKILL.mdに加えて、

.claude/commands/

Claude Codeでのスキルの使用に関する詳細は、「Claude Codeスキルドキュメント」を参照してください。

フックは、ユーザー定義のシェルコマンド、HTTPエンドポイント、またはLLMプロンプトで、Claude Codeのライフサイクルの特定の時点で自動的に実行されます。フックはイベントに基づいてサブエージェントワークフローを自動化できます。フックは特定のアクションでトリガーされ、手動呼び出しなしでサブエージェントタスクを実行します。

フックは以下の場合に適したツールです:

  • すべてのコミットが作成される前に自動的にレビューされるべきである
  • セキュリティチェックが誰も依頼することを覚えていなくても実行されるべきである
  • CIのような品質ゲートがローカル開発プロセスに属している

以下は、テストに合格するまでClaudeがターンを終了するのをブロックするStopフックの例です:

{ "hooks": { "Stop": [ { "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/check-tests.sh" } ] } ] } }

そして、.claude/hooks/check-tests.shにあるスクリプト

#!/bin/bash

INPUT=$(cat)

STOP_HOOK_ACTIVE=$(echo "$INPUT" | jq -r '.stop_hook_active // false')

永久ループを防ぐ — このターンですでにブロックした場合は通過させる

if [ "$STOP_HOOK_ACTIVE" = "true" ]; then

exit 0

fi

if ! npm test --silent > /dev/null 2>&1; then

jq -n '{ decision: "block", reason: "Tests are failing. Run npm test to see the failures and fix them before finishing." }'

exit 0

fi

exit 0

Claudeがターンを終了すると、Stopイベントが発生します。スクリプトはテストスイートを実行し、テストが失敗した場合、decision: "block"を含むJSONを返します。

stop_hook_active

フックは、サブエージェントオーケストレーションの最も自動化されたアプローチを表します。会話型の呼び出しやCLAUDE.mdの指示は、より良い出発点です。フックは、ワークフローが成熟するにつれて後から導入されます。

完全なフック設定については、「Claude Codeパワーユーザーカスタマイズ:フックの設定方法」または「Claude Codeフックドキュメント」を参照してください。

サブエージェントを使用する実践的なパターン

以下のパターンは、一般的なシナリオに適用されるサブエージェントの指示を示しています。

実装前の調査

不慣れなコードに機能を追加するとき、まず調査をサブエージェントに委任することで、実装の議論を探索的ではなく情報に基づいたものに保ちます。例えば:

ユーザー通知を実装する前に、サブエージェントを使用して調査してください:

  • このコードベースでは現在どのようにメールが送信されていますか?
  • どの通知パターンが既に存在しますか?
  • 現在のアーキテクチャに基づいて、新しい通知ロジックはどこに配置すべきですか?

調査結果を要約し、その後一緒に実装計画を立てましょう。

生のコンテキストの20ファイルではなく、統合された要約が届き、実装の議論は確固たる基盤から始まります。

並列変更

同じパターンを複数のファイルで更新する必要がある場合、並列サブエージェントはより速く完了し、焦点を維持します。例えば:

並列サブエージェントを使用して、以下のファイルのエラーハンドリングを更新してください:

  • src/api/users.ts
  • src/api/orders.ts
  • src/api/products.ts

各ファイルは、src/api/auth.tsで確立されたパターンに従うべきです。3つすべてを同時に作業してください。

3つのサブエージェントが並行して作業することで、1つがかかる時間とほぼ同じ時間で完了します。各サブエージェントは、他のサブエージェントからのコンテキストによる混乱や不整合なしに、自分のファイルに集中します。

独立したレビュー

複雑なものを実装した後、実装の過程に影響されていないサブエージェントによる検証は、慣れによって見えなくなるものを捕捉します。例えば:

読み取り専用アクセスを持つ新しいサブエージェントを使用して、私の支払いフローの実装をレビューしてください。以前の議論を見るべきではありません。偏りのないレビューが欲しいです。以下をチェックしてください:セキュリティの脆弱性、未処理のエッジケース、エラーハンドリングのギャップ。批判的に評価してください。

レビューサブエージェントは、どのようなトレードオフが考慮されたか、どのアプローチが拒否されたか、どのような仮定がなされたかを知らずにコードを評価します。この外部の視点は、メインの会話では見逃す可能性のある問題を浮き彫りにします。

パイプラインワークフロー

多段階タスクの場合、段階間の明示的な受け渡しでサブエージェントを連鎖させることで、各段階に焦点を当て続けます。例えば:

この機能をパイプラインとして構築しましょう:

  1. 最初のサブエージェント:API契約を設計し、docs/api-spec.mdに書き込む
  2. 2番目のサブエージェント:その仕様に基づいてバックエンドエンドポイントを実装する
  3. 3番目のサブエージェント:実装の統合テストを書く

各段階は次の段階が始まる前に完了するべきです。出力ファイルを段階間の受け渡しメカニズムとして使用してください。

パイプラインワークフローを使用することで、タスクの各段階は焦点を絞ったコンテキストを受け取ります。設計サブエージェントは実装の懸念に気を取られず、実装サブエージェントはクリーンな仕様から作業し、テストサブエージェントは結果を独立して評価します。

サブエージェントを使用すべきでない場合

サブエージェントは有用な機能ですが、オーバーヘッドを伴います。各サブエージェントは独自のコンテキストを立ち上げ、トークンを消費し、開発者と作業の間に間接的な層を追加します。コンテキストの分離、並列処理、または新しい視点が実際に役立つ場合、そのコストに見合う価値があります。

小さなタスクや密接に連続したタスクの場合、メインの会話に留まる方が通常は簡単です。例えば:

連続的で依存する作業。ステップ2がステップ1の完全な出力を必要とし、ステップ3が両方を必要とする場合、ファイルを通じて状態を受け渡すサブエージェントのリレーよりも、連鎖を処理する単一セッションの方が通常はクリーンです。

同じファイルの編集。2つのサブエージェントが同じファイルを並行して編集することは、競合のレシピです。このシナリオでは、密接に結合された変更を1つのコンテキストウィンドウに保ってください。

小さなタスク。クイックフィックスや焦点を絞った質問の場合、委任のオーバーヘッドは利点を上回ります。メインの会話でプロンプトを出すか尋ねてください。

専門家エージェントが多すぎる。すべてにカスタムサブエージェントを定義したくなるかもしれませんが、Claudeにオプションを溢れさせると、自動委任の信頼性が低下します。ほとんどのチームは、広がりすぎた名簿ではなく、よくスコープされた少数のエージェントに落ち着きます。

エージェント同士が調整する必要がある作業。サブエージェントはメインの会話に報告しますが、互いに話すことはできません。サブエージェントが通信する必要があるタスクには、エージェントチームを使用してください。エージェントチームでは、サブエージェントは1つの中ではなく別々のセッションで調整するため、より重く、より高価になります。サブエージェントとエージェントチームのどちらを使用すべきかの詳細なガイダンスについては、「Claude Codeエージェントチームドキュメント」を確認してください。

前述のシグナル(つまり、第二の意見が必要、サブタスク間に依存関係がない、広範な調査)は、サブエージェントへの委任が価値があるときを明確にします。

会話型から始め、後で自動化する

サブエージェントは、意図的に使用されたときに完全な価値を提供します。Claudeが提供する自動呼び出しは役立ちますが、調査を委任するとき、作業を並列化するとき、新しい視点を要求するときを知ることで、偶然に任せるよりも良い結果を生み出します。

サブエージェントを使用するときは、会話型プロンプトから始めてください。どのリクエストが繰り返し発生するかに気づき、それらのパターンが明確になるにつれて自動化を構築してください。目標は、サブエージェント委任を努力なしに行えるようにし、あなたの注意が重要な作業に留まるようにすることです。

PrevPrev0/5NextNexteBook

curl -fsSL https://claude.ai/install.sh | bashコマンドをクリップボードにコピーirm https://claude.ai/install.ps1 | iexコマンドをクリップボードにコピーまたはドキュメントを読むClaude Codeを試すClaude Codeを試すClaude Codeを試す開発者向けドキュメント開発者向けドキュメント開発者向けドキュメント関連記事

Claudeで構築するチームのための製品ニュースとベストプラクティスをさらに探求してください。

AI指数関数的成長におけるプロダクトマネジメント

Claude CodeAI指数関数的成長におけるプロダクトマネジメント AI指数関数的成長におけるプロダクトマネジメント AI指数関数的成長におけるプロダクトマネジメント AI指数関数的成長におけるプロダクトマネジメント 2026年2月23日AIがCOBOL近代化のコスト障壁を打破する方法

Claude CodeAIがCOBOL近代化のコスト障壁を打破する方法 AIがCOBOL近代化のコスト障壁を打破する方法 AIがCOBOL近代化のコスト障壁を打破する方法 AIがCOBOL近代化のコスト障壁を打破する方法 2026年2月20日Claude Codeデスクトップ版への自動プレビュー、レビュー、マージの導入

Claude CodeClaude Codeデスクトップ版への自動プレビュー、レビュー、マージの導入 Claude Codeデスクトップ版への自動プレビュー、レビュー、マージの導入 Claude Codeデスクトップ版への自動プレビュー、レビュー、マージの導入 Claude Codeデスクトップ版への自動プレビュー、レビュー、マージの導入 2026年3月3日skill-creatorの改善:エージェントスキル(Agent Skills)のテスト、測定、改良

Claude Codeskill-creatorの改善:エージェントスキル(Agent Skills)のテスト、測定、改良 skill-creatorの改善:エージェントスキル(Agent Skills)のテスト、測定、改良 skill-creatorの改善:エージェントスキル(Agent Skills)のテスト、測定、改良 skill-creatorの改善:エージェントスキル(Agent Skills)のテスト、測定、改良Claudeで組織の運営方法を変革する

開発者向けニュースレターを購読

プロダクトアップデート、ハウツーガイド、コミュニティスポットライトなど。毎月メールボックスにお届けします。

購読購読月次開発者ニュースレターの配信をご希望の場合は、メールアドレスをご提供ください。いつでも購読を解除できます。

原文を表示

How and when to use subagents in Claude Code

A practical guide to Claude Code subagents: when they help, how to direct them, and the signals that tell you delegation is worth it.

CategoryClaude Code

ProductClaude Code

DateApril 7, 2026

Reading time5min

ShareCopy linkhttps://claude.com/blog/how-and-when-to-use-subagents-in-claude-code

Claude Code handles complex, multi-step projects well, but long sessions accumulate weight. Every file read, every tangent explored, every half-finished thought stays in the context window, slowing responses and driving up token costs.

Consider building a new feature in a large TypeScript monorepo. The main work is the implementation, but side tasks keep appearing: trace how an existing service handles auth, find the shared util for date formatting, check whether the design system already has a component close to what you need. None of these need the full project context, and running them inside the main session adds noise. What if you could run them in parallel?

Enter subagents. A subagent is an isolated Claude instance with its own context window. It takes a task, does the work, and returns only the result. Think of subagents as the browser tabs of a Claude Code session: a place to chase a tangent without losing the main thread.

In this article, we discuss when it makes sense to use subagents, how to invoke them, and when the overhead isn't worth it.

What is a subagent?

Subagents are self-contained agents that operate with their own context windows. When Claude spawns a subagent, that assistant works independently to read files, explore code, or make changes. When it completes its task, the subagent returns only the relevant results to the main conversation.

Each subagent starts fresh, unburdened by the history of the conversation or invoked skills. Multiple subagents can run in parallel, and each can have different permissions: a research subagent might have read-only access, while an implementation subagent gets full editing capabilities.

Claude Code includes several built-in subagent types, including:

General-purpose agents for complex multi-step tasks

Plan agents that research codebases before presenting implementation strategies

Explore agents optimized for fast, read-only code search

Claude Code often spawns subagents on its own to handle assigned tasks. It's also possible to direct that behavior explicitly and to define reusable specialists that Claude delegates to automatically. Knowing when to reach for subagents is what makes the feature useful.

When should you use subagents?

Certain categories of work benefit clearly from subagent delegation. Learning to recognize them makes the feature far more effective.

Research-heavy tasks

When understanding how something works is a prerequisite to changing it, a subagent can explore the codebase and return a summary rather than dumping dozens of files into the conversation.

The signal: Gathering context requires reading dozens of files.

The benefit: The main conversation stays clean, and synthesized findings arrive instead of raw content.

Multiple independent tasks

When fixing errors across several files, updating patterns in multiple components, or making changes that don't depend on each other, parallel subagents complete the task faster.

The signal: Sub-tasks have no dependencies between them.

The benefit: Three subagents working simultaneously generally finish the task in less time.

Fresh perspective needed

When an unbiased review of an implementation is the goal, a subagent provides a clean slate because it doesn't inherit the assumptions, context, or blind spots from the primary conversation.

The signal: Verification is needed without conversation history influencing the analysis.

The benefit: Cleaner, more objective feedback.

Pro-tip: The /clear command also resets context and conversation history, providing a similarly unbiased slate, but at the cost of losing that history entirely. A subagent achieves the same fresh perspective while the main conversation stays intact.

Verification before committing

Before finalizing changes, an independent subagent can verify the implementation isn't overfitting to tests or missing edge cases.

The signal: A second opinion is warranted before committing code.

The benefit: Catches issues that familiarity with the code might obscure.

Pipeline workflows

When a task has distinct phases (i.e., design, then implement, then test), each stage benefits from focused attention.

The signal: Sequential stages with clear handoffs.

The benefit: Each subagent concentrates on its phase, without context from other stages creating noise.

‍Pro-tip: When a task requires exploring ten or more files, or involves three or more independent pieces of work, that's a strong signal to direct Claude toward subagents.

How to direct subagent usage

Several methods exist for invoking subagents, ranging from simple conversation to automated workflows. The right starting point depends on the workflow, and sophistication can be layered on as patterns emerge.

Conversational invocation

The most flexible approach is simply asking Claude to use subagents in conversation. This works across all Claude Code interfaces: terminal, VS Code, JetBrains, the web, and desktop applications.

Natural language patterns that reliably invoke subagents include:

"Use a subagent to explore how authentication works in this codebase"

"Have a separate agent review this code for security issues"

"Research this in parallel. Check the API routes, database models, and frontend components simultaneously"

"Spin up subagents to fix these TypeScript errors across the different packages"

Being explicit matters. Specify the scope, request parallel execution when tasks are independent, and describe the desired output.

Here's an effective prompt structure:

Use subagents to explore this codebase in parallel: 1. Find all API endpoints and summarize their purposes 2. Identify the database schema and relationships 3. Map out the authentication flow Return a summary of each, not the full file contents.

This prompt works because it clearly defines three independent tasks, explicitly requests parallel execution, and specifies the output format. Claude understands the intent and spawns appropriate subagents.

Tips for effective conversational invocation include:

Scope tasks clearly. "Explore how payments work" beats "explore everything."

Request parallelization explicitly. Say "these can run in parallel" or "work on all three simultaneously."

Specify what should be returned. Summaries, specific findings, or recommendations. Naming the output format helps Claude deliver it.

Ask for fresh context when unbiased analysis matters. "Use a subagent that does not see our previous discussion" ensures clean evaluation.

Pro-tip: When a subagent is taking a while, Ctrl+B sends it to the background. The conversation can continue while it runs, and results surface automatically when it finishes. The /tasks command shows anything running in the background.

Custom subagents

When the same kind of subagent keeps getting requested (a security reviewer, a test writer, a docs proofreader), it can be defined once as a custom subagent.

Claude then delegates to it automatically whenever a task matches its description, no prompting required.

Custom subagents live as markdown files in .claude/agents/

~/.claude/agents/

The easiest way to create one is the /agents command, which walks through setup interactively and can generate a first draft from a description. The file can also be written by hand, for example:

--- name: security-reviewer description: Reviews code changes for security vulnerabilities, injection risks, auth issues, and sensitive data exposure. Use proactively before commits touching auth, payments, or user data. tools: Read, Grep, Glob model: sonnet --- You are a security-focused code reviewer. Analyze the provided changes for: - SQL injection, XSS, and command injection risks - Authentication and authorization gaps - Sensitive data in logs, errors, or responses - Insecure dependencies or configurations Return a prioritized list of findings with file:line references and a recommended fix for each. Be critical. If you find nothing, say so explicitly rather than inventing issues.

With this in place, Claude routes matching work to the subagent automatically. It can also be invoked by name: "Have the security-reviewer look at the staged changes."

Custom subagents work best when:

A specialist should be available for Claude to delegate to automatically when a task matches

The work benefits from a tightly scoped system prompt and restricted tools

The configuration should be shared across a team or reused across projects

Pro-tip: The description field is what Claude uses to decide when to delegate. Be specific about the trigger conditions, not just the capability. "Reviews code for security issues before commits" routes better than "security expert."

For the full configuration reference, including permission modes and how project and user subagents interact, see our Claude Code subagents docs.

CLAUDE.md instructions

Custom subagents define who the specialists are. CLAUDE.md files define the rules for when Claude should reach for them. If every code review should go through a read-only subagent, or every architecture question should trigger a research pass first, CLAUDE.md is where that policy lives. Claude reads it at the start of every conversation, so the behavior stays consistent across sessions and teammates without anyone needing to remember to ask.

CLAUDE.md is a good fit for subagent instructions when:

Code reviews should always use read-only subagents

The project has specific research patterns Claude should follow

Consistent behavior is needed across team members and sessions

Here’s an example of a simple CLAUDE.md file that triggers a subagent given specific conditions:

Code review standards When asked to review code, ALWAYS use a subagent with READ-ONLY access (Glob, Grep, Read only). The review should ALWAYS check for: - Security vulnerabilities - Performance issues - Adherence to project patterns in /docs/architecture.md Return findings as a prioritized list with file:line references.

With the above CLAUDE.md file, every code review request automatically uses the defined pattern, eliminating the need to specify it each time.

For more on CLAUDE.md files, see Customizing Claude Code for your codebase: setting up a CLAUDE.md file and our Claude Code CLAUDE.md file docs.

For complex multi-step workflows that run repeatedly, skills provide a reusable interface. Define a skill once in .claude/skills/, then invoke it with /skill-name or let Claude load it automatically when a task matches its description.

Skills differ from CLAUDE.md files in scope. CLAUDE.md files are always loaded and shapes every interaction. A skill is loaded on demand, either because it was invoked explicitly or because Claude matched the current task to the skill's description field. That makes skills the right place for workflows that should be available but not applied to every prompt.

Skills fit well when:

Certain actions get run regularly

Different team members need access to the same complex operation

Standardizing how certain tasks are performed across the team matters

Here’s an example of a deep-review skill for comprehensive code review:

.claude/skills/deep-review/SKILL.md --- name: deep-review description: Comprehensive code review that checks security, performance, and style in parallel. Use when reviewing staged changes before a commit or PR. --- Run three parallel subagent reviews on the staged changes: 1. Security review - check for vulnerabilities, injection risks, authentication issues, and sensitive data exposure 2. Performance review - check for N+1 queries, unnecessary iterations, memory leaks, and blocking operations 3. Style review - check for consistency with project patterns documented in /docs/style-guide.md Synthesize findings into a single summary with priority-ranked issues. Each issue should include the file, line number, and recommended fix.

In the code snippet above, /deep-review triggers a three-part subagent analysis on demand. Because the description mentions reviewing staged changes before commits, Claude can also reach for this skill automatically when that context comes up.

A skill is a directory, not a single file. Alongside SKILL.md,

.claude/commands/

For more on using skills with Claude Code, see our Claude Code skills docs.

Hooks are user-defined shell commands, HTTP endpoints, or LLM prompts that execute automatically at specific points in Claude Code's lifecycle. Hooks can automate subagent workflows based on events. Hooks trigger on specific actions and run subagent tasks without manual invocation.

Hooks are the right tool when:

Every commit should be reviewed automatically before it's created

Security checks should run without anyone remembering to ask

CI-like quality gates belong in the local development process

Here is an example of a Stop hook that blocks Claude from ending its turn until a test is passed:

{ "hooks": { "Stop": [ { "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/check-tests.sh" } ] } ] } }

And the script at .claude/hooks/check-tests.sh

#!/bin/bash INPUT=$(cat) STOP_HOOK_ACTIVE=$(echo "$INPUT" | jq -r '.stop_hook_active // false') # Don't loop forever — if we already blocked once this turn, let it through if [ "$STOP_HOOK_ACTIVE" = "true" ]; then exit 0 fi if ! npm test --silent > /dev/null 2>&1; then jq -n '{ decision: "block", reason: "Tests are failing. Run npm test to see the failures and fix them before finishing." }' exit 0 fi exit 0

When Claude finishes its turn, the Stop event fires. The script runs the test suite—if tests fail, it returns JSON with decision: "block"

stop_hook_active

Hooks represent the most automated approach to subagent orchestration. Conversational invocation or CLAUDE.md instructions are the better starting point; hooks come later, as workflows mature.

For complete hooks configuration, see Claude Code power user customization: how to configure hooks or our Claude Code hooks docs.

Practical patterns for using subagents

The following patterns demonstrate subagent direction applied to common scenarios.

Research before implementing

When adding a feature to unfamiliar code, delegating research to a subagent first keeps the implementation discussion informed rather than exploratory, for example:

Before I implement user notifications, use a subagent to research: - How are emails currently sent in this codebase? - What notification patterns already exist? - Where should new notification logic live based on the current architecture? Summarize findings, then we'll plan the implementation together.

A synthesized summary arrives instead of twenty files of raw context, and the implementation discussion starts from a solid foundation.

Parallel modifications

When the same pattern needs updating across multiple files, parallel subagents finish faster and maintain focus, for example:

Use parallel subagents to update the error handling in these files: - src/api/users.ts - src/api/orders.ts - src/api/products.ts Each should follow the pattern established in src/api/auth.ts. Work on all three simultaneously.

Three subagents working in parallel complete in roughly the time one would take. Each focuses on its file without context from the others creating confusion or inconsistency.

Independent review

After implementing something complex, verification from a subagent that hasn't been influenced by the implementation journey catches what familiarity obscures, for example:

Use a fresh subagent with read-only access to review my implementation of the payment flow. It should not see our previous discussion. I want an unbiased review. Check for: security vulnerabilities, unhandled edge cases, and error handling gaps. Be critical.

The review subagent evaluates the code without knowing what tradeoffs were considered, what approaches were rejected, or what assumptions were made. This outside perspective surfaces issues the main conversation might miss.

Pipeline workflow

For multi-stage tasks, chaining subagents with explicit handoffs between phases keeps each stage focused, for example:

Let's build this feature as a pipeline: 1. First subagent: Design the API contract and write it to docs/api-spec.md 2. Second subagent: Implement the backend endpoints based on that spec 3. Third subagent: Write integration tests for the implementation Each stage should complete before the next begins. Use the output files as the handoff mechanism between stages.

Using a pipeline workflow, each stage in the task receives focused context. The design subagent isn't distracted by implementation concerns, the implementation subagent works from a clean spec, and the testing subagent evaluates the result independently.

When shouldn’t you use subagents?

While subagents are a useful feature, subagents carry overhead. Each one spins up its own context, consumes tokens, and adds a layer of indirection between the developer and the work. They're worth that cost when context isolation, parallelism, or a fresh perspective actually helps.

For smaller or tightly sequential tasks, sticking to the main conversation is usually simpler, for example:

Sequential, dependent work. When step two needs the full output of step one, and step three needs both, a single session handling the chain is usually cleaner than a relay of subagents passing state through files.

Same-file edits. Two subagents editing the same file in parallel is a recipe for conflict. In this scenario, keep tightly coupled changes in one context window.

Small tasks. For a quick fix or a focused question, the overhead of delegation outweighs the benefit. Just prompt or ask in your main conversation.

Too many specialist agents. It's tempting to define a custom subagent for everything, but flooding Claude with options makes automatic delegation less reliable. Most teams settle on a handful of well-scoped agents rather than a sprawling roster.

Work that needs agents to coordinate with each other. Subagents report back to the main conversation but can't talk to one another. For tasks where subagents need to communicate, use agent teams. With agent teams, subagents coordinate across separate sessions rather than within one, which makes them heavier and more expensive. For more guidance on when to use subagents vs Agent Teams, check out our Claude Code agent teams docs.

The signals described earlier (i.e., needing a second opinion, a lack of dependencies between sub-tasks, and extensive research) make it clear when delegation to a subagent is worth it.

Start conversational, automate later

Subagents deliver their full value when used deliberately. The automatic invocation Claude provides is helpful, but knowing when to delegate research, parallelize work, and request a fresh perspective produces better results than leaving it to chance.

When using subagents, start with conversational prompts. Notice which requests keep occurring and build automation as those patterns clarify. The goal is to make subagent delegation effortless, so your attention stays on the work that matters.

PrevPrev0/5NextNexteBook

curl -fsSL https://claude.ai/install.sh | bashCopy command to clipboardirm https://claude.ai/install.ps1 | iexCopy command to clipboardOr read the documentationTry Claude CodeTry Claude CodeTry Claude CodeDeveloper docsDeveloper docsDeveloper docsRelated posts

Explore more product news and best practices for teams building with Claude.

Product management on the AI exponential

Claude CodeProduct management on the AI exponential Product management on the AI exponential Product management on the AI exponential Product management on the AI exponential Feb 23, 2026How AI helps break the cost barrier to COBOL modernization

Claude CodeHow AI helps break the cost barrier to COBOL modernizationHow AI helps break the cost barrier to COBOL modernizationHow AI helps break the cost barrier to COBOL modernizationHow AI helps break the cost barrier to COBOL modernization Feb 20, 2026Bringing automated preview, review, and merge to Claude Code on desktop

Claude CodeBringing automated preview, review, and merge to Claude Code on desktopBringing automated preview, review, and merge to Claude Code on desktopBringing automated preview, review, and merge to Claude Code on desktopBringing automated preview, review, and merge to Claude Code on desktop Mar 3, 2026Improving skill-creator: Test, measure, and refine Agent Skills

Claude CodeImproving skill-creator: Test, measure, and refine Agent SkillsImproving skill-creator: Test, measure, and refine Agent SkillsImproving skill-creator: Test, measure, and refine Agent SkillsImproving skill-creator: Test, measure, and refine Agent SkillsTransform how your organization operates with Claude

Get the developer newsletter

Product updates, how-tos, community spotlights, and more. Delivered monthly to your inbox.

SubscribeSubscribePlease provide your email address if you'd like to receive our monthly developer newsletter. You can unsubscribe at any time.

この記事をシェア

関連記事

Anthropic Research★32026年3月6日 09:00

2026年3月6日 Frontier Red TeamによるClaudeのCVE-2026-2796エクスプロイトのリバースエンジニアリング

Frontier Red Teamが、Claudeの脆弱性CVE-2026-2796を悪用するエクスプロイトをリバースエンジニアリングした。

Anthropic Research★32026年3月6日 09:00

フロンティア・レッドチーム、Firefoxのセキュリティ向上のためにMozillaと提携

フロンティア・レッドチームは、Firefoxのセキュリティを向上させるため、Mozillaと提携した。

宝玉的分享★42026年2月17日 09:00

59%のユーザーがより安価なモデルを選択:Sonnet 4.6の詳細解説

Anthropic社がClaude Sonnet 4.6をリリースし、Claude Codeテストで70%のユーザーが前世代モデルより好み、59%がフラッグシップモデルOpus 4.5よりも選択した。コーディング、コンピュータ利用、100万トークンコンテキストなど6次元で全面アップグレードされ、価格は据え置き。

ニュース一覧に戻る元記事を読む