
Using Any Other LLM Inside Claude Code
Plug and switch any model you want to use in claude code for flexibility and cheaper option.
Currently there is a lot of people are using Claude Code, terminal-based ai tool to assist their programming or to vibecode. The ability and flexibility to do bunch of tasks done through CLI and tool enabled by CC is really powerful and useful personally. Sadly, CC is dedicated for anthropic models only such as Sonnet and Opus. So, here is the “tricks” I have been using to switch and use any models beside anthropic models especially OSS models that have comparable performance to Sonnet itself (ex: Qwen3 Coder, Kimi K2, GLM 4.5). Thus, you can use cheaper model you want inside claude code directly.
Using Proxy Server
The first method that I have been using in the past is running proxy server that enables CC to work with any Open-AI compatible API providers. Basically you map any other LLM endpoint and its env cofiguration into Anthropic comparable client then you run localhost server to plug it into Anthropic client configuration such as ANTHROPIC_BASE_URL=http://localhost:8082 #localhost FastAPI server
inside CC.
TLDR: convert OpenAI API–compatible requests into Anthropic API format > Set the environment variables > override CC
baseUrl
andapiKey
There is already several claude code proxy github repos that you can directly use so you dont have to implement it from scratch:
- https://github.com/1rgs/claude-code-proxy
- https://github.com/fuergaosi233/claude-code-proxy
- https://github.com/musistudio/claude-code-router
Configure The Environment
Well you know the idea, as basically we just set and inject other LLM env configuration into CC baseUrl
& apiKey
, we can simplified the setup more, no need to start localhost server as proxy just to use other LLM in CC. Many AI labs such as Moonshot AI and Z.AI already make CC-compatible API endpoint that you can inject directly into Anthropic base URL. Now, Z.AI provides claude code plan for $3/month and $15/month be to be used specifically inside claude code (which is a lot of cheaper than claude code max plan). Thus, you can export the model baseUrl
and apiKey
directly then run claude like this:
export ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic
export ANTHROPIC_AUTH_TOKEN=YOUR_API_KEY
claude
Also you can configure the model on ~/.claude/settings.json
with:
{
"env": {
"ANTHROPIC_MODEL": "glm-4.5"
}
}
After that, you can run claude
then prompt /status
. It should be glm-4.5
on there. As we know that we only need to export the configuration directly then run claude to switch model now, we can wrap it as bash function and assign it as glm
or whatever your model name is. Now, you can just run glm
for running Z.AI model inside CC.
glm() {
export ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic
export ANTHROPIC_AUTH_TOKEN=$ZAI_API_KEY
export ANTHROPIC_MODEL="glm-4.5"
claude $1
}
You can also do this to other model that provide CC-compatible baseUrl
like Moonshot one.
kimi() {
export ANTHROPIC_BASE_URL=https://api.moonshot.ai/anthropic
export ANTHROPIC_AUTH_TOKEN=$MOONSHOT_API_KEY
export ANTHROPIC_MODEL="kimi-k2-0905-preview"
claude $1
}