You can change which Claude model Claude Code uses by selecting a different model from the dropdown menu in your settings, or by editing your configuration file directly

Claude Code — Anthropic's coding assistant built into Claude — defaults to Claude 3.5 Sonnet, which is the fastest model for most coding tasks. If you need a different model for a specific project, you can switch between Claude 3.5 Sonnet, Claude 3 Opus, and Claude 3 Haiku without leaving your workspace. The change takes effect on your next message.

The model you choose affects how long responses take, how much context the model can hold, and what you pay per token. Sonnet balances speed and capability. Opus handles longer files and more complex reasoning but costs more and runs slower. Haiku is the fastest and cheapest but struggles with large codebases or intricate problems.

Key Takeaways

  • Switch models through the settings menu in Claude Code, or by editing your .claude configuration file in your project root.
  • Claude 3.5 Sonnet is the default and works best for most coding; Opus is stronger on complex logic but slower; Haiku is fastest for simple tasks.
  • The model change applies only to new messages, not to previous conversation history.
  • Your API usage and cost depend on which model you select, so switching to Haiku or Opus changes what you pay per interaction.

Changing the model through the Claude Code interface

Open Claude Code in your browser and look for the settings icon — usually a gear symbol in the top right or bottom left of the window, depending on your layout. Click it and find the "Model" dropdown. The current model name appears in the dropdown; click it to see all available options.

Select the model you want. Claude Code will confirm the change and remember your choice for future sessions in that workspace. If you are working on a shared project, your model choice is personal to your account and does not affect what your teammates see.

Changing the model in your configuration file

If you prefer to version-control your model choice or set it per project, you can create or edit a .claude file in your project root directory. This is a plain text file that Claude Code reads when it starts.

Add this line to the file:

model: claude-3-5-sonnet-20241022

Replace the model name with one of these options:

  • claude-3-5-sonnet-20241022 — the default, balanced for speed and reasoning
  • claude-3-opus-20250219 — strongest reasoning, slowest, highest cost
  • claude-3-haiku-20250307 — fastest, lowest cost, limited context window

Save the file. Claude Code will use this model the next time you start a conversation in that project. If both the interface setting and the .claude file specify a model, the file takes precedence.

When to use each model

Use Claude 3.5 Sonnet for most work. It handles typical coding tasks — writing functions, debugging, refactoring — faster than Opus and with better reasoning than Haiku. It is the right default unless you hit a specific limitation.

Switch to Claude 3 Opus when you are working with a large codebase, need to reason through a complex algorithm, or are asking Claude Code to hold multiple files in context at once. Opus has a larger context window (200,000 tokens versus Sonnet's 200,000 tokens, though Opus uses them more effectively for reasoning). It costs more per token and takes longer to respond, so use it only when Sonnet struggles.

Use Claude 3 Haiku for quick, simple tasks: writing a short script, explaining a syntax error, or generating boilerplate. It responds in seconds and costs the least, but it cannot hold as much code in memory and will refuse complex requests.

What happens when you switch models mid-project

Changing the model does not affect messages you have already sent or received. Your conversation history stays the same. Only new messages use the new model.

If you were working on a problem with Sonnet and switch to Haiku, Haiku will see the full conversation but may not be able to continue if the task is too complex. If you switch from Haiku to Opus, Opus will have the same context and can usually pick up where Haiku left off, but may approach the problem differently.

There is no penalty for switching back and forth. You can use Haiku for a quick question, then switch to Sonnet for the next task, all in the same conversation.

Understanding token usage and cost differences

Each model charges different rates per token. Haiku is the cheapest, Sonnet is mid-range, and Opus is the most expensive. The exact prices depend on whether you are using Claude through Anthropic's API, a third-party platform, or a subscription plan.

Token usage also varies by model. A response from Opus might use more tokens than the same response from Sonnet because Opus does more reasoning work. If you are on a limited budget or token quota, switching to Haiku or Sonnet can stretch your resources further.

Check your usage dashboard in your Claude account to see how many tokens each model has consumed. Most platforms show this breakdown by model, so you can track which choice costs the most over time.

Troubleshooting model switching issues

If the model dropdown is grayed out or does not show all three options, you may not have access to all models on your account. Anthropic sometimes limits model access by plan or region. Check your account settings or contact support to confirm which models are available to you.

If you edited the .claude file but Claude Code is still using the old model, make sure the file is in your project root (the top-level folder), not in a subdirectory. Also check that the model name is spelled exactly as listed above — Claude Code will ignore the file if the name does not match.

If Claude Code crashes or becomes unresponsive after switching to Opus, it may be running out of memory on your machine. Opus uses more RAM than Sonnet. Try switching back to Sonnet or closing other applications to free up memory.

Frequently Asked Questions

Can I set a different model for different files in the same project?

No. The model setting applies to your entire Claude Code session. You can switch models between conversations or projects, but not per file. If you need different models for different tasks, open a separate Claude Code window or conversation.

Will switching to Opus make Claude Code understand my code better?

Opus is stronger at reasoning through complex logic and can hold more context, so it may catch bugs or suggest improvements that Sonnet misses. But for most coding tasks, Sonnet is sufficient. Test with Opus on a hard problem to see if it makes a difference for your work.

What if I want to use a model that is not in the dropdown?

Claude Code only supports Claude 3 Haiku, Sonnet, and Opus. If you need a different model, you would need to use the Claude API directly or a different tool. Anthropic may add new models to Claude Code in the future.

Does changing the model affect my API costs if I am using Claude Code through an API?

Yes. If you are running Claude Code through the Anthropic API or a platform that bills per token, switching to a more expensive model will increase your costs. Haiku is cheapest, Sonnet is mid-range, and Opus is most expensive.