← Back to Blog

Routing Claude Code to a Different Model: The Setup, and the Fine Print

The env var trick for pointing Claude Code at GLM, Kimi, or DeepSeek works. Here's what actually happens under the hood, and the gotchas most guides skip.

July 15, 2026


If you’ve searched for how to run Claude Code on something other than Claude, you’ve probably found the same four lines of shell config copied across a dozen blog posts. Set a base URL, set a token, pick a model name, done. It reads like a party trick: your favorite coding agent, running on someone else’s model, in under a minute.

It does work. But the guides that hand you those four lines almost never mention that Anthropic’s own documentation explicitly disclaims support for this pattern, that the base URL alone won’t stop your Claude subscription from being billed, or that Claude Code’s tool-calling behavior was tuned against Claude specifically. None of that means don’t do it. It means the actual mechanics and tradeoffs are more interesting than the copy-paste version suggests.

How Claude Code decides where a request goes

Claude Code talks to the outside world using Anthropic’s Messages API, a specific wire format for sending a conversation and getting a response back. Four environment variables control where that traffic actually goes and what it says:

  • ANTHROPIC_BASE_URL sets the address requests get sent to.
  • ANTHROPIC_AUTH_TOKEN (or ANTHROPIC_API_KEY) sets the credential attached to each request.
  • ANTHROPIC_MODEL and ANTHROPIC_SMALL_FAST_MODEL set which model name gets requested, for the main model and for lightweight background tasks respectively.

Change the base URL, and Claude Code will happily send its Messages-API-shaped requests somewhere else entirely. This isn’t a backdoor. It’s the same mechanism Anthropic documents, officially, for large organizations pointing Claude Code at their own account on AWS Bedrock, Google Vertex AI, or Microsoft Foundry (per Anthropic’s current docs at code.claude.com, as of July 2026). The intended use case is “run this through our own cloud infrastructure and billing,” not “run this on a different vendor’s model.” The mechanism is general enough to do both. Only one of those is the one Anthropic signed off on.

What people actually do with it

The community use of this mechanism has moved fast in 2026. A few patterns show up repeatedly:

Native Anthropic-compatible endpoints. DeepSeek, Z.ai (which makes the GLM models), and Moonshot (which makes Kimi) all now expose an endpoint that speaks the Anthropic Messages format directly. DeepSeek’s is at https://api.deepseek.com/anthropic, for instance. That means no translation proxy is required at all: set the base URL, drop in that provider’s API key, and Claude Code just works against it.

OpenRouter as a single point of access. OpenRouter aggregates well over 200 models behind one key and now publishes its own “Claude Code integration” guide. Point the base URL at OpenRouter, use an OpenRouter key as the auth token, and you can switch which underlying model answers just by changing a model name.

claude-code-router, an open-source proxy project (musistudio/claude-code-router on GitHub) that’s grown from roughly 26,000 GitHub stars in January 2026 to over 33,000 by June, is the most popular tool built specifically for this. It lets you route by scenario rather than picking one model for everything: a cheap open-weight model for routine background work, a stronger reasoning model when a prompt looks like it needs deeper thought, and Claude itself reserved for anything higher-stakes.

A typical setup for pointing at DeepSeek directly might look like:

export ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
export ANTHROPIC_AUTH_TOKEN="<your-deepseek-api-key>"
export ANTHROPIC_MODEL="deepseek-chat"

Treat the exact endpoint paths and model names as a starting point, not gospel. Provider APIs and pricing pages change fast enough in this market that anything written down today is worth reconfirming before you rely on it.

The fine print nobody’s guide mentions

This is where the “just set an env var” framing starts to undersell what’s actually going on.

Setting the base URL alone doesn’t stop your Claude subscription from being billed. If you only change ANTHROPIC_BASE_URL and leave your saved claude.ai login as the active credential, Anthropic’s own documentation notes that requests still route through your subscription for usage limits and billing purposes, even while nominally being sent through a gateway. To actually swap out the billing path, you need an active gateway credential (the auth token variable) doing real work, not just present as a formality.

The variables are read once, at startup. Change them mid-session and nothing happens until you restart. This trips people up in ways that look like a broken proxy when the real issue is a stale environment.

Anthropic is blunt about not supporting this. Their current documentation states plainly that they don’t endorse, maintain, or audit third-party gateway products, and don’t support routing Claude Code to non-Claude models through any gateway. That’s not a subtle disclaimer buried in a footnote. It’s the headline position.

There’s also a distinction worth getting right, because a lot of 2026 coverage blurs it. Between January and April 2026, Anthropic tightened enforcement hard against third-party harnesses (tools like OpenClaw or OpenCode) that were reusing Claude subscription OAuth logins to impersonate Claude Code itself. Server-side blocks went in on January 9, a formal Terms of Service update followed on February 19–20, and by April 4 subscription-based access for those third-party tools was cut off entirely. That crackdown is a real and well-documented story. It is not, however, the same thing as running the actual Claude Code binary with a base-URL override pointed at a different provider using your own API key. Anthropic’s docs disclaim support for that pattern too, but it isn’t the thing the enforcement action targeted, and API-key-based usage, including through Bedrock or Vertex, was explicitly unaffected by the crackdown.

Does it actually work well?

Mechanically wiring up a different backend is the easy part. Whether the result is good is a separate question, and it’s worth being honest about where the doubt sits.

Claude Code’s system prompt, tool schemas, and step-by-step agentic loop were built and tuned around how Claude specifically calls tools. Point the same harness at a model that has never seen this exact prompt structure, and you’re asking it to conform to conventions it wasn’t shaped by. Even guides that are enthusiastic about model-swapping tend to include some version of the caveat that reliable tool use is really only guaranteed on Anthropic’s own models.

That said, “stay on the official stack” isn’t automatically the safe choice either, and the last few months are a useful reminder why. As of July 2026, there have been reports that Claude’s newer models themselves, Opus 4.8 and Sonnet 5, occasionally call tools with extra or invented fields that don’t match the schema they were given, a problem some observers say has gotten worse with newer versions rather than better. And Anthropic’s own engineering team published a postmortem in late April 2026 admitting that Claude Code had shipped three stacked quality regressions earlier that spring: a reasoning-effort default quietly downgraded from “high” to “medium” in early March, a caching bug that dropped context on resumed sessions in late March, and a verbosity cap in mid-April that measurably cut eval quality by about 3% before all three were fixed by April 20. None of that was caused by routing to a different model. It happened entirely within Anthropic’s own official pipeline.

The honest gap in all of this: nobody has published an independent, apples-to-apples comparison of Claude Code’s actual task success rate running on Claude versus running on GLM-5, Kimi K2.6, or DeepSeek V4 through the same harness. What circulates instead are general benchmark scores published by the model vendors themselves, which measure the model, not the model’s fit with this specific tool-calling loop. If someone tells you a swap is a clean drop-in, or that it obviously won’t work, both claims are running ahead of the actual evidence.

Why people do it anyway

Cost is the biggest driver. Z.ai sells a “GLM Coding Plan” with flat monthly pricing usable directly inside Claude Code, Cline, and other clients, positioned squarely against what someone would otherwise pay for a Claude Pro or Max subscription. Kimi K2.6 and DeepSeek V4 (both released in April 2026) get cited constantly in these setups as much cheaper per-token alternatives for routine work. Exact prices move often enough in this market that any number here should be treated as a snapshot, not a fixed fact, and reconfirmed at whatever provider’s page you’re actually about to pay.

Beyond cost, people do this to get past usage limits mid-session, to try an open-weight model without fully committing to it, or to run everything locally through Ollama or LM Studio, both of which added native support for the Anthropic wire format in 2026, for cases where sending anything to a third-party API isn’t an option at all.

Where this points to something bigger

Step back from the specific env vars, and what’s actually happening here is a routing problem being solved by hand. Someone decides which requests should go to which model, wires up a base URL and a credential to make that happen, and hopes the target speaks the wire protocol correctly and calls tools the way the harness expects. When a provider’s endpoint changes shape, or pricing shifts, or a model turns out to be flakier on tool calls than advertised, that’s a manual fix: edit the config, restart, hope for the best. And none of the setups above give you a second option if the provider you picked has a bad day. A base URL points at exactly one place. If that place is slow, rate-limited, or down, Claude Code just fails or hangs until a human notices and edits the config again.

This is the exact shape of problem AJNT sits in front of Claude Code (and any other Anthropic-, OpenAI-, or Responses-API-speaking client) to solve properly, as infrastructure rather than a manual habit. Two things specifically map onto what this whole post has been about:

Swapping models without touching your setup. Point Claude Code at AJNT once, the same ANTHROPIC_BASE_URL change described above, and the model actually serving a given request is a routing decision made behind that single endpoint, not something you re-wire by hand every time you want to try a different model. Instead of hand-editing env vars and restarting to test GLM against DeepSeek against Claude itself, you pick or change the target model on AJNT’s side, and Claude Code keeps talking to the same address the whole time.

Falling back automatically when a provider is unavailable. Rather than one base URL with no plan B, AJNT walks a fallback ladder of provider-model pairs for a given request, checks each one’s live health, and falls through to the next option automatically if the one you’d normally use is degraded or unreachable. That’s the difference between a session that hard-fails because one provider had an outage and one that quietly continues on a different rung of the ladder.

Neither of these makes the tool-calling fidelity question from earlier in this post disappear. Swapping to a model that’s never seen Claude Code’s exact tool schema still carries the same risk whether you do it with a hand-edited env var or through a gateway. What changes is that the mechanics of trying, comparing, and falling back between models stop being something you maintain by hand.

The bottom line

The env var trick works, and it’s worth trying if cost or availability is a genuine pain point for you. Just go in with a clear picture of what you’re signing up for: a pattern Anthropic’s own docs explicitly decline to support, a billing subtlety that can leave you double-paying if you get it half-wired, and a tool-calling fidelity question that nobody has actually settled with real data yet. This space, models, pricing, and Anthropic’s own policies, moves on something closer to a monthly cycle than an annual one. Treat everything above as accurate as of writing, and check the specifics again before you build on them.


← Back to Blog