Subagents enable delegation of complex tasks to specialized agents that operate autonomously without user interaction, returning their final output to the main conversation.
Project-level subagents override user-level when names conflict.
| Category |
Color |
Use For |
| Code Generation |
blue |
Agents that write/generate code (coder, writer, generator) |
| Testing & Verification |
green |
Agents that test or verify (tester, verifier, validator) |
| Debugging |
red |
Agents that diagnose/fix problems (debugger, fix) |
| Planning & Analysis |
purple |
Agents that plan/analyze (planner, analyzer, orchestrator, model-*) |
| Infrastructure & Ops |
orange |
Agents for env, platform, release (env, platform, release) |
| Data & Persistence |
cyan |
Agents for data layer (data, query, persist) |
| Research & Interactive |
magenta |
Agents for research, sessions (research, session, api) |
| Architecture & Docs |
yellow |
Agents for architecture (architect, adr, component) |
| Helper & Utility |
(none) |
Background support agents (do-*, helper) |
Full documentation: See docs/agent-colors.md for complete classification guide.
Subagents run in isolated contexts and return their final output to the main conversation. They:
- ✅ Can use tools like Read, Write, Edit, Bash, Grep, Glob
- ✅ Can access MCP servers and other non-interactive tools
- ❌ Cannot use AskUserQuestion or any tool requiring user interaction
- ❌ Cannot present options or wait for user input
- ❌ User never sees subagent's intermediate steps
The main conversation sees only the subagent's final report/output.
Use main chat for:
- Gathering requirements from user (AskUserQuestion)
- Presenting options or decisions to user
- Any task requiring user confirmation/input
- Work where user needs visibility into progress
Use subagents for:
- Research tasks (API documentation lookup, code analysis)
- Code generation based on pre-defined requirements
- Analysis and reporting (security review, test coverage)
- Context-heavy operations that don't need user interaction
Example workflow pattern:
Main Chat: Ask user for requirements (AskUserQuestion)
↓
Subagent: Research API and create documentation (no user interaction)
↓
Main Chat: Review research with user, confirm approach
↓
Subagent: Generate code based on confirmed plan
↓
Main Chat: Present results, handle testing/deployment
---
name: security-reviewer
description: Reviews code for security vulnerabilities
tools: Read, Grep, Glob, Bash
model: sonnet
---
<role>
You are a senior code reviewer specializing in security.
</role>
<focus_areas>
- SQL injection vulnerabilities
- XSS attack vectors
- Authentication/authorization issues
- Sensitive data exposure
</focus_areas>
<workflow>
1. Read the modified files
2. Identify security risks
3. Provide specific remediation steps
4. Rate severity (Critical/High/Medium/Low)
</workflow>
❌ Bad: "You are a helpful assistant that helps with code"
✅ Good: "You are a React component refactoring specialist. Analyze components for hooks best practices, performance anti-patterns, and accessibility issues."
<role> - Who the subagent is and what it does
<constraints> - Hard rules (NEVER/MUST/ALWAYS)
<focus_areas> - What to prioritize
<workflow> - Step-by-step process
<output_format> - How to structure deliverables
<success_criteria> - Completion criteria
<validation> - How to verify work
Medium subagents (multi-step process):
- Add workflow steps, output_format, success_criteria
- Example: api-researcher, documentation-generator
Complex subagents (research + generation + validation):
- Add all tags as appropriate including validation, examples
- Example: mcp-api-researcher, comprehensive-auditor
Keep markdown formatting WITHIN content (bold, italic, lists, code blocks, links).
For XML structure principles and token efficiency details, see @skills/skill-builder/references/use-xml-tags.md - the same principles apply to subagents.
> Use the code-reviewer subagent to check my recent changes
> Have the test-writer subagent create tests for the new API endpoints
Subagent usage and configuration: references/subagents.md
- File format and configuration
- Model selection (Sonnet 4.5 + Haiku 4.5 orchestration)
- Tool security and least privilege
- Prompt caching optimization
- Complete examples
Writing effective prompts: references/writing-subagent-prompts.md
- Core principles and XML structure
- Description field optimization for routing
- Extended thinking for complex reasoning
- Security constraints and strong modal verbs
- Success criteria definition
Advanced topics:
Evaluation and testing: references/evaluation-and-testing.md
- Evaluation metrics (task completion, tool correctness, robustness)
- Testing strategies (offline, simulation, online monitoring)
- Evaluation-driven development
- G-Eval for custom criteria
Error handling and recovery: references/error-handling-and-recovery.md
- Common failure modes and causes
- Recovery strategies (graceful degradation, retry, circuit breakers)
- Structured communication and observability
- Anti-patterns to avoid
Context management: references/context-management.md
- Memory architecture (STM, LTM, working memory)
- Context strategies (summarization, sliding window, scratchpads)
- Managing long-running tasks
- Prompt caching interaction
Orchestration patterns: references/orchestration-patterns.md
- Sequential, parallel, hierarchical, coordinator patterns
- Sonnet + Haiku orchestration for cost/performance
- Multi-agent coordination
- Pattern selection guidance
Debugging and troubleshooting: references/debugging-agents.md
- Logging, tracing, and correlation IDs
- Common failure types (hallucinations, format errors, tool misuse)
- Diagnostic procedures
- Continuous monitoring
- Valid YAML frontmatter (name matches file, description includes triggers)
- Clear role definition in system prompt
- Appropriate tool restrictions (least privilege)
- XML-structured system prompt with role, approach, and constraints
- Description field optimized for automatic routing
- Successfully tested on representative tasks
- Model selection appropriate for task complexity (Sonnet for reasoning, Haiku for simple tasks)
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: create-subagents-23description: Expert guidance for creating, building, and using Claude Code subagents and the Task tool. Use when working with subagents, setting up agent configurations, understanding how agents work, or using the Task tool to launch specialized agents. Use when this capability is needed.4---56<objective>7Subagents are specialized Claude instances that run in isolated contexts with focused roles and limited tool access. This skill teaches you how to create effective subagents, write strong system prompts, configure tool access, and orchestrate multi-agent workflows using the Task tool.89Subagents enable delegation of complex tasks to specialized agents that operate autonomously without user interaction, returning their final output to the main conversation.10</objective>1112<quick_start>13<workflow>141. Run `/agents` command152. Select "Create New Agent"163. Choose project-level (`agents/`) or user-level (`~/agents/`)174. Define the subagent:18 - **name**: lowercase-with-hyphens19 - **description**: When should this subagent be used?20 - **tools**: Optional comma-separated list (inherits all if omitted)21 - **model**: Optional (`sonnet`, `opus`, `haiku`, or `inherit`)225. Write the system prompt (the subagent's instructions)23 </workflow>2425<example>26```markdown27---28name: code-reviewer29description: Expert code reviewer. Use proactively after code changes to review for quality, security, and best practices.30tools: Read, Grep, Glob, Bash31model: sonnet32color: green33---3435<role>36You are a senior code reviewer focused on quality, security, and best practices.37</role>3839<focus_areas>40- Code quality and maintainability41- Security vulnerabilities42- Performance issues43- Best practices adherence44 </focus_areas>4546<output_format>47Provide specific, actionable feedback with file:line references.48</output_format>49```50</example>51</quick_start>5253<file_structure>54| Type | Location | Scope | Priority |55|------|----------|-------|----------|56| **Project** | `agents/` | Current project only | Highest |57| **User** | `~/agents/` | All projects | Lower |58| **Plugin** | Plugin's `agents/` dir | All projects | Lowest |5960Project-level subagents override user-level when names conflict.61</file_structure>6263<configuration>64<field name="name">65- Lowercase letters and hyphens only66- Must be unique67</field>6869<field name="description">70- Natural language description of purpose71- Include when Claude should invoke this subagent72- Used for automatic subagent selection73</field>7475<field name="tools">76- Comma-separated list: `Read, Write, Edit, Bash, Grep`77- If omitted: inherits all tools from main thread78- Use `/agents` interface to see all available tools79</field>8081<field name="model">82- `sonnet`, `opus`, `haiku`, or `inherit`83- `inherit`: uses same model as main conversation84- If omitted: defaults to configured subagent model (usually sonnet)85</field>8687<field name="color">88- Visual distinction in terminal output89- Supported colors: `red`, `blue`, `green`, `yellow`, `purple`, `orange`, `cyan`, `magenta`90- Assign based on agent category (see color classification below)91- If omitted: no colored badge displayed92</field>9394<color_classification>95Use consistent colors based on agent function:9697| Category | Color | Use For |98|----------|-------|---------|99| Code Generation | `blue` | Agents that write/generate code (coder, writer, generator) |100| Testing & Verification | `green` | Agents that test or verify (tester, verifier, validator) |101| Debugging | `red` | Agents that diagnose/fix problems (debugger, fix) |102| Planning & Analysis | `purple` | Agents that plan/analyze (planner, analyzer, orchestrator, model-*) |103| Infrastructure & Ops | `orange` | Agents for env, platform, release (env, platform, release) |104| Data & Persistence | `cyan` | Agents for data layer (data, query, persist) |105| Research & Interactive | `magenta` | Agents for research, sessions (research, session, api) |106| Architecture & Docs | `yellow` | Agents for architecture (architect, adr, component) |107| Helper & Utility | (none) | Background support agents (do-*, helper) |108109**Full documentation**: See `docs/agent-colors.md` for complete classification guide.110</color_classification>111</configuration>112113<execution_model>114<critical_constraint>115**Subagents are black boxes that cannot interact with users.**116117Subagents run in isolated contexts and return their final output to the main conversation. They:118- ✅ Can use tools like Read, Write, Edit, Bash, Grep, Glob119- ✅ Can access MCP servers and other non-interactive tools120- ❌ **Cannot use AskUserQuestion** or any tool requiring user interaction121- ❌ **Cannot present options or wait for user input**122- ❌ **User never sees subagent's intermediate steps**123124The main conversation sees only the subagent's final report/output.125</critical_constraint>126127<workflow_design>128**Designing workflows with subagents:**129130Use **main chat** for:131- Gathering requirements from user (AskUserQuestion)132- Presenting options or decisions to user133- Any task requiring user confirmation/input134- Work where user needs visibility into progress135136Use **subagents** for:137- Research tasks (API documentation lookup, code analysis)138- Code generation based on pre-defined requirements139- Analysis and reporting (security review, test coverage)140- Context-heavy operations that don't need user interaction141142**Example workflow pattern:**143```144Main Chat: Ask user for requirements (AskUserQuestion)145↓146Subagent: Research API and create documentation (no user interaction)147↓148Main Chat: Review research with user, confirm approach149↓150Subagent: Generate code based on confirmed plan151↓152Main Chat: Present results, handle testing/deployment153```154</workflow_design>155</execution_model>156157<system_prompt_guidelines>158<principle name="be_specific">159Clearly define the subagent's role, capabilities, and constraints.160</principle>161162<principle name="use_pure_xml_structure">163Structure the system prompt with pure XML tags. Remove ALL markdown headings from the body.164165```markdown166---167name: security-reviewer168description: Reviews code for security vulnerabilities169tools: Read, Grep, Glob, Bash170model: sonnet171---172173<role>174You are a senior code reviewer specializing in security.175</role>176177<focus_areas>178- SQL injection vulnerabilities179- XSS attack vectors180- Authentication/authorization issues181- Sensitive data exposure182</focus_areas>183184<workflow>1851. Read the modified files1862. Identify security risks1873. Provide specific remediation steps1884. Rate severity (Critical/High/Medium/Low)189</workflow>190```191</principle>192193<principle name="task_specific">194Tailor instructions to the specific task domain. Don't create generic "helper" subagents.195196❌ Bad: "You are a helpful assistant that helps with code"197✅ Good: "You are a React component refactoring specialist. Analyze components for hooks best practices, performance anti-patterns, and accessibility issues."198</principle>199</system_prompt_guidelines>200201<subagent_xml_structure>202Subagent.md files are system prompts consumed only by Claude. Like skills and slash commands, they should use pure XML structure for optimal parsing and token efficiency.203204<recommended_tags>205Common tags for subagent structure:206207- `<role>` - Who the subagent is and what it does208- `<constraints>` - Hard rules (NEVER/MUST/ALWAYS)209- `<focus_areas>` - What to prioritize210- `<workflow>` - Step-by-step process211- `<output_format>` - How to structure deliverables212- `<success_criteria>` - Completion criteria213- `<validation>` - How to verify work214 </recommended_tags>215216<intelligence_rules>217**Simple subagents** (single focused task):218- Use role + constraints + workflow minimum219- Example: code-reviewer, test-runner220221**Medium subagents** (multi-step process):222- Add workflow steps, output_format, success_criteria223- Example: api-researcher, documentation-generator224225**Complex subagents** (research + generation + validation):226- Add all tags as appropriate including validation, examples227- Example: mcp-api-researcher, comprehensive-auditor228 </intelligence_rules>229230<critical_rule>231**Remove ALL markdown headings (##, ###) from subagent body.** Use semantic XML tags instead.232233Keep markdown formatting WITHIN content (bold, italic, lists, code blocks, links).234235For XML structure principles and token efficiency details, see @skills/skill-builder/references/use-xml-tags.md - the same principles apply to subagents.236</critical_rule>237</subagent_xml_structure>238239<invocation>240<automatic>241Claude automatically selects subagents based on the `description` field when it matches the current task.242</automatic>243244<explicit>245You can explicitly invoke a subagent:246247```248> Use the code-reviewer subagent to check my recent changes249```250251```252> Have the test-writer subagent create tests for the new API endpoints253```254</explicit>255</invocation>256257<management>258<using_agents_command>259Run `/agents` for an interactive interface to:260- View all available subagents261- Create new subagents262- Edit existing subagents263- Delete custom subagents264</using_agents_command>265266<manual_editing>267You can also edit subagent files directly:268- Project: `agents/subagent-name.md`269- User: `~/agents/subagent-name.md`270 </manual_editing>271 </management>272273<reference>274**Core references**:275276**Subagent usage and configuration**: [references/subagents.md](references/subagents.md)277- File format and configuration278- Model selection (Sonnet 4.5 + Haiku 4.5 orchestration)279- Tool security and least privilege280- Prompt caching optimization281- Complete examples282283**Writing effective prompts**: [references/writing-subagent-prompts.md](references/writing-subagent-prompts.md)284- Core principles and XML structure285- Description field optimization for routing286- Extended thinking for complex reasoning287- Security constraints and strong modal verbs288- Success criteria definition289290**Advanced topics**:291292**Evaluation and testing**: [references/evaluation-and-testing.md](references/evaluation-and-testing.md)293- Evaluation metrics (task completion, tool correctness, robustness)294- Testing strategies (offline, simulation, online monitoring)295- Evaluation-driven development296- G-Eval for custom criteria297298**Error handling and recovery**: [references/error-handling-and-recovery.md](references/error-handling-and-recovery.md)299- Common failure modes and causes300- Recovery strategies (graceful degradation, retry, circuit breakers)301- Structured communication and observability302- Anti-patterns to avoid303304**Context management**: [references/context-management.md](references/context-management.md)305- Memory architecture (STM, LTM, working memory)306- Context strategies (summarization, sliding window, scratchpads)307- Managing long-running tasks308- Prompt caching interaction309310**Orchestration patterns**: [references/orchestration-patterns.md](references/orchestration-patterns.md)311- Sequential, parallel, hierarchical, coordinator patterns312- Sonnet + Haiku orchestration for cost/performance313- Multi-agent coordination314- Pattern selection guidance315316**Debugging and troubleshooting**: [references/debugging-agents.md](references/debugging-agents.md)317- Logging, tracing, and correlation IDs318- Common failure types (hallucinations, format errors, tool misuse)319- Diagnostic procedures320- Continuous monitoring321 </reference>322323<success_criteria>324A well-configured subagent has:325326- Valid YAML frontmatter (name matches file, description includes triggers)327- Clear role definition in system prompt328- Appropriate tool restrictions (least privilege)329- XML-structured system prompt with role, approach, and constraints330- Description field optimized for automatic routing331- Successfully tested on representative tasks332- Model selection appropriate for task complexity (Sonnet for reasoning, Haiku for simple tasks)333 </success_criteria>334335---336> Converted and distributed by [TomeVault](https://tomevault.io/claim/rayk) — claim your Tome and manage your conversions.337<!-- tomevault:4.0:skill_md:2026-04-13 -->