How to Change the Model in Claude Code
Claude Code — Anthropic's AI-powered coding assistant that runs in your terminal — doesn't lock you into a single model. You can switch between available Claude models depending on what your task demands. Whether you need faster responses for quick edits or deeper reasoning for complex refactoring, understanding how model selection works gives you meaningful control over your workflow.
What "Changing the Model" Actually Means
Claude Code uses Anthropic's API under the hood. When you run Claude Code, it sends your requests to a specific Claude model — such as Claude Opus, Claude Sonnet, or Claude Haiku. These models sit on a spectrum:
- Opus — highest capability, strongest at complex reasoning, architecture decisions, and multi-step problem solving
- Sonnet — balanced performance, strong coding ability with faster response times
- Haiku — lightweight and fast, well-suited to simple completions, quick lookups, and repetitive tasks
Switching the model means directing Claude Code to route your requests through a different one of these engines. The interface stays the same — only the model powering your responses changes.
How to Change the Model in Claude Code
Method 1: The --model Flag at Launch
The most direct way is to pass the --model flag when starting a session:
claude --model claude-opus-4-5 or
claude --model claude-haiku-4-5 Use the exact model identifier string that Anthropic supports. These identifiers follow a naming convention like claude-[name]-[version]. Check Anthropic's official documentation for the current list of available model identifiers, as these update when new versions ship.
Method 2: Setting a Default Model via Environment Variable
If you consistently prefer one model over another, you can set a default so you don't have to specify it every session:
export ANTHROPIC_MODEL=claude-sonnet-4-5 Add this line to your shell configuration file (.bashrc, .zshrc, or equivalent) to make it persist across terminal sessions. Claude Code will read this environment variable on launch.
Method 3: Switching Models Mid-Session
Within an active Claude Code session, you can change the model using the /model command:
/model claude-opus-4-5 This is useful when a task escalates in complexity — you might start with Haiku for lightweight scaffolding, then switch to Opus when you hit a gnarly architecture problem, without restarting your session.
Method 4: Project-Level Configuration
Claude Code supports a configuration file (typically claude.json or project-level settings depending on your version) where you can specify a preferred model for a given project directory. This means your frontend repo could default to Sonnet while a research-heavy data science project defaults to Opus — automatically, based on which directory you're working in.
Check the Claude Code docs for the exact config file format, as this has evolved across releases.
🔍 Factors That Affect Which Model Makes Sense
Model selection isn't purely about raw capability. Several variables shape what "the right choice" actually looks like in practice:
| Factor | Why It Matters |
|---|---|
| Task complexity | Multi-file refactoring or debugging subtle logic errors benefits from Opus; auto-completing boilerplate doesn't |
| Response speed requirements | Haiku returns responses significantly faster — relevant in tight iteration loops |
| API cost structure | Different models carry different token costs; high-volume usage amplifies this difference |
| Context window needs | Some tasks require processing large codebases in one pass; model context limits vary |
| Rate limits on your plan | Your Anthropic API tier may restrict access to certain models or cap usage |
The Variables That Differ Between Users 🛠️
Two developers using Claude Code for "coding help" can have genuinely different needs that point toward different model choices:
- A solo developer prototyping quickly might prioritize speed and cost, making Haiku or Sonnet the practical default
- A senior engineer doing architecture review or debugging production incidents may need Opus's deeper reasoning even if it's slower
- Someone working in a resource-constrained environment (metered API budget, corporate account limits) may not have open access to all tiers
- Users on older Claude Code versions may have a different set of available model identifiers than those on the latest release
The /model command and --model flag are consistent mechanisms, but which identifiers are valid — and which are accessible on your account — depends on your Anthropic API plan and the version of Claude Code you have installed.
Keeping Model Identifiers Current
One practical pitfall: model identifier strings change when Anthropic releases new versions. A model ID that worked six months ago may be deprecated. If Claude Code returns an error when specifying a model, verify the current identifier against Anthropic's API documentation rather than assuming the flag syntax is wrong.
Running claude --help or checking the in-session /help command may surface available options depending on your installed version.
💡 What Stays the Same Regardless of Model
Switching models doesn't change how you interact with Claude Code. Your commands, file context, conversation history within a session, and workflow all remain identical. The model is effectively a swappable reasoning engine — the tooling wrapping it stays consistent.
What does shift is the quality of reasoning on hard problems, token processing speed, and the cost per request on your API bill. Those differences are real and meaningful, but they only matter in the context of what you're actually building, how often you're using it, and what your account allows.
Your specific stack, usage patterns, and access tier are the pieces of the picture that no general guide can fill in.