Model Routing System
You have access to intelligent model routing. Before executing any task, analyze complexity and route to the appropriate model tier.
Routing Decision Matrix
TASK COMPLEXITY ANALYSIS
────────────────────────────────────────────────────────────────
HAIKU (Fast, Cheap) - Use for:
├── Simple file operations (read, list, navigate)
├── Scaffolding and boilerplate generation
├── Deterministic transformations (format, lint, compile)
├── Status checks and health monitoring
├── SEO metadata generation
├── Deployment commands (after code is written)
├── Documentation formatting
├── Simple search and replace
│
│ Token cost: ~$0.25/1M input, $1.25/1M output
│ Latency: Fastest
│ Use when: Task has clear, unambiguous steps
SONNET (Balanced) - Use for:
├── Feature implementation (standard complexity)
├── Bug fixes requiring analysis
├── Content writing (articles, social posts)
├── Code review and quality checks
├── Test generation
├── Refactoring with clear patterns
├── API integration work
├── Database schema design
│
│ Token cost: ~$3/1M input, $15/1M output
│ Latency: Medium
│ Use when: Task requires reasoning but not deep strategy
OPUS (Strategic, Complex) - Use for:
├── Architecture decisions (system design)
├── Multi-agent coordination (council, swarm)
├── Strategic planning (business, product)
├── Complex debugging (multi-file, subtle bugs)
├── Security audits and vulnerability analysis
├── Enterprise AI system design
├── Book writing (narrative, character development)
├── Research synthesis (multiple sources)
├── Ambiguous requirements interpretation
│
│ Token cost: ~$15/1M input, $75/1M output
│ Latency: Slowest but most capable
│ Use when: Task requires deep reasoning, creativity, or strategy
Automatic Routing Rules
When processing a request, apply these rules:
Route to HAIKU when:
- User says: "deploy", "format", "lint", "check status", "list", "scaffold"
- File patterns:
*.config.*, package.json, tsconfig.json
- Commands:
/mcp-status, /inventory-status, /nextjs-deploy (execution phase)
Route to SONNET when:
- User says: "write", "implement", "fix", "create", "build", "test"
- File patterns:
*.ts, *.tsx, *.py, *.md (content files)
- Commands:
/article-creator, /create-music, /spec, /generate-social
Route to OPUS when:
- User says: "design", "architect", "strategy", "council", "analyze", "research"
- Keywords: "enterprise", "system", "multi-agent", "complex", "strategic"
- Commands:
/starlight-architect, /council, /author-team, /research
Cost Optimization
BEFORE (No routing):
All tasks → Opus → $75/1M output tokens
AFTER (With routing):
Simple tasks (40%) → Haiku → $1.25/1M = $0.50
Medium tasks (45%) → Sonnet → $15/1M = $6.75
Complex tasks (15%) → Opus → $75/1M = $11.25
──────────────────────────────────────────────
TOTAL: $18.50 vs $75 = 75% cost reduction
Implementation in Task Tool
When using the Task tool, specify model based on routing:
// Simple task - use haiku
Task({
subagent_type: "Explore",
model: "haiku",
prompt: "List all files in src/"
})
// Medium task - use sonnet (default)
Task({
subagent_type: "code-reviewer",
model: "sonnet",
prompt: "Review this PR for issues"
})
// Complex task - use opus
Task({
subagent_type: "Plan",
model: "opus",
prompt: "Design the architecture for a multi-tenant SaaS platform"
})
Command-Level Routing
| Command |
Default Model |
Rationale |
/acos |
sonnet |
Router needs reasoning |
/article-creator |
sonnet |
Content creation |
/create-music |
sonnet |
Creative work |
/infogenius |
sonnet |
Research + creation |
/starlight-architect |
opus |
Strategic design |
/council |
opus |
Multi-perspective |
/research |
sonnet |
Information synthesis |
/spec |
sonnet |
Feature planning |
/nextjs-deploy |
haiku |
Execution |
/mcp-status |
haiku |
Status check |
/inventory-status |
haiku |
Status check |
/publish |
haiku |
Execution |
/polish-content |
sonnet |
Editing |
/review-content |
sonnet |
Quality check |
Escalation Pattern
If a haiku-routed task fails or produces poor results:
- Automatically escalate to sonnet
- If still failing, escalate to opus
- Log escalation for learning
haiku (attempt) → fail → sonnet (retry) → fail → opus (final)
Model Routing v1.0 - Implementing claude-flow's intelligent routing pattern
1---2name: model-routing3description: Intelligent model selection - routes tasks to Haiku (fast/cheap), Sonnet (balanced), or Opus (complex/strategic) based on task complexity analysis4---5
6# Model Routing System
7
8You have access to intelligent model routing. Before executing any task, analyze complexity and route to the appropriate model tier.
9
10## Routing Decision Matrix
11
12```
13TASK COMPLEXITY ANALYSIS
14────────────────────────────────────────────────────────────────
15
16HAIKU (Fast, Cheap) - Use for:
17├── Simple file operations (read, list, navigate)
18├── Scaffolding and boilerplate generation
19├── Deterministic transformations (format, lint, compile)
20├── Status checks and health monitoring
21├── SEO metadata generation
22├── Deployment commands (after code is written)
23├── Documentation formatting
24├── Simple search and replace
25│
26│ Token cost: ~$0.25/1M input, $1.25/1M output
27│ Latency: Fastest
28│ Use when: Task has clear, unambiguous steps
29
30SONNET (Balanced) - Use for:
31├── Feature implementation (standard complexity)
32├── Bug fixes requiring analysis
33├── Content writing (articles, social posts)
34├── Code review and quality checks
35├── Test generation
36├── Refactoring with clear patterns
37├── API integration work
38├── Database schema design
39│
40│ Token cost: ~$3/1M input, $15/1M output
41│ Latency: Medium
42│ Use when: Task requires reasoning but not deep strategy
43
44OPUS (Strategic, Complex) - Use for:
45├── Architecture decisions (system design)
46├── Multi-agent coordination (council, swarm)
47├── Strategic planning (business, product)
48├── Complex debugging (multi-file, subtle bugs)
49├── Security audits and vulnerability analysis
50├── Enterprise AI system design
51├── Book writing (narrative, character development)
52├── Research synthesis (multiple sources)
53├── Ambiguous requirements interpretation
54│
55│ Token cost: ~$15/1M input, $75/1M output
56│ Latency: Slowest but most capable
57│ Use when: Task requires deep reasoning, creativity, or strategy
58```
59
60## Automatic Routing Rules
61
62When processing a request, apply these rules:
63
64### Route to HAIKU when:
65- User says: "deploy", "format", "lint", "check status", "list", "scaffold"
66- File patterns: `*.config.*`, `package.json`, `tsconfig.json`
67- Commands: `/mcp-status`, `/inventory-status`, `/nextjs-deploy` (execution phase)
68
69### Route to SONNET when:
70- User says: "write", "implement", "fix", "create", "build", "test"
71- File patterns: `*.ts`, `*.tsx`, `*.py`, `*.md` (content files)
72- Commands: `/article-creator`, `/create-music`, `/spec`, `/generate-social`
73
74### Route to OPUS when:
75- User says: "design", "architect", "strategy", "council", "analyze", "research"
76- Keywords: "enterprise", "system", "multi-agent", "complex", "strategic"
77- Commands: `/starlight-architect`, `/council`, `/author-team`, `/research`
78
79## Cost Optimization
80
81```
82BEFORE (No routing):
83 All tasks → Opus → $75/1M output tokens
84
85AFTER (With routing):
86 Simple tasks (40%) → Haiku → $1.25/1M = $0.50
87 Medium tasks (45%) → Sonnet → $15/1M = $6.75
88 Complex tasks (15%) → Opus → $75/1M = $11.25
89 ──────────────────────────────────────────────
90 TOTAL: $18.50 vs $75 = 75% cost reduction
91```
92
93## Implementation in Task Tool
94
95When using the Task tool, specify model based on routing:
96
97```javascript
98// Simple task - use haiku
99Task({
100 subagent_type: "Explore",
101 model: "haiku",
102 prompt: "List all files in src/"
103})
104
105// Medium task - use sonnet (default)
106Task({
107 subagent_type: "code-reviewer",
108 model: "sonnet",
109 prompt: "Review this PR for issues"
110})
111
112// Complex task - use opus
113Task({
114 subagent_type: "Plan",
115 model: "opus",
116 prompt: "Design the architecture for a multi-tenant SaaS platform"
117})
118```
119
120## Command-Level Routing
121
122| Command | Default Model | Rationale |
123|---------|---------------|-----------|
124| `/acos` | sonnet | Router needs reasoning |
125| `/article-creator` | sonnet | Content creation |
126| `/create-music` | sonnet | Creative work |
127| `/infogenius` | sonnet | Research + creation |
128| `/starlight-architect` | **opus** | Strategic design |
129| `/council` | **opus** | Multi-perspective |
130| `/research` | sonnet | Information synthesis |
131| `/spec` | sonnet | Feature planning |
132| `/nextjs-deploy` | haiku | Execution |
133| `/mcp-status` | haiku | Status check |
134| `/inventory-status` | haiku | Status check |
135| `/publish` | haiku | Execution |
136| `/polish-content` | sonnet | Editing |
137| `/review-content` | sonnet | Quality check |
138
139## Escalation Pattern
140
141If a haiku-routed task fails or produces poor results:
1421. Automatically escalate to sonnet
1432. If still failing, escalate to opus
1443. Log escalation for learning
145
146```
147haiku (attempt) → fail → sonnet (retry) → fail → opus (final)
148```
149
150---
151
152*Model Routing v1.0 - Implementing claude-flow's intelligent routing pattern*