Switch Models in Claude Code: /model, Flag, Env Var, Settings
There are four common ways to switch models in Claude Code: type /model in a session, pass --model at startup, set the ANTHROPIC_MODEL environment variable, or add a model field to settings.json. The first two apply to the current session; the last two set a long-term default. When several are set at once, the one closest to the "current action" wins.
Below: how to use each, which one wins in a conflict, and the pitfalls you are most likely to hit with third-party endpoints. The available model names and aliases change between versions, so go by the official docs and the list that /model shows on your machine.
How do I switch models in the middle of a session?
In the Claude Code interactive interface, type:
/model
A selection list appears; pick one with the arrow keys and press Enter. You can also pass an argument directly, such as /model sonnet or /model opus. Aliases (sonnet, opus, haiku, default) and the specific versions they map to depend on your Claude Code version and may differ, so check the official docs.
This switch only applies to the current session. After you exit, the next launch goes back to the default. It fits cases like using a stronger model for planning within a task, then a cheaper, faster one for bulk file edits.
How do I pick a model at startup?
claude --model sonnet
--model accepts an alias or a full model name. A full name is useful when you want to pin a version and avoid drift as an alias moves. This flag only affects the current launch.
How do I make a default model stick?
Pick one of two approaches.
Environment variable:
export ANTHROPIC_MODEL="your-model-name"
Add it to ~/.bashrc or ~/.zshrc; it takes effect in new terminals. On Windows, set it in the system environment variables, or use $env:ANTHROPIC_MODEL in PowerShell.
settings.json:
{
"model": "your-model-name"
}
Settings come in user, project, and local-project levels. For the levels and merge rules, see Claude Code settings.json: levels, precedence, and env configuration. settings.json also has an env field where you can put ANTHROPIC_MODEL, so everyone on the project shares one configuration instead of depending on their own shell.
Which setting wins when they conflict?
According to the official docs, the precedence from highest to lowest is roughly:
| Priority | Method | Scope |
|---|---|---|
| 1 | /model in a session | Current session |
| 2 | --model startup flag | Current launch |
| 3 | ANTHROPIC_MODEL environment variable | Current shell and child processes |
| 4 | model in settings.json | By settings level |
This order may change between versions; if you are unsure, verify it once using the methods below. A common source of confusion: you changed the model in settings, but nothing changed after launch. Most likely ANTHROPIC_MODEL was already exported in your shell and overrides settings.
Also, Claude Code internally uses a smaller model for some small background tasks. The official docs provide environment variables for aliases (for example the ANTHROPIC_DEFAULT_SONNET_MODEL family, plus variables for the small model) that rewrite which specific model an alias points to. Variable names are defined by the official docs, so check them before setting anything.
How do I confirm which model is in use?
- Type
/modelagain in the session; the currently selected item is marked. - Type
/statusto see the session's model, account, and endpoint information (the output varies slightly by version). - When debugging conflicts, first run
env | grep ANTHROPICto look for leftover variables, then check~/.claude/settings.jsonand the project's.claude/settings.json.
What model name do I use with a third-party endpoint?
This is the most common source of errors for newcomers. The official endpoint recognizes official model names. If you point ANTHROPIC_BASE_URL at another service (a gateway, a cloud provider's managed endpoint, and so on), the model name in the request must be one that service recognizes.
- A mismatched name usually produces a "model not found" or "no permission" style error; the exact wording is up to the server.
- Cloud providers often use different model identifier formats from the official API. Bedrock and Vertex AI each have their own ID rules; see Claude Code with AWS Bedrock and Claude Code with Google Vertex AI.
- Before relying on an alias from
/model, confirm that it resolves to a model that exists on your endpoint. If it does not, enter the model name from the provider's own docs.
For the full way to change endpoints, see Custom API endpoints for Claude Code, Codex, and OpenCode. If you are not sure whether you are on a subscription login or an API key, read Claude Code: subscription login or API key first; the available models and billing differ between the two.
What order should I troubleshoot in after switching?
- Can you connect at all? Check Is it down? Claude Code and Anthropic API status to see whether it is a server-side problem.
- Is the model name misspelled, or does it include stray spaces or quotes?
- Is an environment variable overriding settings? Run
env | grep ANTHROPIC. - Does the endpoint support that model? With a third-party endpoint, compare against the provider's model list.
- Does your account or plan have access to that model? Available models may differ by subscription tier; go by the official documentation.
To see model availability and latency across inference providers, see cdnping model monitoring.
What if I have no official account or overseas credit card?
If account registration or payment is the obstacle, you can look at AGI Plan. AGI Plan is a commercial partner of cdnping, so this is only a brief introduction: it is a multi-provider LLM aggregation gateway, billed as a monthly subscription, paid in RMB, with no overseas credit card needed; one subscription lets you switch between several capability groups. Claude Code and Codex only need one endpoint address changed, and Claude Code does not need a Claude account. The site states plainly that it is not an officially authorized channel, and some models are marked "overseas only"; the available range is whatever the models page shows.
The rules in this article apply here too: use a model name the gateway supports, not a copy of the official name. For the three-step setup, see the AGI Plan getting-started page.
What should I do next?
Try /model once in a session and confirm the list matches what you expect. If you need a long-term default, write it to the model field in settings.json and check that no stale ANTHROPIC_MODEL is left in your shell. If you have just installed Claude Code, follow How to use Claude Code: from install to your first code change for the full walkthrough.