โ† Back to Web & Frontend Development

smart-model-switching

Auto-route tasks to the cheapest Claude model

0
Source Code

Smart Model Switching

Three-tier Claude routing: Haiku โ†’ Sonnet โ†’ Opus

Start with the cheapest model. Escalate only when needed. Save 50-90% on API costs.

The Golden Rule

If a human would need more than 30 seconds of focused thinking, escalate from Haiku to Sonnet. If the task involves architecture, complex tradeoffs, or deep reasoning, escalate to Opus.

Cost Reality

Model Input Output Relative Cost
Haiku $0.25/M $1.25/M 1x (baseline)
Sonnet $3.00/M $15.00/M 12x
Opus $15.00/M $75.00/M 60x

Bottom line: Wrong model selection wastes money OR time. Haiku for simple, Sonnet for standard, Opus for complex.


๐Ÿ’š HAIKU โ€” Default for Simple Tasks

Stay on Haiku for:

  • Factual Q&A โ€” "what is X", "who is Y", "when did Z"
  • Quick lookups โ€” definitions, unit conversions, short translations
  • Status checks โ€” calendar, file reads, session monitoring
  • Heartbeats โ€” periodic checks, HEARTBEAT_OK responses
  • Memory & reminders โ€” "remember this", "remind me to..."
  • Casual conversation โ€” greetings, small talk, acknowledgments
  • Simple file ops โ€” read, list, basic writes
  • One-liner tasks โ€” anything answerable in 1-2 sentences

NEVER do these on Haiku

  • โŒ Write code longer than 10 lines
  • โŒ Create comparison tables
  • โŒ Write more than 3 paragraphs
  • โŒ Do multi-step analysis
  • โŒ Write reports or proposals

๐Ÿ’› SONNET โ€” Standard Work (The Workhorse)

Escalate to Sonnet for:

Code & Technical

  • Code generation โ€” write functions, build features, scripts
  • Code review โ€” PR reviews, quality checks
  • Debugging โ€” standard bug investigation
  • Documentation โ€” README, comments, user guides

Analysis & Planning

  • Analysis & evaluation โ€” compare options, assess trade-offs
  • Planning โ€” project plans, roadmaps, task breakdowns
  • Research synthesis โ€” combining multiple sources
  • Multi-step reasoning โ€” "first... then... finally"

Writing & Content

  • Long-form writing โ€” reports, proposals, articles (>3 paragraphs)
  • Creative writing โ€” blog posts, descriptions, copy
  • Summarization โ€” long documents, transcripts
  • Structured output โ€” tables, outlines, formatted docs

โค๏ธ OPUS โ€” Complex Reasoning Only

Escalate to Opus for:

Architecture & Design

  • System architecture decisions
  • Major codebase refactoring
  • Design pattern selection with tradeoffs
  • Database schema design

Deep Analysis

  • Complex debugging (multi-file, race conditions)
  • Security reviews
  • Performance optimization strategy
  • Root cause analysis of subtle bugs

Strategic & Creative

  • Strategic planning โ€” business decisions, roadmaps
  • Nuanced judgment โ€” ethics, ambiguity, competing values
  • Deep research โ€” comprehensive multi-source analysis

๐Ÿ”„ Implementation

For Subagents

```javascript // Routine monitoring sessions_spawn(task="Check backup status", model="haiku")

// Standard code work
sessions_spawn(task="Build the REST API endpoint", model="sonnet")

// Architecture decisions sessions_spawn(task="Design the database schema for multi-tenancy", model="opus") ```

For Cron Jobs

```json { "payload": { "kind": "agentTurn", "model": "haiku" } } ``` Always use Haiku for cron unless the task genuinely needs reasoning.


๐Ÿ“Š Quick Decision Tree

``` Is it a greeting, lookup, status check, or 1-2 sentence answer? YES โ†’ HAIKU NO โ†“

Is it code, analysis, planning, writing, or multi-step? YES โ†’ SONNET
NO โ†“

Is it architecture, deep reasoning, or critical decision? YES โ†’ OPUS NO โ†’ Default to SONNET, escalate if struggling ```


๐Ÿ“‹ Quick Reference Card

``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ SMART MODEL SWITCHING โ”‚ โ”‚ Haiku โ†’ Sonnet โ†’ Opus โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ ๐Ÿ’š HAIKU (cheapest) โ”‚ โ”‚ โ€ข Greetings, status checks, quick lookups โ”‚ โ”‚ โ€ข Factual Q&A, definitions, reminders โ”‚ โ”‚ โ€ข Simple file ops, 1-2 sentence answers โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ ๐Ÿ’› SONNET (standard) โ”‚ โ”‚ โ€ข Code > 10 lines, debugging โ”‚ โ”‚ โ€ข Analysis, comparisons, planning โ”‚ โ”‚ โ€ข Reports, proposals, long writing โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ โค๏ธ OPUS (complex) โ”‚ โ”‚ โ€ข Architecture decisions โ”‚ โ”‚ โ€ข Complex debugging, multi-file refactoring โ”‚ โ”‚ โ€ข Strategic planning, deep research โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ ๐Ÿ’ก RULE: If a human needs > 30 sec thinking โ†’ escalate โ”‚ โ”‚ ๐Ÿ’ฐ COST: Haiku 1x โ†’ Sonnet 12x โ†’ Opus 60x โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ```


Built for Claude-only setups with Haiku, Sonnet, and Opus. Inspired by save-money skill, extended with three-tier progression.