Use other models with Claude Code and Codex
Keep the agent you know and swap the model behind it for GLM, Kimi, DeepSeek, a local model or an aggregator. Here's why you'd do it, how it works and what you give up.
In this guide
Guide checked 3 months ago: some commands may have changed. Let us know if so.
In short
Claude Code and Codex can run models from other providers. Claude Code sends requests to ANTHROPIC_BASE_URL. Ollama (local or Cloud), OpenRouter, Z.ai, Kimi, MiniMax, DeepSeek and Xiaomi offer compatible endpoints. Codex supports any provider that speaks OpenAI's Responses API through ~/.codex/config.toml, and has built-in support for Ollama with --oss. Use this to spend less after you hit your plan limit, keep working during an outage, keep a confidential project on your own machine or work offline. Keep your usual settings and launch the other model with a profile or alias. Anthropic doesn't support this setup, features like Remote Control and built-in web search can disappear, and tool use is less reliable than with the original model.
Do this first: Going hybrid: cloud + localChinese LLMs: MiMo, Qwen, DeepSeek, GLM, Kimi
Claude Code and Codex are excellent agent harnesses. They provide the loop, tools, permissions and sub-agents that turn a model into an agent. The harness and the model are separate pieces. Claude Code sends requests to a URL and Codex sends them to a provider. You can redirect both, keep the tool you know by heart and swap out the model doing the work.
Why do it?
Five reasons, starting with the most common:
- You’ve hit your plan limit. You maxed out Claude Pro for the week on Wednesday evening. An open-model plan like Xiaomi’s Token Plan (from $6 per month) or OpenCode Go ($10) can take over in the same tool until your plan resets.
- The service is down. It happens to everyone. Claude was unavailable on November 13 (in French). Have a second profile ready and you can keep working in the same tool.
- The project has to stay on your machine. Client code, personal data, an embargo. Run your model on the mini-PC with Ollama and everything stays there.
- You’re offline. A train, a plane or somewhere with no signal. A colleague spent eleven hours on a flight with a local AI (in French). It works if you’re willing to use a smaller model.
- You want to compare models. Run the same task with Claude, GLM and Kimi in the same harness to see how each one handles your code.
Give each model a separate profile
Keep your usual configuration intact. If you put ANTHROPIC_BASE_URL in ~/.bashrc, every claude session goes to the other provider, even when you open one for a serious task. Give each model its own profile that you load on demand, with an alias to make it easy to launch.
# ~/.bashrc: aliases only
alias claude-glm='claude --settings ~/.claude/glm.json'
alias claude-local='ollama launch claude --model qwen3.8:27b'
alias codex-kimi='codex --profile kimi'
alias codex-local='codex --oss -m qwen3.8:27b'
Now claude and codex still use Anthropic and OpenAI, while claude-glm or codex-kimi starts a session on the other model. You can tell which one you’re using from the command.
Connect models in each agent
Claude Code reads three things: the URL (ANTHROPIC_BASE_URL), a key and the names of the models to use in place of Opus, Sonnet and Haiku (ANTHROPIC_DEFAULT_OPUS_MODEL and the corresponding variables). There are three kinds of provider:
1. A model on the mini-PC or on Ollama Cloud. Ollama speaks the Anthropic API and sets up the configuration for that session:
ollama launch claude --model qwen3.8:27b # local model, nothing leaves your machine
ollama launch claude --model glm-5.3:cloud # same setup, served by Ollama Cloud
Ollama Cloud ($20 or $100 per month) serves GLM-5.3, Kimi K3.1 Pro, MiniMax M3.1 Flash and DeepSeek V4.1 Flash, among others, according to QUELLE IA’s November 16, 2026 roundup. For exact names, see Ollama’s cloud models page.
2. A vendor plan (Z.ai, Kimi, MiniMax, DeepSeek, Xiaomi). Create a separate settings file and load it with --settings. See Chinese LLMs for the endpoints and full setup.
3. An aggregator. OpenRouter also offers an Anthropic-compatible endpoint. Its docs tell you to clear the Anthropic API key explicitly so that Claude Code doesn’t fall back to your Anthropic account:
# under "env" in ~/.claude/openrouter.json, or export for one session
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="votre_cle_openrouter"
export ANTHROPIC_API_KEY="" # leave this empty
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 # /model lists the models available through OpenRouter
OpenRouter says that Claude Code is only guaranteed to work with Anthropic’s models. Others often work, with no guarantees. Append [1m] to the name of a model that supports a million context tokens. Otherwise Claude Code assumes 200,000.
Once you’ve started a session, /status shows the endpoint and the model. Check both in your first session.
OpenCode supports more than 75 providers as well as local models, and you can switch models mid-session.
opencode
# inside OpenCode:
/connect # add a provider: Z.AI Coding Plan, Kimi For Coding, OpenRouter, OpenCode Go…
/models # choose the model for this session
For a local model, run ollama launch opencode. See Ollama and local models for details.
Codex uses a single protocol, OpenAI’s Responses API. You have two options:
1. Built-in Ollama support. This is the simplest way to run a local model:
codex --oss -m qwen3.8:27b # interactive session
ollama launch codex # or let Ollama prepare a separate profile
2. A Responses-compatible provider. Configure it in ~/.codex/config.toml and activate it with a profile. Kimi, Z.ai, Xiaomi and DeepSeek offer compatible endpoints. Chinese LLMs walks through the full setup with Kimi. The structure is always the same:
# ~/.codex/config.toml
[model_providers.kimi]
name = "Kimi"
base_url = "https://api.kimi.ai/coding/v1"
env_key = "KIMI_API_KEY" # name of the variable that holds the key
wire_api = "responses" # the only value Codex accepts
Then run codex --profile kimi and check the model with /model in the session.
What you give up
- Official support. The Claude Code docs say Anthropic doesn’t support routing to models other than Claude. If an update breaks your setup, you’ll have to fix it yourself.
- Some account features. Remote Control requires a claude.ai subscription and won’t work with another endpoint. Built-in web search and some server-side tools depend on the provider and may be missing.
- Reliable tool use. Claude Code and Codex are tuned for their own models. Another model might misformat a tool call, get stuck in a loop or ignore an instruction in
CLAUDE.md. GLM-5.3 and Kimi K3.1 Pro do well on clearly scoped tasks. On a long autonomous job, the gap with Claude Opus 5.5 shows more than it does in the QUELLE IA agent rankings. - Control over where your data goes. With a vendor plan or aggregator, your code goes to that provider under its terms. See Chinese LLMs for each Chinese vendor’s policy. Only a local model keeps everything on your machine.
- Telemetry still goes to Anthropic. Claude Code continues to send usage statistics to Anthropic. Its docs say those statistics contain no code or prompts. Turn off this telemetry with
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1.
The steps to follow
0 of 5 steps done Your ticks stay in this browser.
-
Decide why you're switching
Cost, outages, confidentiality or offline work: your reason determines whether you need a vendor plan, an aggregator or Ollama. To compare models, the QUELLE IA comparison tool shows two model profiles side by side.
-
Create a separate profile
Use a settings file for Claude Code (
--settings) or a profile for Codex (--profile). Keep your usual configuration as it is. -
Give it a clear alias
claude-glmorcodex-local: the command name tells you which model you’re using. -
Check it in your first session
Run
/statusin Claude Code or/modelin Codex. Then try a small task that uses tools, like reading a file or running tests, to see if the model calls them correctly. -
Keep big jobs on the original model
A backup profile keeps you moving and handles routine work. For architecture and long jobs, switch back to the model the tool was built for.
All the commands in this guide
Frequently asked questions
Can you use Claude Code without an Anthropic subscription?
Yes. Claude Code works with any service that implements the Anthropic API, including Ollama on the mini-PC, Ollama Cloud, OpenRouter and coding plans from Z.ai, Kimi, MiniMax, DeepSeek and Xiaomi. Set ANTHROPIC_BASE_URL and a key, preferably in a file you load with claude --settings. Anthropic doesn't support this setup, and features tied to a claude.ai account, such as Remote Control, won't work.
Can Codex use Claude, Gemini or a Chinese model?
Codex only speaks OpenAI's Responses API. Configure providers that expose it under model_providers in ~/.codex/config.toml, then activate them with a profile. Kimi, Z.ai, Xiaomi and DeepSeek all offer it. For a local model, codex --oss uses Ollama. Claude and Gemini don't have official Responses endpoints, so they need a translation gateway, which is more fragile.
Why not simply use OpenCode, which supports all the models?
That's often the best choice, and this site recommends it for switching between models. Connecting a different model to Claude Code or Codex mainly lets you keep the setup you're used to. Your skills, hooks, MCP servers, CLAUDE.md or AGENTS.md and shortcuts stay in place. Only the model changes for the session.
Will a cheaper model do the same job in Claude Code?
There are trade-offs. Claude Code is tuned for Claude models. Its instructions, tools and way of breaking down work assume a model that follows directions closely and calls tools correctly. GLM-5.3 and Kimi K3.1 Pro do well on clearly scoped tasks. The gap with Claude Opus 5.5 shows more on long autonomous jobs than it does in rankings.
Terms in this guide: Claude CodeCodexAgentSub-agentTokenUnified APIOllamaTools (tool use)
Spotted a mistake?
A command stopped working, a price changed?
Tools change every month. Tell me what is wrong in this chapter and I will fix it and update its date.