Claude Code Agents: 専門サブエージェント完全ガイド
すべてのClaude Codeエージェントタイプをマスターする。ExploreからSecurity-Auditorまで、各専門エージェントの使用タイミングと方法を学び、最大効率を実現。
Claude Codeのエージェントシステムは、最も強力な機能の一つです。Task toolを通じて、特定のタスクに最適化された専門サブエージェントを並列で生成できます。本ガイドでは、すべてのエージェントタイプ、使用タイミング、効果的な組み合わせ方を解説します。
Claude Code Agentsの理解
エージェントとは?
公式ドキュメントによると、Claude Codeにおけるエージェントとは、以下の特徴を持つ専門サブプロセスです:
- 独自のコンテキストで自律的に動作
- 特定のツールと機能にアクセス可能
- 他のエージェントと並列実行可能
- 結果をメイン会話に返却
Task Tool
Task toolはエージェントを生成する方法です:
Task({
subagent_type: "Explore", // Required: Agent type
model: "haiku", // Optional: haiku, sonnet, opus
prompt: "Your task description", // Required: What to do
run_in_background: false // Optional: Async execution
})
エージェントタイプ概要
| エージェントタイプ | 用途 | デフォルトモデル | 最適な用途 |
|---|---|---|---|
Explore | 高速コードベースナビゲーション | Haiku 4.5 | ファイル検索、パターン |
general-purpose | 複雑なマルチステップタスク | Sonnet 4.5 | 実装、分析 |
code-reviewer | コード品質分析 | Sonnet 4.5 | PRレビュー、パターン |
security-auditor | 脆弱性検出 | Sonnet 4.5 | 認証、決済コード |
test-runner | テスト実行 | Haiku 4.5 | テスト実行、分析 |
debugger | 根本原因分析 | Sonnet 4.5 | バグ調査 |
refactor-assistant | コード改善 | Sonnet 4.5 | クリーンアップ、再構築 |
doc-writer | ドキュメント作成 | Haiku/Sonnet | README、API ドキュメント |
Explore Agent
概要
Explore agent(v2.1.0で導入)は、Claude Codeの最速コードベースナビゲーションエージェントです。Haiku 4.5を搭載し、複数の検索ツールを単一の効率的な操作に統合します。
構文
Task({
subagent_type: "Explore",
model: "haiku",
prompt: `
Explore [target] (thoroughness: [level]).
[Specific goals]
`
})
徹底度レベル
| レベル | 時間 | ユースケース |
|---|---|---|
quick | 10-30秒 | 特定のファイルや関数を検索 |
medium | 30-60秒 | モジュール構造とパターンをマッピング |
very thorough | 60-120秒 | 完全なフロー分析 |
例
クイック検索:
Task({
subagent_type: "Explore",
model: "haiku",
prompt: "Explore authentication (thoroughness: quick). Find the login handler."
})
中程度の探索:
Task({
subagent_type: "Explore",
model: "haiku",
prompt: `
Explore payment module (thoroughness: medium).
Find all Stripe integration points and webhook handlers.
`
})
徹底的な分析:
Task({
subagent_type: "Explore",
model: "haiku",
prompt: `
Explore user authentication (thoroughness: very thorough).
Map complete auth flow from login to session management.
Include JWT handling, refresh tokens, and logout.
`
})
なぜExploreが速いのか
従来のアプローチ(5つの手動ステップ):
Agent 1: Glob find *auth*.ts → 15s
Agent 2: Grep search "JWT" → 15s
Agent 3: Read auth/index.ts → 10s
Agent 4: Grep find middleware → 15s
Agent 5: Read test files → 10s
Total: 65 seconds
新しいアプローチ(1つのExplore agent):
Task({
subagent_type: "Explore",
model: "haiku",
prompt: "Explore auth (thoroughness: medium). Map JWT, middleware, tests."
})
// Total: 30-45 seconds
general-purpose Agent
概要
general-purpose agentは、より深い推論が必要な複雑なマルチステップタスクを処理します。バランスの取れたパフォーマンスのため、デフォルトでSonnet 4.5を使用します。
構文
Task({
subagent_type: "general-purpose",
model: "sonnet", // or "opus" for critical tasks
prompt: "Your complex task description"
})
例
実装:
Task({
subagent_type: "general-purpose",
model: "sonnet",
prompt: `
Implement user profile editing feature.
- Add API endpoint for profile updates
- Create form component with validation
- Include image upload support
- Follow existing patterns in src/api/
`
})
分析:
Task({
subagent_type: "general-purpose",
model: "sonnet",
prompt: `
Analyze the current state management architecture.
- Identify patterns and anti-patterns
- Assess scalability
- Recommend improvements
`
})
リファクタリング:
Task({
subagent_type: "general-purpose",
model: "sonnet",
prompt: `
Refactor the order processing module.
- Extract shared logic to utilities
- Improve error handling
- Maintain backward compatibility
`
})
code-reviewer Agent
概要
code-reviewer agentは、コード品質分析、パターン検出、ベストプラクティスの強制に特化しています。
構文
Task({
subagent_type: "code-reviewer",
model: "sonnet",
prompt: "Review [target] for [aspects]"
})
例
PRレビュー:
Task({
subagent_type: "code-reviewer",
model: "sonnet",
prompt: `
Review changes in the authentication module.
Check for:
- Code quality and patterns
- Error handling
- Test coverage
- Documentation
Provide findings with severity levels.
`
})
パターンチェック:
Task({
subagent_type: "code-reviewer",
model: "sonnet",
prompt: `
Review src/components/ for React best practices.
Check:
- Proper hook usage
- Component structure
- Prop validation
- Performance optimizations
`
})
security-auditor Agent
概要
security-auditor agentは、脆弱性検出とセキュリティベストプラクティスに特化しています。認証、決済、データ処理コードに不可欠です。
構文
Task({
subagent_type: "security-auditor",
model: "sonnet", // or "opus" for critical code
prompt: "Audit [target] for security vulnerabilities"
})
例
認証監査:
Task({
subagent_type: "security-auditor",
model: "sonnet",
prompt: `
Audit the authentication module.
Check for OWASP Top 10:
- Injection vulnerabilities
- Broken authentication
- Sensitive data exposure
- Broken access control
Report findings with severity.
`
})
決済セキュリティ:
Task({
subagent_type: "security-auditor",
model: "opus", // Critical code deserves best model
prompt: `
Comprehensive security audit of payment processing.
Check:
- PCI DSS compliance
- Data encryption
- Token handling
- Webhook security
- Error message safety
`
})
security-auditorを使用するタイミング
| シナリオ | 優先度 |
|---|---|
| 認証/ログイン変更 | 高 |
| 決済コード | 最重要 |
| ユーザーデータ処理 | 高 |
| APIエンドポイント | 中 |
| ファイルアップロード | 高 |
| 外部連携 | 中 |
test-runner Agent
概要
test-runner agentは、テスト実行、カバレッジ分析、テスト結果の解釈を担当します。
構文
Task({
subagent_type: "test-runner",
model: "haiku",
prompt: "Run tests for [target] and analyze results"
})
例
テスト実行:
Task({
subagent_type: "test-runner",
model: "haiku",
prompt: `
Run all tests related to user authentication.
Report:
- Pass/fail status
- Coverage percentage
- Failed test details
`
})
カバレッジ分析:
Task({
subagent_type: "test-runner",
model: "haiku",
prompt: `
Analyze test coverage for the checkout module.
Identify:
- Uncovered code paths
- Edge cases missing tests
- Integration test gaps
`
})
debugger Agent
概要
debugger agentは、根本原因分析と体系的なバグ調査に特化しています。
構文
Task({
subagent_type: "debugger",
model: "sonnet",
prompt: "Investigate [error/issue] and find root cause"
})
例
エラー調査:
Task({
subagent_type: "debugger",
model: "sonnet",
prompt: `
Investigate: TypeError: Cannot read 'id' of undefined
at CheckoutForm.handleSubmit (checkout.tsx:45)
Context: Error occurs when submitting with empty cart.
Find root cause and suggest fix.
`
})
パフォーマンス問題:
Task({
subagent_type: "debugger",
model: "sonnet",
prompt: `
Debug slow dashboard load (8s, should be <2s).
Investigate:
- Data fetching patterns
- Render cycles
- Database queries
- Network waterfall
`
})
refactor-assistant Agent
概要
refactor-assistant agentは、機能を変更せずにコードの再構築、クリーンアップ、改善を支援します。
構文
Task({
subagent_type: "refactor-assistant",
model: "sonnet",
prompt: "Refactor [target] to improve [aspect]"
})
例
コードクリーンアップ:
Task({
subagent_type: "refactor-assistant",
model: "sonnet",
prompt: `
Refactor utils/helpers.ts:
- Split into focused modules
- Remove dead code
- Improve naming
- Add TypeScript types
`
})
パターン抽出:
Task({
subagent_type: "refactor-assistant",
model: "sonnet",
prompt: `
Extract common patterns from API handlers.
Create:
- Shared error handling middleware
- Response helpers
- Validation utilities
`
})
doc-writer Agent
概要
doc-writer agentは、ドキュメントの作成と更新に特化しています。
構文
Task({
subagent_type: "doc-writer",
model: "sonnet", // or "haiku" for simple docs
prompt: "Document [target]"
})
例
APIドキュメント:
Task({
subagent_type: "doc-writer",
model: "sonnet",
prompt: `
Document the user API endpoints.
Include:
- Endpoint descriptions
- Request/response formats
- Authentication requirements
- Error codes
- Examples
`
})
README更新:
Task({
subagent_type: "doc-writer",
model: "haiku",
prompt: `
Update README.md with:
- New authentication flow
- Environment variables
- Setup instructions
`
})
並列エージェントパターン
パターン1:分析スウォーム
包括的な分析のために複数のExplore agentを起動:
// 5 parallel Explore agents
Task({ subagent_type: "Explore", model: "haiku",
prompt: "Map auth file structure (thoroughness: quick)" })
Task({ subagent_type: "Explore", model: "haiku",
prompt: "Find JWT patterns (thoroughness: quick)" })
Task({ subagent_type: "Explore", model: "haiku",
prompt: "Analyze middleware (thoroughness: medium)" })
Task({ subagent_type: "Explore", model: "haiku",
prompt: "Check auth tests (thoroughness: quick)" })
Task({ subagent_type: "Explore", model: "haiku",
prompt: "Review recent changes (thoroughness: quick)" })
パターン2:実装とレビューの同時実行
構築と検証を同時に行う:
// Phase 1: Implementation
Task({
subagent_type: "general-purpose",
model: "sonnet",
prompt: "Implement user profile feature"
})
// Phase 2: Parallel review (after Phase 1)
Task({ subagent_type: "code-reviewer", model: "sonnet",
prompt: "Review code quality" })
Task({ subagent_type: "security-auditor", model: "sonnet",
prompt: "Security review" })
Task({ subagent_type: "test-runner", model: "haiku",
prompt: "Run and analyze tests" })
パターン3:マルチファイルリファクタリング
並列エージェント間で作業を分割:
// Each agent handles one file
Task({ subagent_type: "general-purpose", model: "sonnet",
prompt: "Refactor payment/checkout.ts to new pattern" })
Task({ subagent_type: "general-purpose", model: "sonnet",
prompt: "Refactor payment/subscription.ts to new pattern" })
Task({ subagent_type: "general-purpose", model: "sonnet",
prompt: "Refactor payment/refund.ts to new pattern" })
Task({ subagent_type: "general-purpose", model: "sonnet",
prompt: "Update payment/types.ts for new pattern" })
Task({ subagent_type: "test-runner", model: "haiku",
prompt: "Update payment tests for new pattern" })
パターン4:バグ調査
並列仮説テスト:
// Investigate multiple theories simultaneously
Task({ subagent_type: "Explore", model: "haiku",
prompt: "Search for session handling changes (thoroughness: quick)" })
Task({ subagent_type: "Explore", model: "haiku",
prompt: "Check for race conditions (thoroughness: medium)" })
Task({ subagent_type: "Explore", model: "haiku",
prompt: "Review error logs (thoroughness: quick)" })
Task({ subagent_type: "Explore", model: "haiku",
prompt: "Find timeout configurations (thoroughness: quick)" })
Task({ subagent_type: "debugger", model: "sonnet",
prompt: "Analyze most likely root cause from exploration" })
モデル選択ガイド
| タスクタイプ | モデル | コスト | 速度 |
|---|---|---|---|
| クイック検索 | Haiku 4.5 | $ | ⚡⚡⚡ |
| パターンマッチング | Haiku 4.5 | $ | ⚡⚡⚡ |
| テスト実行 | Haiku 4.5 | $ | ⚡⚡⚡ |
| シンプルなドキュメント | Haiku 4.5 | $ | ⚡⚡⚡ |
| コードレビュー | Sonnet 4.5 | $$ | ⚡⚡ |
| 実装 | Sonnet 4.5 | $$ | ⚡⚡ |
| デバッグ | Sonnet 4.5 | $$ | ⚡⚡ |
| セキュリティ監査 | Sonnet/Opus | $$-$$$ | ⚡-⚡⚡ |
| アーキテクチャ | Opus 4.5 | $$$ | ⚡ |
コスト/速度のトレードオフ:
- Haiku 4.5: Sonnetと比較して2倍速く、1/3のコスト
- Sonnet 4.5: 最高のコーディングパフォーマンス
- Opus 4.5: 最高の知性、デフォルトでThinking Mode有効
バックグラウンドエージェント
長時間実行タスクには run_in_background を使用:
Task({
subagent_type: "security-auditor",
model: "opus",
prompt: "Comprehensive security audit of entire codebase",
run_in_background: true
})
バックグラウンドタスクの確認:
TaskOutput({ task_id: "...", block: false })
ベストプラクティス
1. 適切なエージェントを選択
File search → Explore (haiku)
Implementation → general-purpose (sonnet)
Code quality → code-reviewer (sonnet)
Security → security-auditor (sonnet/opus)
Testing → test-runner (haiku)
Bugs → debugger (sonnet)
Cleanup → refactor-assistant (sonnet)
Docs → doc-writer (haiku/sonnet)
2. プロンプトを焦点化
範囲が広すぎる:
"Analyze everything about the codebase"
焦点化:
"Explore authentication module (thoroughness: medium). Find JWT handling and session management."
3. コンテキストを提供
Task({
subagent_type: "general-purpose",
model: "sonnet",
prompt: `
Context: Migrating from REST to GraphQL.
Pattern: Use new ApiClient from src/lib/api.ts
Task: Refactor user service to use GraphQL.
`
})
4. 可能な限り並列処理
独立したタスクは同時に実行すべき:
// These are independent - run in parallel
Task({ ..., prompt: "Analyze file A" })
Task({ ..., prompt: "Analyze file B" })
Task({ ..., prompt: "Analyze file C" })
5. 依存タスクをチェーン化
順次タスクはフェーズ化すべき:
Phase 1: Explore (gather context)
Phase 2: Implement (with context from Phase 1)
Phase 3: Review (verify Phase 2)
はじめに
今日:
thoroughness: mediumで1つのExplore agentを試す- 最近の変更にcode-reviewerを使用
- 次の実装後にtest-runnerを実行
今週:
- 分析スウォームパターンを実装
- 機密コードにsecurity-auditorを使用
- レビュー付き並列実装を試す
今月:
- ワークフロー用のエージェント組み合わせを開発
- コスト/パフォーマンスのモデル選択を最適化
- 一般的なパターン用のテンプレートを作成
Claude Code agentsは、順次プロンプトから並列オーケストレーションへと作業方法を変革します。マスターすることで5-10倍の効率向上を実現できます。
出典: Claude Code Documentation, Claude Code GitHub, CHANGELOG