Claude Code Model: How to Change, Select and Add Custom Models
Change the Claude Code model mid-session, set a permanent default, pin exact versions with tier variables, and route custom or open models through a gateway. Includes precedence tables, ready-to-paste settings and fixes for the errors people hit most.
You open a terminal, start a coding session, and the answers feel slow, expensive or just not sharp enough for the problem in front of you. Nine times out of ten the fix is not a better prompt. It is a different model. Claude Code lets you switch the model in three seconds, pin it for a whole team, or send traffic to something custom through a gateway. The catch is that the options live in five different places, and they override each other in ways that surprise people.
This article lays out every way to change, select and add custom models in Claude Code, in the order that actually matters: the quick in-session switch first, permanent defaults second, version pinning third, and custom gateways last. You will get copy-ready snippets, a precedence table, and a troubleshooting list built from the mistakes that show up again and again.
💡 Quick answer: type /model inside a session to switch now, or launch with claude --model <alias> for a single run. For a permanent default, set "model" in your settings.json or export ANTHROPIC_MODEL.
Why the Right Model Matters
A coding agent is only as useful as the model behind it. Claude Code reads files, plans edits, runs commands and checks its own work, and every one of those steps is a model call. Pick a heavyweight reasoning model for a typo fix and you burn time and budget. Pick a small fast model for a cross-repository refactor and you get confident, wrong edits.
Speed, Cost and Quality
Think of the choice as a triangle. You rarely get all three corners at once.
Priority
Typical pick
Best for
Speed
Small, fast tier
Renames, quick questions, log summaries
Balance
Mid tier
Daily feature work, tests, code review
Depth
Top reasoning tier
Architecture, hard bugs, multi-file refactors
Anthropic groups its models into three families, usually called Opus, Sonnet and Haiku, with the largest being the most capable and the smallest being the cheapest. Claude Code builds its aliases around exactly those families, which is why the shortcuts are so short.
What Changes Per Task
The same developer often needs all three corners in one afternoon. A morning of boilerplate wants a fast model. The afternoon bug that only happens under load wants the deepest one you can afford. That is why a per-session switch beats a single global default for most people, and why the next section comes before everything else.
How to Change Models in a Session
The /model Command
Inside a running session, type:
/model
Claude Code opens a picker with the models available to your account and provider. Move with the arrow keys and press Enter. You can also skip the picker and pass an alias or a full name directly:
/model opus
/model sonnet
/model haiku
The change applies to the current conversation immediately, so you can plan with a strong model and then drop to a cheaper one for execution without losing context. Depending on your version, the picker may also offer to save your choice as the default for new sessions, so read the prompt before you confirm.
💡 Tip:/model is the highest priority method. Whatever you set here beats the flag, the environment variable and the settings file for the rest of that session.
The --model Startup Flag
For a one-off run, pass the model when you launch:
claude --model opus
claude --model claude-sonnet-4-6
This is perfect for scripts, aliases in your shell profile, or a quick test of a different model on the same task. Nothing is written to disk, and the next plain claude launch goes back to your configured default.
Checking What Is Active
Do not assume. After any switch, confirm what the session is really using. The status command shows the active model, and the picker marks the current selection. This matters most when you are using a gateway or a pinned alias, because a silent fallback is the number one reason people think a change "did nothing."
Set a Default Model Permanently
If you open the same kind of work every day, stop switching by hand. There are two durable options.
Environment Variable
Set ANTHROPIC_MODEL in your shell profile:
# macOS or Linux
export ANTHROPIC_MODEL=sonnet
# Windows PowerShell
$env:ANTHROPIC_MODEL = "sonnet"
On Windows, use setx or the system environment dialog if you want it to survive a restart. The value can be an alias or a full model name.
The settings.json File
The cleaner option for teams is the settings file. In your user file (~/.claude/settings.json) the choice follows you everywhere. In a project file (.claude/settings.json) it follows the repository, so every teammate gets the same model without any setup.
The env block is handy because it keeps variables inside the project instead of scattering them across shell profiles.
Precedence Table
When two settings disagree, the higher row wins.
Priority
Method
Scope
1 (highest)
/model in a session
Current session
2
--model startup flag
Single launch
3
ANTHROPIC_MODEL variable
Every launch in that shell
4 (lowest)
model field in settings
Every launch for that user or project
💡 Rule of thumb: if a change is ignored, something higher in this table is overriding it. Check from the top down.
Aliases and Version Pinning
Alias Cheat Sheet
Aliases are short names that point at a recommended model for your provider. They update over time, which is convenient and occasionally dangerous.
Alias
What it does
default
Clears overrides and uses the recommended model for your account type
sonnet
Daily coding tier
opus
Deepest reasoning tier
haiku
Fast, low-cost tier
opusplan
Opus while planning, Sonnet while executing
Because aliases move, the model behind sonnet today may not be the model behind sonnet next quarter. For personal use that is a feature. For a team with reproducible results, it is a risk.
Pinning With Tier Variables
To freeze an alias on an exact version, use the per-tier variables:
With these set, typing /model sonnet always resolves to the version you chose, no matter what Anthropic changes upstream. If you want to read about those exact models outside the terminal, you can chat with Claude Opus 4.7, Claude Sonnet 4.6 and Claude 4.5 Haiku directly on PicassoIA to compare how each one writes and reasons.
Two related variables are worth knowing:
CLAUDE_CODE_SUBAGENT_MODEL sets the model used by subagents, so you can keep the main thread strong and let helpers run cheap.
ANTHROPIC_SMALL_FAST_MODEL is deprecated. Use ANTHROPIC_DEFAULT_HAIKU_MODEL instead.
If you work through Amazon Bedrock, Google Cloud or Microsoft Foundry, alias resolution can lag behind the direct API, so pinning is not optional there. Always set the tier variables explicitly.
The opusplan Trick
opusplan is the most underrated alias. In Plan Mode it uses the opus tier to think through the approach, then switches to the sonnet tier when it starts editing. You pay top-tier prices only for the part of the job that benefits from them.
claude --model opusplan
💡 Why it works: planning is a small number of tokens with a large effect on quality. Execution is a large number of tokens with a smaller effect. Splitting them is the cheapest way to raise output quality.
Add Custom Models Through a Gateway
Here is the part most guides skip. Claude Code is built to talk to Anthropic models, and ANTHROPIC_BASE_URL changes where requests go, not which model answers them. To use something else, you put a gateway between Claude Code and the model, and the gateway translates.
Point Claude Code at the Gateway
A gateway is a proxy that exposes an Anthropic-compatible endpoint and forwards requests to other providers. Tools such as LiteLLM, Bifrost and similar routers do this job. Set two variables:
Claude Code now sends every request to the gateway using the token you gave it, instead of the standard Anthropic login.
💡 Watch out: if an Anthropic API credential variable is also set in your shell, it can take priority and make Claude Code bypass the gateway entirely. If traffic is not showing up in your gateway logs, check for a leftover variable first.
Map Tiers to Gateway Slugs
Next, tell each alias which gateway model to use. Gateways name models in their own format, so the values are usually provider-prefixed slugs:
Several gateway providers recommend that the value still contain a recognizable Anthropic model ID where possible, because Claude Code makes decisions based on the name. Follow your gateway's documentation for the exact slug format.
To make the picker readable, newer builds also honor display-name and description overrides for each tier (for example ANTHROPIC_DEFAULT_SONNET_MODEL_NAME). Recent releases additionally document a variable that adds a single custom entry to the /model picker, named ANTHROPIC_CUSTOM_MODEL_OPTION. Names and behavior change quickly, so confirm both against the documentation of your installed version.
Local and Open Models
The same pattern works for local servers such as vLLM or Ollama-style runtimes that expose an Anthropic-compatible route, directly or through a gateway. Point ANTHROPIC_BASE_URL at the local address, give the tier variables the local model name, and Claude Code treats it like any other backend.
Be realistic about the trade-off:
Factor
Anthropic models
Custom or local models
Tool calling reliability
Tuned for Claude Code
Varies widely
Long-context behavior
Predictable
Depends on the server config
Cost
Per token
Hardware or provider rate
Privacy
Provider terms
Fully under your control if local
Common Gotchas
There is a reported issue where the tier variables appear to be ignored when a custom base URL is used. Whether you hit it depends on your version, so test it: run /model, select an alias, and watch the gateway logs to see the model name that actually arrives. If the name is wrong, pass the full gateway slug with --model instead of relying on an alias.
Other mistakes that waste an hour:
Quotes and trailing spaces in environment variables.
A gateway that does not support streaming, which makes sessions feel frozen.
A model without tool support, which makes Claude Code read files but never edit them.
Mixing settings files, where the project file silently overrides the user file.
Fix Model Errors Fast
When the model will not change, or an error mentions an unknown model, work through this list in order.
Symptom
Likely cause
Fix
Switch has no effect
A higher priority method is overriding it
Check /model, then the flag, then the variable, then settings
"Model not found"
Wrong name for your provider
Use the exact ID your provider lists
Alias points to an old model
Provider resolves aliases late
Pin with the tier variables
Gateway receives no traffic
A leftover Anthropic credential variable
Unset it and restart the terminal
Picker shows no custom entries
Gateway names are not mapped
Set the tier variables and display names
Costs climbing
Top tier used for every task
Use opusplan or switch to the sonnet tier for execution
💡 Debug habit: change one variable at a time, restart the session, and verify with the picker. Changing three things at once is how people end up unable to tell which one worked.
Build a Team Setup That Lasts
If you manage more than one developer, a short checklist saves arguments later:
Commit a project settings.json with the model field and pinned tier variables.
Keep credentials out of the repository. Put tokens in each developer's shell, not in the committed file.
Pick a default of balance, not depth. The mid tier is right for most commits.
Document the escape hatch. Tell people they can run /model opus when a task is hard.
Review pins quarterly. Pinned versions do not improve by themselves, so schedule time to test newer ones.
Freelancers and solo builders can skip the checklist and keep one personal default with opusplan for large tasks. It is the closest thing to a free lunch in the whole configuration.
How to Get Similar Results on PicassoIA
Claude Code itself is a terminal tool and it is not a model on PicassoIA, so there is nothing to install or launch there. What PicassoIA does offer is direct chat access to several Claude models, which is useful when you want to compare tiers before you pin one in your settings, or when you want a coding assistant in the browser. Here is a clean way to run that comparison with Claude Sonnet 5.
Step 1: Open the model page. Go to the Claude Sonnet 5 page and start a new chat.
Step 2: Paste a real task. Use a function you actually need to refactor, a failing test, or a short design question. Real work shows differences that toy prompts hide.
Step 3: Set the constraints in the prompt. State the language, the style rules, and what should not change. Clear limits produce tighter answers.
Step 4: Repeat on another tier. Run the same prompt on Claude Opus 4.7 for deeper reasoning, and on Claude 4.5 Haiku for speed. If you want a heavier option for complex coding, Claude Fable 5 is also available.
Step 5: Decide what to pin. Note which answer you would have accepted without edits, then set that tier in your Claude Code settings.
💡 Parameter tip: keep the prompt identical across models and change only the model. Otherwise you are comparing prompts, not models.
Pick a Model and Test It Today
Everything above comes down to a handful of habits. Switch with /model when the task changes. Set a default in settings.json when it does not. Pin the tier variables when reproducibility matters. Reach for a gateway only when you truly need a model outside the Anthropic lineup, and verify what arrives at the other end.
The fastest way to build intuition is to run the same prompt through several models and compare. Open PicassoIA, try the Claude models listed above on a task from your own backlog, and bring the winner back to your terminal. And since PicassoIA also covers image, video, voice and music models, you can keep experimenting well beyond code: generate visuals for your project docs, narrate a demo, or draft release notes in the same place. Start with one prompt and two models, and you will know within ten minutes which setting belongs in your config.