Create well-structured subagents for Claude Code with specialized expertise, proper tool configurations, and effective system prompts...
Create specialized AI subagents for Claude Code that handle specific tasks with focused expertise and isolated context.
Subagents are specialized AI assistants that Claude Code delegates tasks to. Each subagent:
.claude/agents/ (project) or ~/.claude/agents/ (user-wide)Create subagents for:
Select a starting template from assets/:
template-code-reviewer.md - Code quality and security reviewtemplate-debugger.md - Error investigation and fixingtemplate-test-runner.md - Automated testing workflowstemplate-codebase-researcher.md - Architecture analysis and reverse engineeringtemplate-data-analyst.md - Statistical analysis and visualizationOr start from scratch using the structure in references/subagent-best-practices.md.
Edit the YAML frontmatter:
---
name: your-subagent-name # lowercase-with-hyphens
description: Specific description # When to use this subagent
tools: Read, Edit, Bash # Optional: specific tools only
model: sonnet # Optional: sonnet/opus/haiku/inherit
---
Description writing tips:
Tool selection:
tools: to inherit all tools (flexible but less focused)/agents command to see all available tools including MCP toolsModel selection:
sonnet: Default, balanced speed and capabilityopus: Most capable, use for complex analysis haiku: Fastest, use for simple tasks'inherit': Match main conversation's modelFollow this structure:
You are a [role] specializing in [domain].
When invoked:
1. [First step - usually gather information]
2. [Second step - analysis or processing]
3. [Final step - output or recommendation]
[Specific guidance section]:
- [Key principle or rule]
- [Technique to apply]
- [Important pattern]
For each [output type], provide:
- [Required element 1]
- [Quality standard]
- [Format specification]
Focus on [core objective], not [anti-pattern to avoid].
See references/subagent-best-practices.md for detailed examples and patterns.
For project-specific use:
mkdir -p .claude/agents
mv your-subagent.md .claude/agents/
For personal use across all projects:
mkdir -p ~/.claude/agents
mv your-subagent.md ~/.claude/agents/
Priority: Project subagents override user-level subagents with the same name.
> Use the your-subagent-name subagent to [task]Best for: Debugging, testing, deployment
When invoked:
1. Discovery/analysis step
2. Planning step
3. Execution step
4. Verification step
Best for: Code review, architecture analysis, research
Analysis checklist:
- Criterion 1
- Criterion 2
- Criterion 3
Feedback organized by:
- Critical issues
- Warnings
- Suggestions
Best for: Databases, cloud services, file formats
When invoked:
1. Understand requirement
2. Use [specific tool/command]
3. Process/format results
4. Present findings
The /agents command provides an interactive interface:
/agents
Features:
Recommended: Use /agents for tool management - it shows all available tools including MCP server tools.
For complex workflows:
> Use code-analyzer to find issues, then optimizer to fix them
Claude coordinates the sequence automatically.
Make subagents activate automatically:
Example:
description: Test runner. Use proactively after code changes to run tests and fix failures.
See references/subagent-best-practices.md for:
Available in assets/:
template-code-reviewer.md
template-debugger.md
template-test-runner.md
template-codebase-researcher.md
template-data-analyst.md
name: code-quality-enforcer
description: Style and quality enforcer. Use proactively before commits to ensure standards.
tools: Read, Bash, Grep
name: git-specialist
description: Git workflow expert. Use before commits, after conflicts, when investigating history.
tools: Bash, Read, Grep
name: doc-writer
description: Technical documentation specialist. Use after implementing features to generate docs.
tools: Read, Write, Grep, Glob
name: security-auditor
description: Security analyst. MUST BE USED when reviewing auth, data handling, or API endpoints.
tools: Read, Grep, Glob
ā Do:
ā Don't:
Subagent not triggering automatically?
> Use [name] subagent to [task]Subagent lacking necessary context?
Subagent using wrong tools?
/agents command to adjust tool accessMultiple subagents with similar names?
/agentsassets/ that matches your needs.claude/agents/ or ~/.claude/agents/references/subagent-best-practices.md for detailed guidance