Smart Model Route
Classifies each incoming prompt and injects a systemMessage telling the AI which model to pass to Agent tool calls and what reasoning depth to use. Uses Haiku for classification when ANTHROPIC_API_KEY is available; otherwise falls back to keyword heuristics.
How It Works
UserPromptSubmit hook fires on every prompt
- Sends prompt to
claude-haiku-4-5 with a classification system prompt
- Returns
low | medium | high | critical
- Injects a
[AUTO:haiku] or [AUTO:heuristic] system message for non-medium tasks
- Claude uses this to calibrate reasoning depth and
model: parameter on Agent calls
Classification Rules
| Level |
Signals |
Agent model |
| low |
Search, grep, read, git status, quick questions, <20 words |
claude-haiku-4-5 |
| medium |
Standard coding, bug fixes, typical tasks (default) |
claude-haiku-4-5 (env) |
| high |
Implement, refactor, debug, optimize, PR review, >15 words |
claude-sonnet-4-6 |
| critical |
Security, OAuth, CVE, arch decisions, prod deploys, migrations |
claude-opus-4-7 |
Installation
- Copy
complexity-classifier.sh to ~/.claude/hooks/
- Make it executable:
chmod +x ~/.claude/hooks/complexity-classifier.sh
- Add to
settings.json:
"UserPromptSubmit": [{
"matcher": "*",
"hooks": [{
"type": "command",
"command": "/path/to/hooks/complexity-classifier.sh",
"timeout": 5
}]
}]
- To enable Haiku-based classification (vs heuristic fallback):
"env": {
"ANTHROPIC_API_KEY": "your-key"
}
Or to route through a local LiteLLM / Ollama proxy (set these to your own host + key):
"env": {
"ANTHROPIC_API_KEY": "${LITELLM_MASTER_KEY}",
"ANTHROPIC_BASE_URL": "http://<your-litellm-host>:4000"
}
Using in Agent Calls
Once the hook is active, Claude reads the injected hint and applies it:
# For clearly simple tasks (override default)
Agent(model="haiku", prompt="search for all TODO comments")
# For complex tasks (override default)
Agent(model="opus", prompt="design the auth architecture for multi-tenant SaaS")
Session Model Override
For architecture or security sessions, switch the main model:
/model claude-opus-4-7
Switch back when done:
/model claude-sonnet-4-6
Dependencies
anthropic Python SDK (for Haiku classification): pip install anthropic
- Heuristic fallback requires no dependencies
1---2name: smart-model-route3description: Auto-classify prompt complexity via Haiku (with heuristic fallback) and inject model routing hints for Agent tool calls. Wired as a UserPromptSubmit hook — fires on every prompt, routes low tasks to Haiku, standard to Sonnet, complex to Sonnet with thorough reasoning, and critical (security/arch/migrations) to Opus.4---56# Smart Model Route78Classifies each incoming prompt and injects a `systemMessage` telling the AI which model to pass to `Agent` tool calls and what reasoning depth to use. Uses Haiku for classification when `ANTHROPIC_API_KEY` is available; otherwise falls back to keyword heuristics.910## How It Works11121. `UserPromptSubmit` hook fires on every prompt132. Sends prompt to `claude-haiku-4-5` with a classification system prompt143. Returns `low | medium | high | critical`154. Injects a `[AUTO:haiku]` or `[AUTO:heuristic]` system message for non-medium tasks165. Claude uses this to calibrate reasoning depth and `model:` parameter on Agent calls1718## Classification Rules1920| Level | Signals | Agent model |21|-------|---------|-------------|22| **low** | Search, grep, read, git status, quick questions, <20 words | `claude-haiku-4-5` |23| **medium** | Standard coding, bug fixes, typical tasks (default) | `claude-haiku-4-5` (env) |24| **high** | Implement, refactor, debug, optimize, PR review, >15 words | `claude-sonnet-4-6` |25| **critical** | Security, OAuth, CVE, arch decisions, prod deploys, migrations | `claude-opus-4-7` |2627## Installation28291. Copy `complexity-classifier.sh` to `~/.claude/hooks/`302. Make it executable: `chmod +x ~/.claude/hooks/complexity-classifier.sh`313. Add to `settings.json`:3233```json34"UserPromptSubmit": [{35 "matcher": "*",36 "hooks": [{37 "type": "command",38 "command": "/path/to/hooks/complexity-classifier.sh",39 "timeout": 540 }]41}]42```43444. To enable Haiku-based classification (vs heuristic fallback):4546```json47"env": {48 "ANTHROPIC_API_KEY": "your-key"49}50```5152Or to route through a local LiteLLM / Ollama proxy (set these to your own host + key):5354```json55"env": {56 "ANTHROPIC_API_KEY": "${LITELLM_MASTER_KEY}",57 "ANTHROPIC_BASE_URL": "http://<your-litellm-host>:4000"58}59```6061## Using in Agent Calls6263Once the hook is active, Claude reads the injected hint and applies it:6465```python66# For clearly simple tasks (override default)67Agent(model="haiku", prompt="search for all TODO comments")6869# For complex tasks (override default)70Agent(model="opus", prompt="design the auth architecture for multi-tenant SaaS")71```7273## Session Model Override7475For architecture or security sessions, switch the main model:7677```78/model claude-opus-4-779```8081Switch back when done:8283```84/model claude-sonnet-4-685```8687## Dependencies8889- `anthropic` Python SDK (for Haiku classification): `pip install anthropic`90- Heuristic fallback requires no dependencies