数万ファイルのリポジトリを Claude Code に調査させると、すぐにコンテキストが枯渇する。Sub-agents は別コンテキストで探索を走らせ、結果サマリだけを返すため、メイン会話を汚さずに調査を分離できる。本稿は公式ドキュメント準拠で活用パターンと注意点を整理する。
なぜサブエージェントが効くか
Claude Code の本質的な制約は「コンテキストウィンドウは有限で、埋まるほど性能が落ちる」こと。コードベース探索で何十ファイルも読むと、本来やりたい実装の前にコンテキストが枯渇する。
Sub-agents は別のコンテキストで動き、要約だけを返す。公式ドキュメントは "subagents are one of the most powerful tools available" と明記している。
使い方の基本
use subagents to investigate how our authentication system handles token
refresh, and whether we have any existing OAuth utilities I should reuse.メイン会話には数行のサマリだけが返ってくる。読んだファイルの中身はメイン側に蓄積しない。
カスタムサブエージェントを `.claude/agents/` に置く
```markdown --- name: security-reviewer description: Reviews code for security vulnerabilities tools: Read, Grep, Glob, Bash model: opus --- You are a senior security engineer. Review code for: - Injection vulnerabilities (SQL, XSS, command injection) - Authentication and authorization flaws - Secrets or credentials in code - Insecure data handling
無料でアカウント作成
CCHub は Claude Code 開発者のための日本語コミュニティです。