Files
claude-plugins/claude-code/skills/claude-subagents/SKILL.md

303 lines
7.5 KiB
Markdown
Raw Normal View History

2025-10-28 12:28:48 -05:00
---
name: Claude Code Subagent Specialist
2025-10-28 12:48:17 -05:00
description: Refine and troubleshoot Claude Code subagents by optimizing prompts, tool access, descriptions, and performance. Use PROACTIVELY immediately AFTER creating subagent with /agents command to optimize configuration, when subagent doesn't activate as expected, when users mention "subagent not working", "agent won't trigger", or "refine agent". NOT for initial creation - use /agents command first.
2025-10-28 12:28:48 -05:00
---
# Claude Code Subagent Refinement & Troubleshooting
## When to Use This Skill
Use this skill when:
2025-10-28 12:48:17 -05:00
- Refining existing subagent prompts
- Troubleshooting activation issues
2025-10-28 12:28:48 -05:00
- Optimizing tool access and permissions
2025-10-28 12:48:17 -05:00
- Improving delegation patterns
- Converting ad-hoc workflows to subagents
2025-10-28 12:28:48 -05:00
Do NOT use this skill for:
2025-10-28 12:48:17 -05:00
- **Initial creation** - Use `/agents` command
- Creating slash commands (use claude-commands skill)
- General troubleshooting
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
**Important**: Always start with `/agents` to create subagents.
2025-10-28 12:28:48 -05:00
## Quick Reference: Subagent Structure
```yaml
---
2025-10-28 12:48:17 -05:00
name: agent-name # kebab-case
description: When to use # Triggers delegation
2025-10-28 12:28:48 -05:00
tools: Tool1, Tool2 # Optional: omit to inherit all
model: sonnet # Optional: sonnet/opus/haiku/inherit
---
2025-10-28 12:48:17 -05:00
System prompt defining role, capabilities, behavior.
2025-10-28 12:28:48 -05:00
```
**Locations**:
- Project: `.claude/agents/` (highest priority)
- User: `~/.claude/agents/` (shared across projects)
- Plugin: `agents/` in plugin directory
## Common Problems (Quick Solutions)
### Problem 1: Subagent Never Activates
2025-10-28 12:48:17 -05:00
**Diagnosis**: Vague description
2025-10-28 12:28:48 -05:00
```yaml
2025-10-28 12:48:17 -05:00
# ❌ Too vague
2025-10-28 12:28:48 -05:00
---
description: Helper agent
---
2025-10-28 12:48:17 -05:00
# ✓ Specific with triggers
2025-10-28 12:28:48 -05:00
---
description: Analyze code for security vulnerabilities including SQL injection, XSS, authentication flaws, and hardcoded secrets. Use PROACTIVELY when reviewing code for security issues.
---
```
2025-10-28 12:48:17 -05:00
**Fix**: Add specificity + "PROACTIVELY" or "MUST BE USED"
2025-10-28 12:28:48 -05:00
### Problem 2: Wrong Tool Access
```yaml
2025-10-28 12:48:17 -05:00
# ❌ Too permissive (inherits all)
2025-10-28 12:28:48 -05:00
---
name: security-analyzer
2025-10-28 12:48:17 -05:00
# (no tools field)
2025-10-28 12:28:48 -05:00
---
# ✓ Restricted to needs
---
name: security-analyzer
tools: Read, Grep, Glob
---
```
**Tool Access Strategies**:
2025-10-28 12:48:17 -05:00
- **Inherit All**: Omit `tools` field
- **Read-Only**: `tools: Read, Grep, Glob`
- **Specific**: `tools: Read, Write, Edit, Bash(npm test:*)`
- **Research**: `tools: WebFetch, WebSearch`
2025-10-28 12:28:48 -05:00
### Problem 3: Poor Output Quality
2025-10-28 12:48:17 -05:00
**Diagnosis**: Needs structured prompt
2025-10-28 12:28:48 -05:00
```markdown
# ❌ Vague
You review code for issues.
# ✓ Structured
2025-10-28 12:48:17 -05:00
You are a senior code reviewer specializing in production-ready quality.
2025-10-28 12:28:48 -05:00
## Your Responsibilities
1. **Logic & Correctness**: Verify algorithms, edge cases
2. **Code Quality**: SRP, DRY, meaningful naming
3. **Security**: Injection vulnerabilities, auth checks
4. **Performance**: O(n²) algorithms, resource cleanup
## Output Format
For each issue:
- **Severity**: Critical/High/Medium/Low
- **Location**: file:line
- **Issue**: Clear description
- **Fix**: Specific code example
## Constraints
- Only actionable issues
- Focus on high-impact problems
```
2025-10-28 12:48:17 -05:00
For detailed patterns, see [patterns.md](patterns.md)
2025-10-28 12:28:48 -05:00
## Description Best Practices
### Template
```yaml
2025-10-28 12:48:17 -05:00
description: [Action] [domain] [including capabilities]. Use [trigger]. PROACTIVELY when [scenario].
2025-10-28 12:28:48 -05:00
```
### Examples
**✓ Good**:
```yaml
description: Analyze Python code for performance bottlenecks including O(n²) algorithms, memory leaks, and inefficient database queries. Use PROACTIVELY when optimizing Python applications.
description: Generate comprehensive API documentation from code including endpoints, parameters, responses, and examples. Use when documenting REST or GraphQL APIs.
description: Review frontend code for accessibility issues following WCAG 2.1 AA standards. MUST BE USED for all UI component changes.
```
**❌ Avoid**:
```yaml
description: Helps with coding
description: Python utilities
description: Security checker
```
2025-10-28 12:48:17 -05:00
## Model Selection
2025-10-28 12:28:48 -05:00
| Model | Use For | Avoid For |
|-------|---------|-----------|
2025-10-28 12:48:17 -05:00
| haiku | Simple transforms, quick checks | Complex reasoning |
| sonnet | General tasks (default) | When opus needed |
| opus | Complex architecture, creative work | Simple tasks (costly) |
2025-10-28 12:28:48 -05:00
| inherit | Task matches main thread | Need different capability |
## Testing Subagents
### Test Plan Template
```markdown
# Positive Tests (Should Activate)
1. "Create REST endpoint for user auth"
Expected: Activates
Actual: ___
# Negative Tests (Should NOT Activate)
1. "Write unit tests for API"
2025-10-28 12:48:17 -05:00
Expected: Does not activate (different concern)
2025-10-28 12:28:48 -05:00
Actual: ___
## Results
2025-10-28 12:48:17 -05:00
- Precision: X%
- Recall: Y%
2025-10-28 12:28:48 -05:00
```
2025-10-28 12:48:17 -05:00
For complete testing, see [testing.md](testing.md)
2025-10-28 12:28:48 -05:00
## System Prompt Structure
```markdown
# Role Definition
You are a [role] specializing in [domain].
## Responsibilities
1. [Primary responsibility]
2. [Secondary responsibility]
## Process
1. [Step 1]
2. [Step 2]
## Output Format
[Specific structure required]
## Examples
### Good Example
[Show what good looks like]
## Constraints
- [Important limitation]
```
## Optimization Patterns
2025-10-28 12:48:17 -05:00
### Domain Specialists
2025-10-28 12:28:48 -05:00
```yaml
# Frontend Specialist
---
name: frontend-specialist
description: React/TypeScript UI development and component design. Use PROACTIVELY for frontend work.
tools: Read, Write, Edit, Grep, Bash(npm:*)
---
2025-10-28 12:48:17 -05:00
You are a React/TypeScript expert specializing in modern frontend.
2025-10-28 12:28:48 -05:00
## Tech Stack
- React 18+ with hooks
- TypeScript (strict mode)
- Tailwind CSS
- Component-driven architecture
## Principles
- Functional components only
- Custom hooks for logic reuse
- Accessibility (WCAG AA)
```
2025-10-28 12:48:17 -05:00
### Role-Based Pipeline
```yaml
# Architect Agent (opus)
---
name: solution-architect
description: Design system architecture from requirements
tools: Read, Write, WebSearch
model: opus
---
# Implementer Agent (sonnet)
---
name: code-implementer
description: Implement features from designs
tools: Read, Write, Edit, Bash(npm test:*)
model: sonnet
---
```
2025-10-28 12:28:48 -05:00
## Debugging Checklist
2025-10-28 12:48:17 -05:00
When subagent doesn't work:
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
- [ ] Description is specific with trigger words
- [ ] Description includes "PROACTIVELY" if needed
2025-10-28 12:28:48 -05:00
- [ ] System prompt defines role clearly
- [ ] System prompt includes process/steps
- [ ] System prompt specifies output format
- [ ] Tools match required capabilities
2025-10-28 12:48:17 -05:00
- [ ] Model appropriate for complexity
- [ ] File in `.claude/agents/`
2025-10-28 12:28:48 -05:00
- [ ] YAML frontmatter valid
- [ ] Name uses kebab-case
2025-10-28 12:48:17 -05:00
- [ ] Tested positive/negative scenarios
2025-10-28 12:28:48 -05:00
## Migration: Ad-Hoc to Subagent
### When to Migrate
- Used same prompt 3+ times
2025-10-28 12:48:17 -05:00
- Prompt has clear pattern
2025-10-28 12:28:48 -05:00
- Task benefits from isolation
- Multiple team members need it
### Process
**Step 1: Extract Pattern**
2025-10-28 12:48:17 -05:00
```
2025-10-28 12:28:48 -05:00
# Repeated prompts:
2025-10-28 12:48:17 -05:00
1. "Review auth.js for security"
2025-10-28 12:28:48 -05:00
2. "Check payment.js for vulnerabilities"
2025-10-28 12:48:17 -05:00
3. "Analyze api.js for security"
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
# Pattern: Review [file] for security
2025-10-28 12:28:48 -05:00
```
**Step 2: Generalize**
```yaml
---
name: security-reviewer
2025-10-28 12:48:17 -05:00
description: Review code for security vulnerabilities. Use PROACTIVELY for security reviews.
2025-10-28 12:28:48 -05:00
tools: Read, Grep, Glob
---
```
**Step 3: Test & Refine**
2025-10-28 12:48:17 -05:00
Test with previous use cases, refine until quality matches.
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
## Additional Resources
2025-10-28 12:28:48 -05:00
2025-10-28 12:48:17 -05:00
**Need more?**
2025-10-28 12:28:48 -05:00
- [Optimization Patterns](patterns.md) - Advanced subagent patterns
2025-10-28 12:48:17 -05:00
- [Testing Strategies](testing.md) - Comprehensive testing
2025-10-28 12:28:48 -05:00
- [System Prompt Templates](templates.md) - Ready-to-use prompts
2025-10-28 12:48:17 -05:00
- [Official Docs](https://docs.claude.com/en/docs/claude-code/sub-agents)
💡 **Tip**: Start with `/agents`, then refine. Iterate based on real usage. Test thoroughly.
2025-10-28 12:28:48 -05:00
---
2025-10-28 12:48:17 -05:00
**Remember**: Use `/agents` to create. This skill refines. Specific descriptions trigger correctly. Test positive AND negative scenarios.