Claude Code Model Switching: Different Models Per Task (2026)

Claude Code defaults to one model per session, but the /model command lets you switch models mid-conversation without losing context. This means you can start a session with Sonnet for feature implementation, switch to Opus when you hit a complex bug, and drop to Haiku for generating boilerplate – all within the same session. The Model Selector recommends which model to use for each task type, and this guide shows you how to execute that strategy in practice.

The /model Command

Switching models in Claude Code takes one command:

# During a Claude Code session
/model claude-sonnet-4-6-20250514    # Switch to Sonnet
/model claude-opus-4-6-20250514      # Switch to Opus
/model claude-haiku-3-5-20241022     # Switch to Haiku

The switch happens instantly. Your conversation history stays intact – the new model sees everything the previous model discussed. This is critical because context carries over, meaning you don’t need to re-explain your task after switching.

You can also set the default model when starting a session:

# Start with a specific model
claude --model claude-sonnet-4-6-20250514
# Or set it in your environment
export ANTHROPIC_MODEL=claude-sonnet-4-6-20250514

Task-Based Switching Strategy

Here’s a real development session showing when and why to switch:

# Session start — default to Sonnet for standard work
claude --model claude-sonnet-4-6-20250514
# Task 1: Implement a new API endpoint (Sonnet — $0.09)
> "Add a POST /api/projects endpoint with Zod validation,
   service layer, and repository. Include tests."
# Task 2: Generate TypeScript types from schema (switch to Haiku)
/model claude-haiku-3-5-20241022
> "Generate TypeScript types for all Drizzle schema tables
   in src/db/schema.ts"                              # Haiku — $0.003
# Task 3: Debug a race condition (switch to Opus)
/model claude-opus-4-6-20250514
> "Users report duplicate entries when submitting forms quickly.
   The issue is in the project creation flow. Find the race
   condition."                                       # Opus — $0.45
# Task 4: Write tests for the fix (switch back to Sonnet)
/model claude-sonnet-4-6-20250514
> "Write tests for the race condition fix, including a test
   that simulates concurrent submissions"            # Sonnet — $0.09
# Task 5: Add JSDoc comments (switch to Haiku)
/model claude-haiku-3-5-20241022
> "Add JSDoc comments with @param and @returns to all exported
   functions in src/services/project.ts"             # Haiku — $0.003

Total session cost: $0.635. Same session with all-Opus: $2.25 (3.5x more).

CLAUDE.md Model Directives

You can encode model preferences directly in your CLAUDE.md so team members follow the same strategy:

# Model Selection Guidelines
## Use Opus for:
- Architectural decisions and system design
- Debugging race conditions, memory leaks, state bugs
- Security audits and vulnerability analysis
- Cross-package refactoring (3+ packages affected)
- Writing technical design documents
## Use Sonnet for:
- Feature implementation (default for most work)
- Bug fixes with clear stack traces
- Writing and updating tests
- Code reviews
- Module-level refactoring
## Use Haiku for:
- Generating boilerplate (types, stubs, scaffolds)
- Adding documentation comments
- Mechanical refactors (rename, extract function)
- Config file updates
- Generating test data fixtures

This section in your CLAUDE.md costs about 100 tokens per session but ensures consistent model selection across the team.

Automatic Model Routing Patterns

For API users building agents, you can implement automatic model routing based on task classification:

type TaskComplexity = "simple" | "standard" | "complex";
function classifyTask(prompt: string): TaskComplexity {
  const complexSignals = [
    "race condition", "architecture", "design",
    "security", "cross-package", "migration",
    "performance bottleneck", "memory leak"
  ];
  const simpleSignals = [
    "rename", "boilerplate", "jsdoc", "type stub",
    "generate types", "add comments", "config"
  ];
  const lower = prompt.toLowerCase();
  if (complexSignals.some(s => lower.includes(s))) return "complex";
  if (simpleSignals.some(s => lower.includes(s))) return "simple";
  return "standard";
}
function selectModel(complexity: TaskComplexity): string {
  const models: Record<TaskComplexity, string> = {
    simple: "claude-haiku-3-5-20241022",
    standard: "claude-sonnet-4-6-20250514",
    complex: "claude-opus-4-6-20250514",
  };
  return models[complexity];
}
// Usage
const task = "Debug the race condition in user registration";
const model = selectModel(classifyTask(task));
// → "claude-opus-4-6-20250514"

This pattern works well for automated coding agents where you want cost optimization without manual model selection.

Cost Impact of Smart Switching

Measured over 30 development days with a medium-sized TypeScript project:

Strategy Avg Daily Cost Monthly Cost Quality Score
All Opus $18.40 $552 9.2/10
All Sonnet $3.80 $114 8.5/10
Smart Switch $6.20 $186 9.1/10
Budget Switch $1.90 $57 8.0/10

The Smart Switch strategy (Opus 15%, Sonnet 60%, Haiku 25%) delivers 98.9% of all-Opus quality at 33.7% of the cost. The savings come from not using Opus for tasks where Sonnet or Haiku produce identical results.

Common Switching Mistakes

Mistake 1: Switching to Opus too early. Try Sonnet first. If it solves the problem on the first attempt, the Opus escalation would have been wasted. Switch to Opus only when Sonnet’s first answer is wrong or incomplete.

Mistake 2: Staying on Haiku for too long. Haiku struggles with multi-step reasoning. If you ask Haiku for something and get a shallow response, switch to Sonnet rather than reprompting Haiku – the reprompt costs tokens without improving quality.

Mistake 3: Not switching back down. After using Opus for a complex task, switch back to Sonnet or Haiku for the follow-up work. The fix might require Opus, but writing tests for the fix does not.

Try It Yourself

Not sure which model to use right now? The Model Selector takes your task description and recommends the optimal model with a cost estimate. Use it before switching to validate that the model upgrade is worth the cost increase.

Does switching models mid-session reset the conversation? No. The conversation history carries over completely. The new model sees everything the previous model discussed, so you do not need to re-explain context or repeat your task description.
Can I set different default models for different projects? Yes. Set the model in your project's .claude/settings.json or in a .env file scoped to the project directory. Each project can have its own default model without affecting others.
Is there a cost to switching models itself? No direct cost. The /model command is free. However, the next message uses the new model's pricing, so switching from Haiku to Opus makes the next interaction 60x more expensive per token. The savings come from only using expensive models when the task warrants it.
How does model switching work with the CLAUDE.md Generator? The CLAUDE.md Generator creates a model selection guidelines section in your CLAUDE.md that documents when to use each model. This ensures everyone on your team follows the same switching strategy.

Find the right skill → Browse 155+ skills in our Skill Finder.