ポッドキャストに戻るClaude
Claude Code subagents
サブエージェントを作る
In the previous video, we covered what sub aents are and how they work.
前回の動画では、サブエージェントとは何か、どのように機能するかを説明しました。
Cloud code includes built-in sub aents, but you can also create your own sub aents that specialize in certain tasks.
Claude Codeには組み込みのサブエージェントがありますが、特定のタスクに特化したカスタムサブエージェントも作成できます。
Custom sub aents are markdown files with YAML front matter.
カスタムサブエージェントは、YAMLフロントマターを持つmarkdownファイルです。
These markdown files contain configuration that helps claude understand when to use the sub aent and provides directions to the sub aent itself.
これらのmarkdownファイルには、Claudeがサブエージェントをいつ使用するかを判断するための設定と、サブエージェント自身への指示が含まれています。
Now, the easiest way to create a sub agent is with the / agents command.
サブエージェントを作成する最も簡単な方法は、/agentsコマンドを使うことです。
This panel is the main interface for managing your sub aents.
このパネルがサブエージェントを管理するメインのインターフェースです。
Once here, select create new agent.
ここで「新しいエージェントを作成」を選択します。
You'll then be asked if you want to create a sub aent for the current project or a sub aent that will be shared between all the projects on your machine.
現在のプロジェクト用のサブエージェントを作るか、マシン上のすべてのプロジェクトで共有するサブエージェントを作るかを選択するよう求められます。
Next, you can create a sub aent manually, but we recommend using claw code to automatically generate it for you.
サブエージェントを手動で作成することもできますが、Claude Codeを使って自動生成することをお勧めします。
Our first sub aent will be a code reviewer.
最初のサブエージェントはコードレビュアーにします。
I'll ask Claude to make a sub agent that reviews code quality and security issues.
コードの品質とセキュリティの問題をレビューするサブエージェントの作成をClaudeに依頼します。
Claude will use your input to generate a name, description, and system prompt for the sub agent.
Claudeはあなたの入力をもとに、サブエージェントの名前、説明、システムプロンプトを生成します。
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 an execution to allow the sub agent to more easily identify pending changes.
このサブエージェントはコードのレビューのみを担うため、編集ツールを無効にしても良いですが、変更待ちのコードを特定しやすくするために実行権限は残しておきます。
Next, you'll be prompted to select the model that powers this sub agent.
次に、このサブエージェントを動かすモデルを選択するよう求められます。
And finally, a color.
そして最後に、カラーを選択します。
This color is used in the UI to help you better identify the sub agent.
このカラーはUIでサブエージェントを識別しやすくするために使われます。
And it also just adds a little bit of personal flare.
個性を加えることもできます。
Now at the summary window, we see that the sub aent 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.
nameフィールドは一意の識別子です。
This is how you reference the sub agent either by asking claw directly or using at agent code quality reviewer in your message.
Claudeに直接指定するか、メッセージ内で@agent code-quality-reviewerと入力してサブエージェントを参照します。
The description controls when cla decides to use the sub aent.
descriptionフィールドは、Claudeがサブエージェントをいつ使用するかを制御します。
The description must be on a single line.
descriptionは必ず1行にまとめる必要があります。
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.
Claudeにサブエージェントをより頻繁に自動で使わせたい場合は、descriptionにproactivelyという単語を追加してください。
You can also add example conversations to help Claude understand when it should be using the sub agent.
また、サンプルの会話を追加することで、Claudeがサブエージェントをいつ使うべきかを理解しやすくなります。
The tools field lists which tools the sub agent can access.
toolsフィールドには、サブエージェントがアクセスできるツールが列挙されています。
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 claw model to use.
modelフィールドは使用するClaudeのモデルを指定します。
Sonnet, opus, haiku or inherit.
Sonnet、Opus、Haiku、またはinheritです。
Use haiku for fast tasks.
高速なタスクにはHaikuを使います。
Opus for complex analysis and sonnet if you need something between the two.
複雑な分析にはOpus、その中間にはSonnetを使います。
Inherit will use the same model as your main conversation.
inheritを選ぶと、メインの会話と同じモデルが使われます。
The body of the file contains the system prompt that is given to the sub aent.
ファイルの本文には、サブエージェントに渡すシステムプロンプトが含まれています。
The system prompt will provide guidance to the sub agent, helping it understand how to complete its task 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 claw to review them.
サブエージェントを作成したら、コードを変更してClaudeにレビューを依頼し、動作を確認してみてください。
If the sub agent isn't being used when you expect, check your description.
サブエージェントが期待通りに使われない場合は、descriptionを確認してください。
Adding more specific examples helps Claude understand when to delegate.
より具体的な例を追加することで、Claudeがいつ委譲すべきかを理解しやすくなります。