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: create-subagents
3description: 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.
4origin: "https://raw.githubusercontent.com/glittercowboy/taches-cc-resources/main/skills/create-subagents/SKILL.md"
5metadata:
6 source: https://skillmd.com/skills/yanacuti1121/create-subagents
7---
8
9<objective>
10Subagents 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.
11
12Subagents enable delegation of complex tasks to specialized agents that operate autonomously without user interaction, returning their final output to the main conversation.
13</objective>
14
15<quick_start>
16<workflow>
171. Run `/agents` command
182. Select "Create New Agent"
193. Choose project-level (`.claude/agents/`) or user-level (`~/.claude/agents/`)
204. Define the subagent:
21 - **name**: lowercase-with-hyphens
22 - **description**: When should this subagent be used?
23 - **tools**: Optional comma-separated list (inherits all if omitted)
24 - **model**: Optional (`sonnet`, `opus`, `haiku`, or `inherit`)
255. Write the system prompt (the subagent's instructions)
26</workflow>
27
28<example>
29```markdown
30---
31name: code-reviewer
32description: Expert code reviewer. Use proactively after code changes to review for quality, security, and best practices.
33tools: Read, Grep, Glob, Bash
34model: sonnet
35---
36
37<role>
38You are a senior code reviewer focused on quality, security, and best practices.
39</role>
40
41<focus_areas>
42- Code quality and maintainability
43- Security vulnerabilities
44- Performance issues
45- Best practices adherence
46</focus_areas>
47
48<output_format>
49Provide specific, actionable feedback with file:line references.
50</output_format>
51```
52</example>
53</quick_start>
54
55<file_structure>
56| Type | Location | Scope | Priority |
57|------|----------|-------|----------|
58| **Project** | `.claude/agents/` | Current project only | Highest |
59| **User** | `~/.claude/agents/` | All projects | Lower |
60| **Plugin** | Plugin's `agents/` dir | All projects | Lowest |
61
62Project-level subagents override user-level when names conflict.
63</file_structure>
64
65<configuration>
66<field name="name">
67- Lowercase letters and hyphens only
68- Must be unique
69</field>
70
71<field name="description">
72- Natural language description of purpose
73- Include when Claude should invoke this subagent
74- Used for automatic subagent selection
75</field>
76
77<field name="tools">
78- Comma-separated list: `Read, Write, Edit, Bash, Grep`
79- If omitted: inherits all tools from main thread
80- Use `/agents` interface to see all available tools
81</field>
82
83<field name="model">
84- `sonnet`, `opus`, `haiku`, or `inherit`
85- `inherit`: uses same model as main conversation
86- If omitted: defaults to configured subagent model (usually sonnet)
87</field>
88</configuration>
89
90<execution_model>
91<critical_constraint>
92**Subagents are black boxes that cannot interact with users.**
93
94Subagents run in isolated contexts and return their final output to the main conversation. They:
95- ✅ Can use tools like Read, Write, Edit, Bash, Grep, Glob
96- ✅ Can access MCP servers and other non-interactive tools
97- ❌ **Cannot use AskUserQuestion** or any tool requiring user interaction
98- ❌ **Cannot present options or wait for user input**
99- ❌ **User never sees subagent's intermediate steps**
100
101The main conversation sees only the subagent's final report/output.
102</critical_constraint>
103
104<workflow_design>
105**Designing workflows with subagents:**
106
107Use **main chat** for:
108- Gathering requirements from user (AskUserQuestion)
109- Presenting options or decisions to user
110- Any task requiring user confirmation/input
111- Work where user needs visibility into progress
112
113Use **subagents** for:
114- Research tasks (API documentation lookup, code analysis)
115- Code generation based on pre-defined requirements
116- Analysis and reporting (security review, test coverage)
117- Context-heavy operations that don't need user interaction
118
119**Example workflow pattern:**
120```
121Main Chat: Ask user for requirements (AskUserQuestion)
122 ↓
123Subagent: Research API and create documentation (no user interaction)
124 ↓
125Main Chat: Review research with user, confirm approach
126 ↓
127Subagent: Generate code based on confirmed plan
128 ↓
129Main Chat: Present results, handle testing/deployment
130```
131</workflow_design>
132</execution_model>
133
134<system_prompt_guidelines>
135<principle name="be_specific">
136Clearly define the subagent's role, capabilities, and constraints.
137</principle>
138
139<principle name="use_pure_xml_structure">
140Structure the system prompt with pure XML tags. Remove ALL markdown headings from the body.
141
142```markdown
143---
144name: security-reviewer
145description: Reviews code for security vulnerabilities
146tools: Read, Grep, Glob, Bash
147model: sonnet
148---
149
150<role>
151You are a senior code reviewer specializing in security.
152</role>
153
154<focus_areas>
155- SQL injection vulnerabilities
156- XSS attack vectors
157- Authentication/authorization issues
158- Sensitive data exposure
159</focus_areas>
160
161<workflow>
1621. Read the modified files
1632. Identify security risks
1643. Provide specific remediation steps
1654. Rate severity (Critical/High/Medium/Low)
166</workflow>
167```
168</principle>
169
170<principle name="task_specific">
171Tailor instructions to the specific task domain. Don't create generic "helper" subagents.
172
173❌ Bad: "You are a helpful assistant that helps with code"
174✅ Good: "You are a React component refactoring specialist. Analyze components for hooks best practices, performance anti-patterns, and accessibility issues."
175</principle>
176</system_prompt_guidelines>
177
178<subagent_xml_structure>
179Subagent.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.
180
181<recommended_tags>
182Common tags for subagent structure:
183
184- `<role>` - Who the subagent is and what it does
185- `<constraints>` - Hard rules (NEVER/MUST/ALWAYS)
186- `<focus_areas>` - What to prioritize
187- `<workflow>` - Step-by-step process
188- `<output_format>` - How to structure deliverables
189- `<success_criteria>` - Completion criteria
190- `<validation>` - How to verify work
191</recommended_tags>
192
193<intelligence_rules>
194**Simple subagents** (single focused task):
195- Use role + constraints + workflow minimum
196- Example: code-reviewer, test-runner
197
198**Medium subagents** (multi-step process):
199- Add workflow steps, output_format, success_criteria
200- Example: api-researcher, documentation-generator
201
202**Complex subagents** (research + generation + validation):
203- Add all tags as appropriate including validation, examples
204- Example: mcp-api-researcher, comprehensive-auditor
205</intelligence_rules>
206
207<critical_rule>
208**Remove ALL markdown headings (##, ###) from subagent body.** Use semantic XML tags instead.
209
210Keep markdown formatting WITHIN content (bold, italic, lists, code blocks, links).
211
212For XML structure principles and token efficiency details, see @skills/create-agent-skills/references/use-xml-tags.md - the same principles apply to subagents.
213</critical_rule>
214</subagent_xml_structure>
215
216<invocation>
217<automatic>
218Claude automatically selects subagents based on the `description` field when it matches the current task.
219</automatic>
220
221<explicit>
222You can explicitly invoke a subagent:
223
224```
225> Use the code-reviewer subagent to check my recent changes
226```
227
228```
229> Have the test-writer subagent create tests for the new API endpoints
230```
231</explicit>
232</invocation>
233
234<management>
235<using_agents_command>
236Run `/agents` for an interactive interface to:
237- View all available subagents
238- Create new subagents
239- Edit existing subagents
240- Delete custom subagents
241</using_agents_command>
242
243<manual_editing>
244You can also edit subagent files directly:
245- Project: `.claude/agents/subagent-name.md`
246- User: `~/.claude/agents/subagent-name.md`
247</manual_editing>
248</management>
249
250<reference>
251**Core references**:
252
253**Subagent usage and configuration**: [references/subagents.md](references/subagents.md)
254- File format and configuration
255- Model selection (Sonnet 4.5 + Haiku 4.5 orchestration)
256- Tool security and least privilege
257- Prompt caching optimization
258- Complete examples
259
260**Writing effective prompts**: [references/writing-subagent-prompts.md](references/writing-subagent-prompts.md)
261- Core principles and XML structure
262- Description field optimization for routing
263- Extended thinking for complex reasoning
264- Security constraints and strong modal verbs
265- Success criteria definition
266
267**Advanced topics**:
268
269**Evaluation and testing**: [references/evaluation-and-testing.md](references/evaluation-and-testing.md)
270- Evaluation metrics (task completion, tool correctness, robustness)
271- Testing strategies (offline, simulation, online monitoring)
272- Evaluation-driven development
273- G-Eval for custom criteria
274
275**Error handling and recovery**: [references/error-handling-and-recovery.md](references/error-handling-and-recovery.md)
276- Common failure modes and causes
277- Recovery strategies (graceful degradation, retry, circuit breakers)
278- Structured communication and observability
279- Anti-patterns to avoid
280
281**Context management**: [references/context-management.md](references/context-management.md)
282- Memory architecture (STM, LTM, working memory)
283- Context strategies (summarization, sliding window, scratchpads)
284- Managing long-running tasks
285- Prompt caching interaction
286
287**Orchestration patterns**: [references/orchestration-patterns.md](references/orchestration-patterns.md)
288- Sequential, parallel, hierarchical, coordinator patterns
289- Sonnet + Haiku orchestration for cost/performance
290- Multi-agent coordination
291- Pattern selection guidance
292
293**Debugging and troubleshooting**: [references/debugging-agents.md](references/debugging-agents.md)
294- Logging, tracing, and correlation IDs
295- Common failure types (hallucinations, format errors, tool misuse)
296- Diagnostic procedures
297- Continuous monitoring
298</reference>
299
300<success_criteria>
301A well-configured subagent has:
302
303- Valid YAML frontmatter (name matches file, description includes triggers)
304- Clear role definition in system prompt
305- Appropriate tool restrictions (least privilege)
306- XML-structured system prompt with role, approach, and constraints
307- Description field optimized for automatic routing
308- Successfully tested on representative tasks
309- Model selection appropriate for task complexity (Sonnet for reasoning, Haiku for simple tasks)
310</success_criteria>