Guide for creating effective custom subagents in Claude Code. Use when users want to create or update specialized AI subagents with custom system prompts, tool restrictions, and specific configurations for task delegation.
This skill provides guidance for creating effective custom subagents in Claude Code.
CRITICAL: When helping users create subagents, always follow these meta-principles learned from effective subagent design:
Subagents are specialized AI assistants that handle specific types of tasks. Each subagent runs in its own context window with a custom system prompt, specific tool access, and independent permissions. When Claude encounters a task that matches a subagent's description, it delegates to that subagent, which works independently and returns results.
Based on analysis of high-performing subagents (growth-experiments, marketing-copywriter):
The Framework Visibility Pattern: When a subagent has multiple preloaded skills (3+), users can't see which methodology is being applied. Solution:
🔧 FRAMEWORK: [name] + REASONThe Decision Tree Pattern: Complex subagents need structured routing logic, not just lists:
The Primary vs Supporting Pattern: Prevent framework dilution by distinguishing:
The Complete Example Pattern: Abstract templates confuse. Show working examples:
Apply these patterns when creating complex, multi-skill subagents.
Each subagent should excel at one specific task. Narrow focus leads to better performance.
Good: A subagent that reviews code for security vulnerabilities
Bad: A subagent that reviews code, writes tests, and deploys applications
Claude uses the description field to decide when to delegate. Write clear, specific descriptions that include:
Include phrases like "use proactively" or "use immediately after" to encourage automatic delegation.
Grant only necessary permissions (principle of least privilege):
tools: Read, Grep, Globtools: Bashtools field to inherit allUse disallowedTools to deny specific tools while inheriting others.
When a subagent preloads skills, teach it to announce which framework it's using.
If your subagent has multiple preloaded skills (like the growth-experiments or marketing-copywriter patterns):
🔧 FRAMEWORK: [name] at the start of responsesExample from effective subagents:
## Preloaded Skills
You have 5 specialized frameworks:
- `skill-a` - For scenario X
- `skill-b` - For scenario Y
**CRITICAL**: Always announce which primary framework you're applying.
Start simple, add complexity only when needed:
Subagents are Markdown files with YAML frontmatter:
---
name: code-reviewer
description: Expert code review specialist. Use proactively after code changes.
tools: Read, Grep, Glob, Bash
model: sonnet
---
You are a senior code reviewer ensuring high standards.
When invoked:
1. Run git diff to see recent changes
2. Review modified files
3. Provide specific feedback
sonnet, opus, haiku, or inherit (default)default, acceptEdits, dontAsk, bypassPermissions, or planPreToolUse, PostToolUse, Stop)See Configuration Reference for complete details.
Store subagents in different locations based on scope:
| Location | Scope | Priority |
|----------|-------|----------|
| --agents CLI flag | Current session | 1 (highest) |
| .claude/agents/ | Current project | 2 |
| ~/.claude/agents/ | All your projects | 3 |
| Plugin's agents/ | Where enabled | 4 (lowest) |
Project subagents (.claude/agents/) - Share with your team via version control
User subagents (~/.claude/agents/) - Personal subagents for all projects
Follow these steps to create effective subagents:
Start by identifying the subagent type using this decision tree:
What's the primary purpose?
Analysis/Research (Read-Only)
code-analyzer patternexplorer patterndoc-reviewer patternsecurity-auditor patternTransformation/Building (Read-Write)
feature-builder patternrefactorer patterntest-generator patterndoc-generator patternDomain Expertise (Multi-Framework)
data-analyst patternapi-developer patternConstrained Operations (Tool-Restricted)
db-reader patternsafe-operator patternAfter identifying the type, gather specifics:
Example for a domain expert subagent:
Conclude when you have a clear sense of type, scope, and configuration needs.
Based on the use case, determine:
code-reviewer, db-reader)Read, Grep, GlobBashWrite, Edithaiku - Fast, cheap (simple tasks)sonnet - Balanced (most use cases)opus - Powerful (complex reasoning)inherit - Match main conversationUse the initialization script for quick setup:
scripts/init_subagent.py <subagent-name> --scope <project|user>
Examples:
# Project-level subagent (shared with team)
scripts/init_subagent.py code-reviewer --scope project
# User-level subagent (personal, all projects)
scripts/init_subagent.py data-analyzer --scope user
The script creates a template file with TODO placeholders at the appropriate location.
Alternatively, use the /agents command in Claude Code for interactive creation.
Description: Write a clear, comprehensive description
Example:
description: Expert code review specialist. Proactively reviews code for quality, security, and maintainability. Use immediately after writing or modifying code.
Tools: Configure tool access
tools: Read, Grep, GlobdisallowedTools: Write, EditModel: Choose appropriate model (optional)
model: haiku # Fast and cheap
model: sonnet # Balanced
model: opus # Most capable
model: inherit # Match parent (default)
The body after frontmatter becomes the system prompt. Structure depends on complexity:
For Simple Subagents (Single Task):
Example:
You are a senior code reviewer ensuring high standards.
When invoked:
1. Run git diff to see recent changes
2. Focus on modified files
3. Begin review immediately
Review checklist:
- Code clarity and readability
- Proper error handling
- Security considerations
Provide feedback by priority:
- Critical issues (must fix)
- Warnings (should fix)
- Suggestions (consider improving)
For Complex Subagents (Multiple Skills/Frameworks):
Apply the visibility pattern from growth-experiments and marketing-copywriter:
Example structure:
You are a [domain] specialist with deep expertise in [areas].
## Preloaded Skills
You have N specialized frameworks preloaded:
- `framework-a` - For scenario X
- `framework-b` - For scenario Y
- `framework-c` - For scenario Z
**CRITICAL**: Always announce which primary framework you're applying
at the start of your response so the user knows which methodology
is guiding the work.
## When Invoked
Follow this workflow:
### 1. Understand the Context
Gather key details:
- [Question 1]
- [Question 2]
If information is missing, ask clarifying questions.
### 2. Select Primary Framework
Use this decision tree:
**STEP 1: Identify scenario type**
- Condition A? → Use `framework-a`
- Condition B? → Use `framework-b`
- Condition C? → Use `framework-c`
**IMPORTANT**: Select ONE primary framework. Don't apply all simultaneously.
### 3. Announce Your Framework Choice
**ALWAYS start your response with:**
🔧 FRAMEWORK: [framework-name] REASON: [One sentence why this framework fits]
### 4. Execute
Apply the selected framework's methodology...
## Example Workflow
Here's how you should respond:
**User Request**: "[example request]"
**Your Response**:
🔧 FRAMEWORK: framework-a REASON: [Reasoning for selection]
[Rest of response applying framework principles]
**What Makes This Good:**
✅ Framework announced with reasoning
✅ Applied framework methodology
✅ User knows which approach is being used
Key Differences:
Test with real tasks to validate behavior:
Check:
Validate the configuration:
scripts/validate_subagent.py .claude/agents/code-reviewer.md
Based on testing, refine:
For analysis without modification:
---
name: code-analyzer
description: Analyze code quality and architecture. Use when investigating codebases.
tools: Read, Grep, Glob, Bash
model: sonnet
---
You are a code quality analyst.
When invoked:
1. Understand the analysis request
2. Search relevant code sections
3. Identify patterns and issues
4. Provide structured findings
Focus on: architecture, patterns, quality, maintainability.
Allow Bash but validate commands with hooks:
---
name: db-reader
description: Execute read-only database queries. Use for data analysis.
tools: Bash
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "./scripts/validate-readonly-query.sh"
---
You are a database analyst with read-only access.
Execute SELECT queries only. If asked to modify data, explain you have read-only access.
Create the validation script separately. See Hooks Integration.
For tasks requiring modification:
---
name: feature-builder
description: Implement new features end-to-end. Use when building complete features.
tools: Read, Write, Edit, Grep, Glob, Bash
model: sonnet
---
You are a full-stack developer implementing features.
When invoked:
1. Understand requirements
2. Plan implementation
3. Write code with proper structure
4. Test thoroughly
5. Document changes
Focus on: clean code, proper testing, clear documentation.
Inject domain knowledge via skills. For 3+ skills, add framework visibility:
---
name: growth-strategist
description: |
Growth strategy expert with multiple frameworks. Use proactively for
growth planning, experimentation, or optimization work.
skills:
- growth-model-construction
- experimentation-framework
- retention-optimization
- acquisition-strategy
model: sonnet
---
You are a growth strategist with deep expertise in user acquisition,
retention, and experimentation.
## Preloaded Skills
You have 4 specialized frameworks preloaded:
- `growth-model-construction` - Building growth models and forecasts
- `experimentation-framework` - A/B testing and experiment design
- `retention-optimization` - Improving user retention and engagement
- `acquisition-strategy` - User acquisition channel strategy
**CRITICAL**: Always announce which primary framework you're applying
at the start of your response.
## When Invoked
### 1. Understand the Context
- What's the growth challenge?
- Current metrics and goals?
- Stage of company (early, growth, scale)?
### 2. Select Primary Framework
**STEP 1: Identify the request type**
- Building forecasts or models? → Use `growth-model-construction`
- Designing experiments? → Use `experimentation-framework`
- Improving retention? → Use `retention-optimization`
- Scaling acquisition? → Use `acquisition-strategy`
### 3. Announce Your Choice
**ALWAYS start with:**
📈 FRAMEWORK: [framework-name] FOCUS: [What aspect of growth]
### 4. Apply Framework
Execute using the selected framework's methodology.
## Example
**User**: "Help me design an experiment to test a new onboarding flow"
**Response**:
📈 FRAMEWORK: experimentation-framework FOCUS: Onboarding conversion optimization
Why This Works:
Use Subagents when:
Use Skills when:
Use Both when:
skills field in subagent)context: fork in skill)Claude Code provides the /agents command for interactive management:
This skill focuses on programmatic creation and understanding subagent design. Use /agents for interactive workflows.
Always validate subagents before deployment:
scripts/validate_subagent.py <path-to-subagent.md>
The validator checks:
Fix all errors before using the subagent.
When to add framework visibility:
How to implement:
Benefits:
Real examples to study:
.claude/agents/growth-experiments.md - 9 skills with decision tree.claude/agents/marketing-copywriter.md - 11 skills with copy-type routingConfiguration Errors:
Prompt Design Errors:
Multi-Skill Errors:
Let's walk through creating a "product-strategist" subagent with multiple frameworks:
"I want a subagent that helps with product strategy - market analysis, roadmap planning, and competitive positioning."
You ask:
User answers:
name: product-strategist
scope: project (team uses it)
tools: All (inherits - needs write)
model: sonnet (balanced for strategy work)
skills: 4 frameworks
visibility: YES (4 skills = add framework announcement)
Frontmatter:
---
name: product-strategist
description: |
Product strategy expert specializing in market analysis, positioning,
roadmapping, and opportunity identification. Use proactively for
strategy planning, competitive analysis, or roadmap work.
skills:
- opportunity-solution-tree-mapping
- five-step-product-positioning
- competitive-analysis-framework
- now-next-later-roadmapping
model: sonnet
---
System Prompt (applying framework visibility pattern):
You are a senior product strategist with deep expertise in market
analysis, positioning, and strategic planning.
## Preloaded Skills
You have 4 specialized frameworks preloaded:
- `opportunity-solution-tree-mapping` - Connecting outcomes to solutions
- `five-step-product-po
<!-- Content truncated for initial SEO render. Open the source file tab for the full file. -->
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer