Instructions without markers apply to all agents.
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.
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/create-agent-skills/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)
1---2name: kitt-create-subagents3description: Expert guidance for creating, building, and using 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.4---56<agent_identification>7**Before proceeding, identify which agent you are:**8- **I am Claude Code** → Follow [CLAUDE] instructions9- **I am GitHub Copilot** → Follow [COPILOT] instructions10- **I am Gemini CLI** → No native agent support1112Instructions without markers apply to all agents.13</agent_identification>1415<cli_paths>16| Resource | [CLAUDE] | [COPILOT] |17|----------|----------|-----------|18| Agents | `~/.claude/agents/` | `~/.copilot/agents/` |19</cli_paths>2021<objective>22Subagents are specialized agent 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.2324Subagents enable delegation of complex tasks to specialized agents that operate autonomously without user interaction, returning their final output to the main conversation.25</objective>2627<quick_start>28<workflow>291. Run `/agents` command302. Select "Create New Agent"313. Choose project-level (`.claude/agents/`) or user-level (`~/.claude/agents/`)324. Define the subagent:33 - **name**: lowercase-with-hyphens34 - **description**: When should this subagent be used?35 - **tools**: Optional comma-separated list (inherits all if omitted)36 - **model**: Optional (`sonnet`, `opus`, `haiku`, or `inherit`)375. Write the system prompt (the subagent's instructions)38</workflow>3940<example>41```markdown42---43name: code-reviewer44description: Expert code reviewer. Use proactively after code changes to review for quality, security, and best practices.45tools: Read, Grep, Glob, Bash46model: sonnet47---4849<role>50You are a senior code reviewer focused on quality, security, and best practices.51</role>5253<focus_areas>54- Code quality and maintainability55- Security vulnerabilities56- Performance issues57- Best practices adherence58</focus_areas>5960<output_format>61Provide specific, actionable feedback with file:line references.62</output_format>63```64</example>65</quick_start>6667<file_structure>68| Type | Location | Scope | Priority |69|------|----------|-------|----------|70| **Project** | `.claude/agents/` | Current project only | Highest |71| **User** | `~/.claude/agents/` | All projects | Lower |72| **Plugin** | Plugin's `agents/` dir | All projects | Lowest |7374Project-level subagents override user-level when names conflict.75</file_structure>7677<configuration>78<field name="name">79- Lowercase letters and hyphens only80- Must be unique81</field>8283<field name="description">84- Natural language description of purpose85- Include when the agent should invoke this subagent86- Used for automatic subagent selection87</field>8889<field name="tools">90- Comma-separated list: `Read, Write, Edit, Bash, Grep`91- If omitted: inherits all tools from main thread92- Use `/agents` interface to see all available tools93</field>9495<field name="model">96- `sonnet`, `opus`, `haiku`, or `inherit`97- `inherit`: uses same model as main conversation98- If omitted: defaults to configured subagent model (usually sonnet)99</field>100</configuration>101102<execution_model>103<critical_constraint>104**Subagents are black boxes that cannot interact with users.**105106Subagents run in isolated contexts and return their final output to the main conversation. They:107- ✅ Can use tools like Read, Write, Edit, Bash, Grep, Glob108- ✅ Can access MCP servers and other non-interactive tools109- ❌ **Cannot use AskUserQuestion** or any tool requiring user interaction110- ❌ **Cannot present options or wait for user input**111- ❌ **User never sees subagent's intermediate steps**112113The main conversation sees only the subagent's final report/output.114</critical_constraint>115116<workflow_design>117**Designing workflows with subagents:**118119Use **main chat** for:120- Gathering requirements from user (AskUserQuestion)121- Presenting options or decisions to user122- Any task requiring user confirmation/input123- Work where user needs visibility into progress124125Use **subagents** for:126- Research tasks (API documentation lookup, code analysis)127- Code generation based on pre-defined requirements128- Analysis and reporting (security review, test coverage)129- Context-heavy operations that don't need user interaction130131**Example workflow pattern:**132```133Main Chat: Ask user for requirements (AskUserQuestion)134 ↓135Subagent: Research API and create documentation (no user interaction)136 ↓137Main Chat: Review research with user, confirm approach138 ↓139Subagent: Generate code based on confirmed plan140 ↓141Main Chat: Present results, handle testing/deployment142```143</workflow_design>144</execution_model>145146<system_prompt_guidelines>147<principle name="be_specific">148Clearly define the subagent's role, capabilities, and constraints.149</principle>150151<principle name="use_pure_xml_structure">152Structure the system prompt with pure XML tags. Remove ALL markdown headings from the body.153154```markdown155---156name: security-reviewer157description: Reviews code for security vulnerabilities158tools: Read, Grep, Glob, Bash159model: sonnet160---161162<role>163You are a senior code reviewer specializing in security.164</role>165166<focus_areas>167- SQL injection vulnerabilities168- XSS attack vectors169- Authentication/authorization issues170- Sensitive data exposure171</focus_areas>172173<workflow>1741. Read the modified files1752. Identify security risks1763. Provide specific remediation steps1774. Rate severity (Critical/High/Medium/Low)178</workflow>179```180</principle>181182<principle name="task_specific">183Tailor instructions to the specific task domain. Don't create generic "helper" subagents.184185❌ Bad: "You are a helpful assistant that helps with code"186✅ Good: "You are a React component refactoring specialist. Analyze components for hooks best practices, performance anti-patterns, and accessibility issues."187</principle>188</system_prompt_guidelines>189190<subagent_xml_structure>191Subagent.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.192193<recommended_tags>194Common tags for subagent structure:195196- `<role>` - Who the subagent is and what it does197- `<constraints>` - Hard rules (NEVER/MUST/ALWAYS)198- `<focus_areas>` - What to prioritize199- `<workflow>` - Step-by-step process200- `<output_format>` - How to structure deliverables201- `<success_criteria>` - Completion criteria202- `<validation>` - How to verify work203</recommended_tags>204205<intelligence_rules>206**Simple subagents** (single focused task):207- Use role + constraints + workflow minimum208- Example: code-reviewer, test-runner209210**Medium subagents** (multi-step process):211- Add workflow steps, output_format, success_criteria212- Example: api-researcher, documentation-generator213214**Complex subagents** (research + generation + validation):215- Add all tags as appropriate including validation, examples216- Example: mcp-api-researcher, comprehensive-auditor217</intelligence_rules>218219<critical_rule>220**Remove ALL markdown headings (##, ###) from subagent body.** Use semantic XML tags instead.221222Keep markdown formatting WITHIN content (bold, italic, lists, code blocks, links).223224For XML structure principles and token efficiency details, see @skills/create-agent-skills/references/use-xml-tags.md - the same principles apply to subagents.225</critical_rule>226</subagent_xml_structure>227228<invocation>229<automatic>230Claude automatically selects subagents based on the `description` field when it matches the current task.231</automatic>232233<explicit>234You can explicitly invoke a subagent:235236```237> Use the code-reviewer subagent to check my recent changes238```239240```241> Have the test-writer subagent create tests for the new API endpoints242```243</explicit>244</invocation>245246<management>247<using_agents_command>248Run `/agents` for an interactive interface to:249- View all available subagents250- Create new subagents251- Edit existing subagents252- Delete custom subagents253</using_agents_command>254255<manual_editing>256You can also edit subagent files directly:257- Project: `.claude/agents/subagent-name.md`258- User: `~/.claude/agents/subagent-name.md`259</manual_editing>260</management>261262<reference>263**Core references**:264265**Subagent usage and configuration**: [references/subagents.md](references/subagents.md)266- File format and configuration267- Model selection (Sonnet 4.5 + Haiku 4.5 orchestration)268- Tool security and least privilege269- Prompt caching optimization270- Complete examples271272**Writing effective prompts**: [references/writing-subagent-prompts.md](references/writing-subagent-prompts.md)273- Core principles and XML structure274- Description field optimization for routing275- Extended thinking for complex reasoning276- Security constraints and strong modal verbs277- Success criteria definition278279**Advanced topics**:280281**Evaluation and testing**: [references/evaluation-and-testing.md](references/evaluation-and-testing.md)282- Evaluation metrics (task completion, tool correctness, robustness)283- Testing strategies (offline, simulation, online monitoring)284- Evaluation-driven development285- G-Eval for custom criteria286287**Error handling and recovery**: [references/error-handling-and-recovery.md](references/error-handling-and-recovery.md)288- Common failure modes and causes289- Recovery strategies (graceful degradation, retry, circuit breakers)290- Structured communication and observability291- Anti-patterns to avoid292293**Context management**: [references/context-management.md](references/context-management.md)294- Memory architecture (STM, LTM, working memory)295- Context strategies (summarization, sliding window, scratchpads)296- Managing long-running tasks297- Prompt caching interaction298299**Orchestration patterns**: [references/orchestration-patterns.md](references/orchestration-patterns.md)300- Sequential, parallel, hierarchical, coordinator patterns301- Sonnet + Haiku orchestration for cost/performance302- Multi-agent coordination303- Pattern selection guidance304305**Debugging and troubleshooting**: [references/debugging-agents.md](references/debugging-agents.md)306- Logging, tracing, and correlation IDs307- Common failure types (hallucinations, format errors, tool misuse)308- Diagnostic procedures309- Continuous monitoring310</reference>311312<success_criteria>313A well-configured subagent has:314315- Valid YAML frontmatter (name matches file, description includes triggers)316- Clear role definition in system prompt317- Appropriate tool restrictions (least privilege)318- XML-structured system prompt with role, approach, and constraints319- Description field optimized for automatic routing320- Successfully tested on representative tasks321- Model selection appropriate for task complexity (Sonnet for reasoning, Haiku for simple tasks)322</success_criteria>