Claude Code with other models: router, OpenRouter, DeepSeek and local

Every working method to point Claude Code at non-Anthropic models, with exact env vars from each vendor's docs, the caveats, and when a multi-model agent is the simpler choice.

Updated October 2026

You can run Claude Code with non-Anthropic models by pointing ANTHROPIC_BASE_URL at an Anthropic-compatible endpoint: a provider like DeepSeek or Z.ai, OpenRouter, a LiteLLM proxy, Ollama, or a local router like claude-code-router. It works, but Anthropic doesn't support it, and features can break. An agent built for many models is the simpler path.

Last checked: October 2026. Commands and quotes come from the official docs of Claude Code, OpenRouter, DeepSeek, Z.ai, Ollama, LiteLLM and claude-code-router, linked below.

Does Anthropic support Claude Code with other models?

No. Claude Code's own gateway docs say: "Anthropic doesn't endorse, maintain, or audit third-party gateway products, and doesn't support routing Claude Code to non-Claude models through any gateway."

That doesn't mean it fails. It means nobody guarantees it, and when Claude Code ships a feature that a gateway or model doesn't understand, things break until someone updates the gateway. The docs say as much: "a gateway that doesn't forward them breaks the corresponding features."

Two more things to know before you start:

  • Your Claude subscription doesn't apply. When a gateway credential (ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY or an apiKeyHelper) is active, requests use that credential instead of your claude.ai login, and are billed by whoever owns it.
  • Some Claude Code features switch off. Remote Control and voice dictation are unavailable while a gateway credential is set, and Remote Control is disabled whenever ANTHROPIC_BASE_URL points at a non-Anthropic host. Tool search for MCP tools is off on non-first-party hosts unless you set ENABLE_TOOL_SEARCH=true (per LiteLLM's guide).

How the trick works

Claude Code speaks the Anthropic Messages API. It reads a few environment variables:

  • ANTHROPIC_BASE_URL: where to send requests.
  • ANTHROPIC_AUTH_TOKEN (sent as a bearer token) or ANTHROPIC_API_KEY (sent as x-api-key): the credential.
  • ANTHROPIC_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL and CLAUDE_CODE_SUBAGENT_MODEL: which model name to send for each role.

Anything that accepts Anthropic-format requests at that URL can answer, whatever model is behind it. There are four common ways to get such an endpoint.

Method 1: a provider's Anthropic-compatible endpoint

Several model vendors now expose an Anthropic-format endpoint specifically so Claude Code can use them.

Claude Code with DeepSeek

DeepSeek's docs give this setup (macOS/Linux):

export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=<your DeepSeek API key>
export ANTHROPIC_MODEL=deepseek-flash[1m]
export ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-flash[1m]
export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-flash[1m]
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-flash
export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-flash

DeepSeek's compatibility page notes that names starting with claude-opus map to deepseek-v4-pro, and claude-sonnet or claude-haiku map to deepseek-flash. Some Anthropic features are not supported there, including documents, MCP tool use blocks and code execution results, and fields like cache_control and citations are ignored.

Claude Code with GLM (Z.ai)

Z.ai's GLM Coding Plan docs set ANTHROPIC_BASE_URL to https://api.z.ai/api/anthropic, put your key in ANTHROPIC_AUTH_TOKEN, and map the Opus, Sonnet and Haiku variables to GLM-5.3 models in ~/.claude/settings.json. Their docs say compatibility was verified with Claude Code 2.0.14 and recommend the latest version.

Pros: one vendor, one key, a setup the vendor documents. Cons: one model family per configuration, and you depend on the vendor keeping up with Claude Code's request format.

Method 2: OpenRouter

OpenRouter documents Claude Code directly:

export OPENROUTER_API_KEY="<your OpenRouter key>"
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""

Then map roles with the ANTHROPIC_DEFAULT_*_MODEL variables, and run /status to confirm the base URL. If you were logged in with an Anthropic account, run /logout first.

The important caveat is in OpenRouter's own docs: "Claude Code with OpenRouter is only guaranteed to work with the Anthropic first-party provider," and "Claude Code is optimized for Anthropic models and may not work correctly with other providers." So OpenRouter is a reliable way to pay for Claude through OpenRouter, and a best-effort way to use GPT, Gemini, Qwen or Kimi inside Claude Code.

Method 3: LiteLLM proxy

LiteLLM is a self-hosted proxy that translates the Anthropic format to 100+ providers. Its "Claude Code with non-Anthropic models" tutorial uses a config.yaml like this:

model_list:
  - model_name: gpt-5.6-terra
    litellm_params:
      model: openai/gpt-5.6-terra
      api_key: os.environ/OPENAI_API_KEY

Then:

litellm --config /path/to/config.yaml   # listens on port 4000
export ANTHROPIC_BASE_URL="http://0.0.0.0:4000"
export ANTHROPIC_AUTH_TOKEN="$LITELLM_MASTER_KEY"
claude --model gpt-5.6-terra

Caveats from LiteLLM's docs:

  • Switching models with /model needs CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1, and the picker only shows gateway models whose IDs contain claude or anthropic (use display_name for a friendlier label).
  • Claude Code doesn't learn the real context window from the proxy. Set CLAUDE_CODE_AUTO_COMPACT_WINDOW, or Claude Code can overfill a smaller model's context and the provider will reject requests.
  • The master key gives access to every model on the proxy; use virtual keys to restrict it.

Pros: any provider, central budgets and logging, good for teams. Cons: you run and update a server.

Method 4: claude-code-router

claude-code-router (CCR) is an MIT licensed, community-built local gateway (37,600 GitHub stars, version 3.1.3 released October 9, 2026). It now describes itself as "one local control plane for every AI agent" and serves Claude Code, Codex, OpenCode and other clients from one endpoint at http://127.0.0.1:3456.

npm install -g @musistudio/claude-code-router
ccr ui    # management UI at http://127.0.0.1:3458

It supports OpenAI, Anthropic, Gemini, OpenRouter, DeepSeek, Moonshot/Kimi, Mistral, Z.AI and custom compatible endpoints, with routing rules, rewrites, retries and fallbacks. A desktop app is the recommended install. It needs Node.js 22+.

Pros: routes different requests to different models, free, local. Cons: another moving part to keep current, and it is not affiliated with Anthropic.

Claude Code with a local model (Ollama)

Ollama has a one-line launcher:

ollama launch claude

Or set it up by hand against a local Ollama server:

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5

Ollama's guide says to pick a model that supports tools and recommends a context window of 64k or more for local models. Expect local models on consumer hardware to be slower and less reliable at multi-step tool use than hosted frontier models.

Comparing the approaches

ApproachSetupTool-calling reliabilityCostSupported by Anthropic
Claude Code with ClaudeNoneBest: built for itClaude subscription or APIYes
Provider endpoint (DeepSeek, Z.ai)A few env varsDepends on the vendor's compatibility layerVendor's API or coding planNo
OpenRouterA few env varsGuaranteed only for Anthropic first-party; others best effortOpenRouter ratesNo
LiteLLMRun a proxy, write configDepends on translation and modelProvider rates plus your hostingNo
claude-code-routerInstall app or CLI, configure providersDepends on transform and modelProvider ratesNo
Ollama (local)ollama launch claudeVaries widely by model and context sizeYour hardwareNo
An agent built for many modelsInstall and pick a modelAgent is designed and tested across vendorsAgent's plan or your keysNot applicable

The simpler path: an agent built for many models

If what you actually want is "Claude Code, but with DeepSeek, GPT, Gemini or Qwen", a multi-model agent avoids the translation layer entirely. The agent's prompts, tool definitions and model list are designed for many vendors, so you aren't relying on a gateway to fake the Anthropic format.

Darce

Darce is the agent this site is about. It is an open source (MIT) terminal agent with 250+ coding models through OpenRouter, included in one plan, so there are no provider keys or env vars:

npx darce-cli                              # free trial, no account
darce --model deepseek/deepseek-v4-pro     # start on a specific model

Inside a session, /model (or Ctrl+P) opens a picker that only lists models able to drive a coding agent: tool calling, 64k+ context, current generation. Shift+↑ and Shift+↓ move to a smarter or cheaper model mid-task, with the price difference shown first, in an order you set with gears in ~/.darcerc. /derby races three models on the same task so you can compare diffs, tests and cost. See Models and the model directory.

Coming from Claude Code, Darce reads your CLAUDE.md and AGENTS.md and loads Claude Code skills as they are. Its /undo also covers files that shell commands changed, which Claude Code's rewind doesn't (see Claude Code rewind vs Darce undo).

Honest limits: Darce doesn't run local models; Free covers models up to $5 per million output tokens, Builder ($15/month) adds Claude Sonnet, Opus, GPT and Gemini Pro, and Power ($65/month) covers every model (see pricing). Requests go through Darce's API to OpenRouter, not directly to a provider you choose.

Other multi-model agents

  • OpenCode: MIT, 75+ providers via your own keys, plus local models and ChatGPT or Copilot logins. Best if you want to pay providers directly or run local models. See Darce vs OpenCode.
  • Aider: Apache-2.0, works with almost any LLM including local ones; git-native. See Darce vs Aider.
  • Crush: Charm's agent, many providers plus any OpenAI- or Anthropic-compatible API, local models via Ollama and others.
  • Kilo CLI and Cline: hundreds of models through their gateways or your own keys.

More options are in our OpenCode alternatives and Claude Code alternative pages.

Which should you use?

  • You want Claude models: use Claude Code as intended.
  • You want one cheaper model inside Claude Code and accept some breakage: the vendor's own Anthropic endpoint (DeepSeek, Z.ai) is the least fragile hack.
  • Your company already runs LiteLLM: use it, and set the context window variables.
  • You want local models: Ollama's launcher for experiments; OpenCode or Aider for daily use.
  • You want many vendors' models, switchable mid-task, without gateways: a multi-model agent like Darce or OpenCode.

Sources

Frequently asked questions

Can Claude Code use models other than Claude?

Technically yes: set ANTHROPIC_BASE_URL to an Anthropic-compatible endpoint such as DeepSeek, OpenRouter, LiteLLM or Ollama. Anthropic's docs say it doesn't support routing Claude Code to non-Claude models through any gateway, so features can break.

What is claude-code-router?

An MIT licensed community project that runs a local gateway at 127.0.0.1:3456 and forwards Claude Code's requests to providers like OpenRouter, DeepSeek, Gemini or Kimi, with routing rules and fallbacks. It is not affiliated with Anthropic.

How do I use Claude Code with DeepSeek?

DeepSeek's docs set ANTHROPIC_BASE_URL to https://api.deepseek.com/anthropic, put your DeepSeek key in ANTHROPIC_AUTH_TOKEN, and map ANTHROPIC_MODEL and the ANTHROPIC_DEFAULT_*_MODEL variables to DeepSeek model names.

Does OpenRouter work with Claude Code?

Yes, with ANTHROPIC_BASE_URL set to https://openrouter.ai/api and your OpenRouter key in ANTHROPIC_AUTH_TOKEN. OpenRouter says it is only guaranteed to work with the Anthropic first-party provider; other models may not work correctly.

Can I run Claude Code with a local model?

Yes. Ollama's docs offer ollama launch claude, or manual setup with ANTHROPIC_BASE_URL=http://localhost:11434. Pick a model with tool support and at least 64k context.

Does my Claude Pro or Max subscription cover other models in Claude Code?

No. When a gateway credential is set, requests use that credential instead of your claude.ai login, so subscription limits don't apply and the provider bills you.

Related guides