#70
Intelligent model routing for Claude Code
Problem
When running Ralph with Claude Code, all stories use the same model regardless of complexity. This means:
- Simple tasks (text changes, config tweaks) use expensive Opus tokens unnecessarily
- Complex tasks that need Opus get the same treatment as trivial ones
- No way to optimize for cost vs. quality tradeoffs
Proposed Solution
Add intelligent model routing that assigns the appropriate Claude model (opus/sonnet/haiku) to each user story based on complexity and risk.
Two modes:
--mode max-quality: Opus for everything (current behavior, default)--mode cost-efficient: Right model for each story (explicit choice)
Key design decisions:
- Opus is always the "orchestrator" that analyzes stories and assigns models during PRD conversion
- Decision principle: when in doubt, round up (prefer more capable models when uncertain)
- Users can override any assignment by editing
prd.jsonbefore running
Model assignment criteria:
opus: Schema changes, auth, payments, complex logic, any uncertaintysonnet: Standard CRUD, typical UI, well-defined scopehaiku: Trivial text changes, obvious pattern repetition, config tweaks
Auto-escalation: If a story fails twice, Ralph automatically escalates to a more capable model:
- haiku → sonnet (after 2 failures) → opus (after 4 failures)
- sonnet → opus (after 2 failures)
This self-corrects when the assigned model can't handle a task.
Implementation
I have a working implementation ready that touches:
ralph.sh- adds--modeflag, model selection, and auto-escalationskills/ralph/SKILL.md- model assignment rules for PRD conversionprd.jsonschema - addsmodelandfailuresfields to stories- Documentation updates
Open to feedback on the approach.
Activity
0No activity yet.