Guide for designing and creating effective Claude Code custom agents (subagents). Use when users want to create, update, or optimize agents defined in .claude/agents/. Triggers on requests like "make an agent", "create a subagent", "build a reviewer agent", "add a custom agent", or "define an agent for code review".
Create well-designed Claude Code custom agents by following a structured process: define the role, select the right architecture, configure frontmatter, write an effective system prompt, and create the agent file.
Ask the user:
| Pattern | When to Use | Example |
|---|
| Standalone | User invokes directly via Task tool | "Security reviewer I run on demand" |
| Subagent | Parent agent auto-delegates based on description | "Explorer spawned for codebase search" |
| Team member | Coordinates with peers via shared task list (agent teams) | "Frontend dev alongside backend dev" |
Use a single agent when: the task is sequential, context must persist across steps, or the change is small.
Use subagents when: you want tool/permission isolation, the work is verbose, or parallel research is needed.
Use agent teams when: peers must communicate directly, work decomposes into file-disjoint units, or competing hypotheses benefit from parallel investigation.
See references/claude-code-agents.md for the complete frontmatter field reference with examples.
The description field determines when the parent agent delegates to this agent. Write it comprehensively:
See references/claude-code-agents.md > "Writing Effective Descriptions" for Bad/Good examples.
Each agent should have one clear job. As instruction complexity increases, adherence degrades.
| Role | tools | model | Use Case |
|---|---|---|---|
| Explorer/Researcher | Read, Glob, Grep | haiku | Codebase search, doc lookup |
| Implementer | Read, Edit, Write, Bash | inherit | Writing code, making changes |
| Reviewer/Critic | Read, Glob, Grep, Bash | sonnet or opus | Code review, security audit |
| Planner/Architect | Read, Glob, Grep | opus | Design decisions, decomposition |
| Tester | Read, Bash, Glob, Grep | inherit | Running tests, writing tests |
| Debugger | Read, Edit, Bash, Grep, Glob | inherit | Diagnosing and fixing issues |
Apply the principle of least privilege:
tools fielddisallowedTools when inheriting all toolsTask(worker, researcher) limits which agents can be launcheduser, project, or localSee references/design-patterns.md for detailed patterns, examples, and anti-patterns.
Structure the prompt body (after frontmatter) in this order:
1. Identity and role (1-2 sentences)
2. When invoked / trigger conditions
3. Step-by-step workflow (numbered)
4. Constraints and guardrails
5. Output format expectations
Key principles:
Create the agent file at .claude/agents/<agent-name>.md using the frontmatter designed in Step 3 and the system prompt from Step 4. See references/claude-code-agents.md for full annotated examples to use as a starting point.
Then:
After two failed prompt corrections, restructure the architecture (split into multiple agents or change the workflow) rather than adding more prompt patches.
Code Reviewer