---
title: "Switch Models in Claude Code: /model, Flag, Env Var, Settings"
description: "Switch Claude Code models with /model per session, or set a default via ANTHROPIC_MODEL or settings.json. Precedence, verification, and third-party model names."
url: https://cdnping.org/en/blog/claude-code-switch-model
language: en
published: 2026-11-25
category: "Developer tools"
tags: ["Claude Code","model switching","settings.json","environment variables","API configuration"]
source: cdnping.org
license: Free to quote and summarize with a link to the url above.
---
# 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](/en/blog/claude-code-settings-json-guide). 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 `/model` again in the session; the currently selected item is marked.
- Type `/status` to see the session's model, account, and endpoint information (the output varies slightly by version).
- When debugging conflicts, first run `env | grep ANTHROPIC` to look for leftover variables, then check `~/.claude/settings.json` and 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](/en/blog/claude-code-aws-bedrock-setup) and [Claude Code with Google Vertex AI](/en/blog/claude-code-vertex-ai-setup).
- 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](/en/blog/configure-custom-api-endpoint-claude-code-codex). If you are not sure whether you are on a subscription login or an API key, read [Claude Code: subscription login or API key](/en/blog/claude-code-subscription-or-api-key) first; the available models and billing differ between the two.

## What order should I troubleshoot in after switching?

1. Can you connect at all? Check [Is it down? Claude Code](/en/down/claude-code) and [Anthropic API status](/en/status/anthropic) to see whether it is a server-side problem.
2. Is the model name misspelled, or does it include stray spaces or quotes?
3. Is an environment variable overriding settings? Run `env | grep ANTHROPIC`.
4. Does the endpoint support that model? With a third-party endpoint, compare against the provider's model list.
5. 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](/en/models).

## 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](https://agiplan.dev/models) 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](https://agiplan.dev/startup).

## 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](/en/blog/claude-code-beginner-guide) for the full walkthrough.
