Learn how to create powerful, interconnected Claude sub-agents using advanced patterns.
---
name: your-agent-name
description: |
One-line description of expertise.
Examples:
- <example>
Context: When this agent should be used
user: "Example user request"
assistant: "I'll use the your-agent-name to..."
<commentary>
Why this agent was selected
</commentary>
</example>
tools: Read, Write, Edit, Bash # Optional - inherits all if omitted
---
You are an expert [role] specializing in [domain].
## Core Expertise
- [Specific skill 1]
- [Specific skill 2]
## Task Approach
1. [How you handle tasks]
2. [Your methodology]
## Delegation Patterns
When I encounter [type of task], I delegate to [agent-name].Claude uses XML-style examples in descriptions for intelligent agent selection:
description: |
Expert backend developer specializing in APIs and security.
Examples:
- <example>
Context: User needs to build an API
user: "Create a REST API for products"
assistant: "I'll use the backend-developer to build a comprehensive products API"
<commentary>
API development is a core backend task
</commentary>
</example>
- <example>
Context: User has completed backend and needs frontend
user: "Now I need a UI for this API"
assistant: "The backend is complete. Let me hand this off to the tailwind-frontend-expert"
<commentary>
Recognizing when to delegate to frontend specialist
</commentary>
</example>- Pattern Learning: Claude learns from examples when to invoke agents
- Context Awareness: Understands project stage and user intent
- Smart Delegation: Knows when to hand off to other specialists
- Self-Documenting: Examples serve as live documentation
Add delegation patterns to your system prompt:
## Delegation Patterns
When tasks require expertise outside my domain:
- Frontend UI needed → tailwind-frontend-expert
- Security review → security-auditor
- Database optimization → database-architect
I will complete my portion and suggest the appropriate specialist.For complex workflows, use delegation examples:
Delegations:
- <delegation>
Trigger: Frontend implementation needed
Handoff: "Backend API complete at /api/products. Handing off to frontend expert."
Context: { endpoints: ["/api/products", "/api/products/{id}"], auth: "Bearer token" }
</delegation>The tools field in the agent frontmatter is optional. When you omit it, the agent inherits ALL available tools, including:
- All built-in Claude Code tools (Read, Write, Edit, MultiEdit, Bash, Grep, Glob, LS, etc.)
- WebFetch for accessing documentation and web resources
- Any MCP (Model Context Protocol) tools from connected servers
---
name: my-agent
description: "My agent description"
# No tools field = inherits everything!
---Only specify tools when you want to restrict an agent's capabilities:
---
name: code-reviewer
description: "Reviews code without making changes"
tools: Read, Grep, Glob, Bash # Read-only tools for safety
---- Most agents should omit the tools field - This gives maximum flexibility
- Security-sensitive agents - Explicitly list tools (e.g., reviewers get read-only)
- Future-proof - Omitting tools means new tools are automatically available
- Single domain mastery
- Clear boundaries
- Specific use cases
- 2-3 examples covering different scenarios
- Include edge cases
- Show when NOT to use this agent
- Know your limits
- Identify next steps
- Pass context forward
- Invocation Test: Does it trigger on appropriate requests?
- Delegation Test: Does it hand off correctly?
- Quality Test: Is the output expert-level?
Backend Expert → API Complete → Frontend Expert → UI Built → Code Reviewer
Project Orchestrator → Backend Expert + Frontend Expert → Integration → Testing
Developer Agent → Code Complete → Security Auditor → Deployment Expert
- See Interconnected Agents for advanced workflows
- Check examples/ for real agent implementations
- Use templates/agent-template.md as starting point