[FEATURE] Declarative phase-based model routing via CLAUDE.md and settings.json
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet (closest: #39282, #19269 — both are related but neither covers phase-based routing with declarative CLAUDE.md config and tool-event-driven detection)
- [x] This is a single feature request (not multiple features)
Problem Statement
Different task phases within a session have fundamentally different quality/cost requirements:
- Planning / architecture → requires deep reasoning (Opus)
- Implementation / coding → speed and quality balanced (Sonnet)
- Code review / final check → reasoning important again (Opus)
- Test runs / quick lookups → fast and cheap is fine (Haiku)
Currently the model is fixed for the entire session. Users who want optimal quality and cost must manually /model switch at each phase transition, which breaks flow and is easy to forget. Most users pick one model and accept the tradeoff.
Proposed Solution
Allow users to declare phase-to-model routing rules in CLAUDE.md or settings.json. Claude Code honors these rules automatically by detecting the current phase from tool event signals already emitted by the harness.
In CLAUDE.md:
## Model Routing
| Phase | Model |
|----------|--------------------|
| planning | claude-opus-4-6 |
| coding | claude-sonnet-4-6 |
| review | claude-opus-4-6 |
| testing | claude-haiku-4-5 |
Or in settings.json:
{
"modelRouting": {
"planning": "claude-opus-4-6",
"coding": "claude-sonnet-4-6",
"review": "claude-opus-4-6",
"testing": "claude-haiku-4-5"
}
}
Phase Detection (implementation suggestion)
Detection can be fully rule-based on tool event types — no LLM inference required:
| Tool event | Detected phase |
|---|---|
| EnterPlanMode fired | planning |
| Write or Edit tool called | coding |
| TodoWrite task marked completed | review |
| Bash call matching test runner pattern (pytest, jest, dotnet test, etc.) | testing |
Phase reverts to the session default when the signal clears. The harness already emits all these events; this is purely a routing layer on top.
Concrete Use Case
A team runs Claude Code on a multi-module refactor. They want:
- Opus-level reasoning when the session enters plan mode (architecture decisions matter)
- Sonnet for the bulk of file edits (fast, good enough)
- Opus again for a final review pass
- Haiku when running the test suite between iterations
Today this requires four manual /model switches and is unrealistic in practice. With declarative routing it's a one-time config in CLAUDE.md, version-controlled and shared across the team.
Why This Is Different From Existing Requests
- #39282 proposes automatic routing but without declarative config or CLAUDE.md integration — it relies on heuristic content detection rather than tool event signals
- #19269 proposes routing by skill name and tool name (per-invocation), not by task phase (per-session-segment)
This proposal focuses on the phase as the routing unit, detected from events the harness already produces, configured declaratively where project conventions already live.
Impact
Meaningful cost reduction without quality loss. Teams can encode their model strategy once and stop thinking about it.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗