Large Language Models

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.

Claude Code Model: How to Change, Select and Add Custom Models
Cristian Da Conceicao

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

Developer at an oak desk in a bright loft, about to choose a tool

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.

PriorityTypical pickBest for
SpeedSmall, fast tierRenames, quick questions, log summaries
BalanceMid tierDaily feature work, tests, code review
DepthTop reasoning tierArchitecture, 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

Close-up of a hand adjusting a steel selector dial on a mixing console

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

Overhead view of a developer desk with a laptop, notebook and coffee

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.

{
  "model": "opus",
  "env": {
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6"
  }
}

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.

PriorityMethodScope
1 (highest)/model in a sessionCurrent session
2--model startup flagSingle launch
3ANTHROPIC_MODEL variableEvery launch in that shell
4 (lowest)model field in settingsEvery 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

Pegboard wall of neatly hung hand tools in a workshop

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.

AliasWhat it does
defaultClears overrides and uses the recommended model for your account type
sonnetDaily coding tier
opusDeepest reasoning tier
haikuFast, low-cost tier
opusplanOpus 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:

ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-4-7
ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-6
ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5

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

Wide aisle of a data center with black server racks

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:

export ANTHROPIC_BASE_URL=https://your-gateway.example.com
export ANTHROPIC_AUTH_TOKEN=your-gateway-token

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:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://your-gateway.example.com",
    "ANTHROPIC_AUTH_TOKEN": "your-gateway-token",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "bedrock/global.anthropic.claude-opus-4-7",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "provider/your-sonnet-class-model",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "provider/your-small-fast-model"
  }
}

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:

FactorAnthropic modelsCustom or local models
Tool calling reliabilityTuned for Claude CodeVaries widely
Long-context behaviorPredictableDepends on the server config
CostPer tokenHardware or provider rate
PrivacyProvider termsFully under your control if local

Macro of ethernet patch cables in a network switch

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

Two engineers planning at a whiteboard in a daylit room

When the model will not change, or an error mentions an unknown model, work through this list in order.

SymptomLikely causeFix
Switch has no effectA higher priority method is overriding itCheck /model, then the flag, then the variable, then settings
"Model not found"Wrong name for your providerUse the exact ID your provider lists
Alias points to an old modelProvider resolves aliases latePin with the tier variables
Gateway receives no trafficA leftover Anthropic credential variableUnset it and restart the terminal
Picker shows no custom entriesGateway names are not mappedSet the tier variables and display names
Costs climbingTop tier used for every taskUse 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

Freelance developer working at a rainy cafe window

If you manage more than one developer, a short checklist saves arguments later:

  1. Commit a project settings.json with the model field and pinned tier variables.
  2. Keep credentials out of the repository. Put tokens in each developer's shell, not in the committed file.
  3. Pick a default of balance, not depth. The mid tier is right for most commits.
  4. Document the escape hatch. Tell people they can run /model opus when a task is hard.
  5. 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.

Over-the-shoulder view of a woman typing a question into a chat window

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.

ModelBest use in this comparison
Claude Sonnet 5Everyday coding and drafting
Claude Opus 4.7Hard reasoning, long chains of logic
Claude 4.5 HaikuFast answers and short edits
Claude Fable 5Complex coding tasks

💡 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.

Share this article

Choose your language

FreeCreate AI Images and VideosFree, No Credit CardFree Generations to StartSeedance 2.5 Lite IncludedStart Free Now