---
name: patterns
description: Common agent patterns and templates for Claude Code. Use when implementing agents to follow proven patterns for proxy mode, TodoWrite integration, and quality checks.
---
# Agent Patterns
## Proxy Mode Pattern
Enable agents to delegate to external AI models via Claudish.
```xml
**FIRST STEP: Check for Proxy Mode Directive**
Before executing, check if the incoming prompt starts with:
```
PROXY_MODE: {model_name}
```
If you see this directive:
1. **Extract model name** (e.g., "x-ai/grok-code-fast-1")
2. **Extract actual task** (everything after PROXY_MODE line)
3. **Construct agent invocation**:
```bash
AGENT_PROMPT="Use the Task tool to launch the '{agent-name}' agent:
{actual_task}"
```
4. **Delegate via Claudish**:
```bash
printf '%s' "$AGENT_PROMPT" | npx claudish --stdin --model {model_name} --quiet --auto-approve
```
5. **Return attributed response**:
```markdown
## {Task Type} via External AI: {model_name}
{EXTERNAL_AI_RESPONSE}
---
*Generated by: {model_name} via Claudish*
```
6. **STOP** - Do not execute locally
**If NO PROXY_MODE directive**: Proceed with normal workflow
```
**Key Elements:**
- Check for directive first
- Use `--auto-approve` flag
- Clear attribution in response
- STOP after proxy (don't continue locally)
---
## TodoWrite Integration Pattern
Every agent must track workflow progress.
```xml
You MUST use TodoWrite to track your workflow.
**Before starting**, create todo list:
1. Phase 1 description
2. Phase 2 description
3. Phase 3 description
**Update continuously**:
- Mark "in_progress" when starting
- Mark "completed" immediately after finishing
- Keep only ONE task "in_progress" at a time
Initialize TodoWrite with all phases
Mark PHASE 1 as in_progress
... perform work ...
Mark PHASE 1 as completed
Mark PHASE 2 as in_progress
```
---
## Quality Checks Pattern (Implementers)
```xml
Before presenting code, perform these checks in order:
Biome.js
bun run format
Must pass
Fix and retry
Biome.js
bun run lint
All errors resolved
Fix errors, retry
TypeScript
bun run typecheck
Zero type errors
Resolve errors, retry
Vitest
bun test
All tests pass
Fix failing tests
```
---
## Review Feedback Pattern (Reviewers)
```xml
## Review: {name}
**Status**: PASS | CONDITIONAL | FAIL
**Reviewer**: {model}
**Issue Summary**:
- CRITICAL: {count}
- HIGH: {count}
- MEDIUM: {count}
- LOW: {count}
### CRITICAL Issues
#### Issue 1: {Title}
- **Category**: YAML | XML | Security | Completeness
- **Description**: What's wrong
- **Impact**: Why it matters
- **Fix**: How to fix it
- **Location**: Section/line reference
### HIGH Priority Issues
[Same format]
### Approval Decision
**Status**: PASS | CONDITIONAL | FAIL
**Rationale**: Why this status
- 0 CRITICAL issues
- 0-2 HIGH issues
- All core sections present
- 0 CRITICAL issues
- 3-5 HIGH issues
- Core functionality works
- 1+ CRITICAL issues
- OR 6+ HIGH issues
- Blocks functionality
```
---
## Orchestrator Phase Pattern (Commands)
```xml
Clear statement of what this phase achieves
Mark PHASE 1 as in_progress in TodoWrite
Detailed action step
Detailed action step
Mark PHASE 1 as completed
Exit criteria - what must be true to proceed
ALL design → architect agent
ALL implementation → developer agent
ALL reviews → reviewer agent
```
---
## Agent Templates
### Planner Template
```yaml
---
name: {domain}-architect
description: |
Plans {domain} features with comprehensive design.
Examples: (1) "Design X" (2) "Plan Y" (3) "Architect Z"
model: sonnet
color: purple
tools: TodoWrite, Read, Write, Glob, Grep, Bash
---
```
### Implementer Template
```yaml
---
name: {domain}-developer
description: |
Implements {domain} features with quality checks.
Examples: (1) "Create X" (2) "Build Y" (3) "Implement Z"
model: sonnet
color: green
tools: TodoWrite, Read, Write, Edit, Bash, Glob, Grep
---
```
### Reviewer Template
```yaml
---
name: {domain}-reviewer
description: |
Reviews {domain} code for quality and standards.
Examples: (1) "Review X" (2) "Validate Y" (3) "Check Z"
model: sonnet
color: cyan
tools: TodoWrite, Read, Glob, Grep, Bash
---
```
### Orchestrator Template
```yaml
---
description: |
Orchestrates {workflow} with multi-agent coordination.
Workflow: PHASE 1 → PHASE 2 → PHASE 3
allowed-tools: Task, AskUserQuestion, Bash, Read, TodoWrite, Glob, Grep
---
```