Disclosure: we build CodeRouter, a router for coding agents. The runs below went through CodeRouter's Direct mode, which sends each request to the model you name.
TL;DR — Claude Code works with open models if the endpoint speaks Anthropic's Messages API and you set the model variables. We gave Claude Code the same small task on DeepSeek V4.1 Flash, GLM-5.3 and Kimi K2.6: two failing unit tests, fix the code, don't touch the tests. All three passed, in 8.5 s, 17 s and 48 s, for $0.004, $0.052 and $0.040 at list price. Claude Code's own cost summary was wrong by up to 22×: it doesn't know these models and prices them as Claude. And an open model isn't automatically the cheap choice inside Claude Code, where most input is cache reads: GLM-5.3's cache-read price is 3× Claude Sonnet 5.5's.
Why run Claude Code on an open model
Claude Code's tools, permissions and workflow don't depend on the model behind them. Point it at a different endpoint and the same agent loop runs on DeepSeek, GLM or Kimi. Plenty of people do: OpenRouter's public app rankings list Claude Code among the top apps by tokens on DeepSeek V4.1 Flash and GLM 5.3 Flash.
The usual reasons are price per token, a second model when Anthropic is rate-limited, or trying a model you already use elsewhere.
Setup: four steps
1. Get a key and switch to Direct mode
Sign in (new accounts get $1 of usage for 7 days with no card, $5 once you add a card that isn't charged; it covers every model except Claude Opus) and create an API key.
Then, in the dashboard, switch the account to Direct mode (pay-as-you-go and trial accounts; Team keys always use smart routing). This step matters. In smart routing, the default, CodeRouter picks the model for each request and rewrites a model name in the request to auto, so deepseek-chat would not reach DeepSeek. In Direct mode, the model you name answers, with no routing and no fallback. You can switch back at any time. More: Direct mode.
2. Set the environment variables
Put the key in ANTHROPIC_AUTH_TOKEN, not ANTHROPIC_API_KEY, and set every model variable to the open model. This is the configuration of our second DeepSeek run below:
export ANTHROPIC_BASE_URL="https://www.coderouter.io"
export ANTHROPIC_AUTH_TOKEN="<your-coderouter-key>"
export ANTHROPIC_MODEL="deepseek-chat"
export ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-chat"
export ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-chat"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-chat"
export CLAUDE_CODE_SUBAGENT_MODEL="deepseek-chat"
Or, to keep it to one project, the same values in the env block of .claude/settings.local.json (keep that file out of version control):
{
"env": {
"ANTHROPIC_BASE_URL": "https://www.coderouter.io",
"ANTHROPIC_AUTH_TOKEN": "<your-coderouter-key>",
"ANTHROPIC_MODEL": "kimi-k2.6",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "kimi-k2.6",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "kimi-k2.6",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "kimi-k2.6",
"CLAUDE_CODE_SUBAGENT_MODEL": "kimi-k2.6"
}
}
Why all of them: Claude Code doesn't send every request with ANTHROPIC_MODEL. Background tasks use the Haiku-class model, and subagents and /model choices use the Opus or Sonnet names. In Direct mode a Claude model name gets that Claude model, billed at its own price. If you want Claude for planning and an open model for the rest, that's a valid setup too: set only the variables you want to change.
If you ever logged in to Claude Code with an Anthropic account, run /logout once, quit, and start claude again. If ANTHROPIC_API_KEY is set in your shell, unset it.
3. Start Claude Code and check
cd /path/to/your/project
claude
Run /status and look for the CodeRouter base URL. Claude Code may print an unrecognized_model notice for these names; it still sends the requests. Each response carries an X-CodeRouter-Model header naming the model that answered, and every request shows in your dashboard.
4. Read the cost in the dashboard, not in Claude Code
Claude Code computes its cost summary from its own price table. For a model it doesn't know, it uses Claude prices. In our runs it said $0.069 and $0.203 for two DeepSeek V4.1 Flash runs whose list-price cost was $0.004 and $0.009. Your CodeRouter dashboard shows what each request actually cost.
The test run
Task: a 12-line Python file with two bugs and two failing unit tests. word_count split on single spaces, so newlines and double spaces counted wrong. top_words didn't break ties alphabetically. The prompt:
The tests in this repo fail. Fix the code in textstats.py (do not change the tests) so that 'python3 -m unittest' passes, then run the tests to confirm.
Setup: Claude Code 2.1.282 in headless mode (claude -p), allowed tools Read, Edit, Write and python3 -m unittest, at most 15 turns, one run per model, November 12, 2026. We checked afterwards that the test file was unchanged and that the tests pass on the fixed code.
| Model (ID) | Result | Time | Turns | Cost at list price | Claude Code's cost summary |
|---|---|---|---|---|---|
DeepSeek V4.1 Flash (deepseek-chat) |
Both tests pass, tests unchanged | 8.5 s | 6 | $0.004 | $0.069 |
GLM-5.3 (glm-5.3) |
Both tests pass, tests unchanged | 17.1 s | 6 | $0.052 | $0.118 |
Kimi K2.6 (kimi-k2.6) |
Both tests pass, tests unchanged | 47.5 s | 7 | $0.040 | $0.142 |
| DeepSeek V4.1 Flash, all model variables set (the setup above) | Both tests pass, tests unchanged | 13.5 s | 8 | $0.009 | $0.203 |
Cost at list price is the token counts Claude Code reports times each model's list price, cache reads included. The first three runs set ANTHROPIC_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL and ANTHROPIC_SMALL_FAST_MODEL; the last one set the five variables in step 2. In all four, every request went to the named model.
One caveat on the first DeepSeek run: its prompt cache was already warm from an attempt we stopped just before (our tool settings blocked a file write), so only 7.6K of its input tokens were uncached, against 23–25K for GLM-5.3 and Kimi K2.6. The fourth run had no such head start and cost $0.009, the fairer DeepSeek number. DeepSeek V4.1 Flash was still 4–6× cheaper than the other two.
What this shows: the whole loop works on each model. Claude Code reads the file, edits it, runs the tests, reads the result and stops. What it doesn't show: which model is better. It's one small task and one run each. For that, see the comparison below.
Which model to pick
List prices per million tokens on CodeRouter (November 12, 2026), and pass rates from our 176-task single-file Python benchmark (November 3, 2026; one retry allowed with the failing test output):
| Model (ID) | Context | Input | Output | Cache read | 176 tasks: first try | With one retry |
|---|---|---|---|---|---|---|
DeepSeek V4.1 Flash (deepseek-chat) |
1M | $0.30 | $1.20 | $0.006 | 70.3% | 80.6% |
GLM-5.3 (glm-5.3) |
1M | $1.24 | $4.31 | $0.308 | 62.3% | 89.1% |
Kimi K2.6 (kimi-k2.6) |
256K | $0.95 | $4.00 | $0.16 | 86.9% | 94.9% |
For comparison: Claude Haiku 5.5 (claude-haiku-5.5) |
100K | $0.10 | $0.50 | $0.01 | 72.0% | 93.7% |
For comparison: Claude Sonnet 5.5 (claude-sonnet-5.5) |
1M | $2.00 | $10.00 | $0.10 | 93.7% | 100% |
The benchmark is single-file tasks with short contexts, not long agent sessions; it's measured by TokenWatt, a project run by the same team as CodeRouter. Other open models you can name in Direct mode include deepseek-v4-pro, kimi-k3, kimi-k3.1-pro and glm-5.2; all prices are on the models page.
How we'd read it:
- Kimi K2.6 had the highest pass rate of the three, and it's the model smart routing uses for most implementation steps. Slowest in our run. Update, Nov 12, 2026 (later the same day): inside Claude Code on 30 real repository tasks, Kimi K2.6 solved 9, cost 4.8× Sonnet 5.5 per task and hit our 60-minute limit on half of them; GLM-5.3 solved 14 and DeepSeek V4.1 Flash 9, against Sonnet's 16. Full results: Claude Code on open models, 30 real tasks. Moonshot closed the K2 series to new accounts on October 31 and plans to retire it by the end of December 2026, so expect to move to a newer Kimi model then.
- DeepSeek V4.1 Flash is the cheapest by far, especially on cache reads, and the fastest in our run. It passed fewer of the 176 tasks.
- GLM-5.3 recovered well with one retry (62% → 89%). Its cache-read price is the highest of the five.
- Check the cache-read column. Claude Code resends the whole conversation every turn, so most input in a long session is cache reads: 79% of input tokens on our own team's traffic. GLM-5.3's cache reads cost 3× Sonnet 5.5's, and Claude Haiku 5.5 costs less per token than any of the three open models except on DeepSeek's cache reads. If price is your only reason, compare with Haiku too.
- Steps differ too. A different model takes a different number of steps to finish the same task, so per-token prices only go so far. Try your own tasks and read the per-request costs in the dashboard.
Why through CodeRouter, and when not to
DeepSeek, Moonshot (Kimi) and Zhipu (GLM) each offer their own Anthropic-compatible endpoint. If you only ever want one of them, using it directly works and adds no fee.
Through CodeRouter you get one key and one prepaid balance for all of them and for Claude, you switch models by changing one variable, and you can turn on smart routing when you'd rather not choose. Usage is billed at each model's list price with no markup; a 5.5% payment fee is added when you buy credit (a $20 top-up costs $21.10). See pricing.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The dashboard shows a different model than you set | The account is in smart routing, which rewrites named models to auto |
Switch to Direct mode in the dashboard |
| Some requests went to a Claude model | A model variable still names Claude (Haiku-class background calls, subagents, /model) |
Set all five variables in step 2 |
| Auth errors right after setup | The key is in ANTHROPIC_API_KEY, or the shell wasn't reloaded |
Use ANTHROPIC_AUTH_TOKEN; reload the shell and relaunch claude |
/status names a Claude account |
You're still logged in to Anthropic | /logout, quit, relaunch |
| Claude Code's cost looks far too high | It prices unknown models as Claude | Read costs in the CodeRouter dashboard |
| HTTP 402 | Prepaid balance is $0 | Top up in the dashboard; the response links there |
FAQ
Does Claude Code officially support DeepSeek, GLM or Kimi?
Claude Code lets you set a custom base URL and model names. It doesn't know these models' prices or limits, so its cost summary is wrong for them and it may print an unrecognized_model notice. The agent loop itself ran fine on all three in our test.
Do I lose prompt caching? No. All three providers cache repeated prompt prefixes, and the cache-read prices above are what you pay for those tokens.
Can I mix: Claude for planning, an open model for edits?
Yes. In Direct mode, each request goes to the model it names, so set ANTHROPIC_DEFAULT_OPUS_MODEL to a Claude model and the others to an open one. Or use smart routing (ANTHROPIC_MODEL=auto) and let CodeRouter choose per request: Claude Code router setup.