Last updated · Santosh Kumar Radha

How to run Claude Code with Ollama, DeepSeek or OpenRouter (and when not to)

Point Claude Code at Ollama, DeepSeek or OpenRouter with ANTHROPIC_BASE_URL, step by step, and when an any-model agent such as CodeAF is simpler.

You run Claude Code on another provider by setting ANTHROPIC_BASE_URL to an Anthropic-compatible endpoint and ANTHROPIC_AUTH_TOKEN to that provider's key; DeepSeek, OpenRouter and Ollama each document this, and a proxy such as LiteLLM covers the rest. If what you really want is a coding agent built for any model, CodeAF, the open-source terminal agent by AgentField, takes those providers directly, and on DeepSeek V4 Flash it solved 62 of 113 DeepSWE tasks where Claude Code solved 16.

Every command below is copied from the provider's own docs, checked 2026-11-21. Anthropic itself says Claude Code "doesn't support routing Claude Code to non-Claude models through any gateway" (LLM gateway), so these routes work at your own risk.

At a glance

RouteBase URLKey variableModel settingSource
OpenRouterhttps://openrouter.ai/apiANTHROPIC_AUTH_TOKEN, with ANTHROPIC_API_KEY=""ANTHROPIC_DEFAULT_*_MODELOpenRouter docs
DeepSeekhttps://api.deepseek.com/anthropicANTHROPIC_AUTH_TOKENdeepseek-flash, deepseek-v4-proDeepSeek docs
Ollama, localhttp://localhost:11434ANTHROPIC_AUTH_TOKEN=ollamaclaude --model <model>Ollama docs
LiteLLM proxyyour proxy, e.g. http://0.0.0.0:4000ANTHROPIC_AUTH_TOKEN = master keyclaude --model <name>LiteLLM docs
CodeAF insteadnone to setcodeaf connect <service>per task, or autoCodeAF FAQ

How does Claude Code talk to another provider?

Claude Code reads three variables for this: ANTHROPIC_BASE_URL to "override the API endpoint to route requests through a proxy or gateway", ANTHROPIC_AUTH_TOKEN for a bearer token, and ANTHROPIC_API_KEY for an X-Api-Key header (env vars). The endpoint has to speak the Anthropic Messages API at POST /v1/messages.

Which model answers is a separate setting. Anthropic's model docs say "ANTHROPIC_BASE_URL changes where requests are sent, not which model answers them" (model config). You pick the model with claude --model, /model, ANTHROPIC_MODEL, or by remapping the opus, sonnet and haiku aliases with ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL. The Haiku slot is "also used for background functionality", so a provider that does not map it will fail on background calls. You can put the same variables in the env block of ~/.claude/settings.json instead of your shell.

How do I run Claude Code with OpenRouter?

OpenRouter documents Claude Code directly: set the base URL to https://openrouter.ai/api (no /v1), pass your OpenRouter key as ANTHROPIC_AUTH_TOKEN, and set ANTHROPIC_API_KEY to an empty string. OpenRouter adds that Claude Code "is only guaranteed to work with the Anthropic first-party provider".

  1. Add this to your shell profile, from OpenRouter's guide:

    bash
    export OPENROUTER_API_KEY="<your-openrouter-api-key>"
    export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
    export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
    export ANTHROPIC_API_KEY="" # Important: Must be explicitly empty
  2. Run source ~/.zshrc or open a new terminal.

  3. If you ever signed in to Anthropic in Claude Code, run /logout and start claude again.

  4. Run /status and check it shows Auth token: ANTHROPIC_AUTH_TOKEN.

The guide's model overrides use OpenRouter's Anthropic models, such as ANTHROPIC_DEFAULT_SONNET_MODEL="~anthropic/claude-sonnet-latest[1m]". Setting CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 lists more models in /model, but the page warns that "Claude Code is optimized for Anthropic models and may not work correctly with other providers."

How do I run Claude Code with DeepSeek?

DeepSeek runs an Anthropic-compatible API at https://api.deepseek.com/anthropic and publishes a Claude Code setup that maps every Claude alias to a DeepSeek model. Claude model names sent to it are mapped too: claude-opus* goes to deepseek-v4-pro, and claude-sonnet* and claude-haiku* go to deepseek-flash.

  1. Install Claude Code (npm install -g @anthropic-ai/claude-code, Node.js 18 or newer) and check claude --version.

  2. Create a key at platform.deepseek.com/api_keys.

  3. Set the variables, verbatim from DeepSeek's Claude Code page:

    bash
    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
    export CLAUDE_CODE_EFFORT_LEVEL=max
    export CLAUDE_CODE_AUTO_COMPACT_WINDOW=786432
  4. cd into your project and run claude.

DeepSeek's compatibility notes list what it ignores or rejects: cache_control, top_k and budget_tokens are ignored; MCP tool blocks and code_execution_tool_result are not supported; and deepseek-v4-pro replaces images with [Unsupported Image].

How do I run Claude Code with Ollama or a local model?

Ollama serves an Anthropic-compatible API and ships a launcher: ollama launch claude starts Claude Code against your Ollama server. To set it up by hand, point Claude Code at http://localhost:11434 with a placeholder token and name a model you have pulled.

bash
ollama pull qwen3-coder
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3-coder

Those three variables and the claude --model form come from Ollama's Claude Code page, which uses qwen3.5 as its example and qwen3-coder on its Anthropic compatibility page. Ollama's advice on context is specific: "For larger repositories, set the context length to 64k or higher." A local model that cannot hold that much context, or call tools reliably, will struggle with any coding agent, so hardware sets the ceiling. Ollama's cloud models work the same way with ANTHROPIC_BASE_URL=https://ollama.com and an OLLAMA_API_KEY from your Ollama account.

Can I use LiteLLM or claude-code-router as a proxy?

LiteLLM documents a proxy that translates Claude Code's requests to OpenAI, Gemini, Vertex AI or Azure models; claude-code-router is an MIT-licensed community gateway for the same job. Both sit between Claude Code and the provider, so you run and maintain one more process.

For LiteLLM, from its tutorial:

  1. Install it: uv tool install 'litellm[proxy]'.
  2. Write a config.yaml with a model_list entry for each model, with its key from an environment variable such as os.environ/OPENAI_API_KEY, and set LITELLM_MASTER_KEY.
  3. Start it: litellm --config /path/to/config.yaml.
  4. Point Claude Code at it with ANTHROPIC_BASE_URL="http://0.0.0.0:4000" and ANTHROPIC_AUTH_TOKEN="$LITELLM_MASTER_KEY", then run claude --model <model_name>.

claude-code-router installs with npm install -g @musistudio/claude-code-router@latest on Node.js 22 or newer; ccr ui opens its settings at http://127.0.0.1:3458, and its gateway listens on http://127.0.0.1:3456. It had about 38.3k GitHub stars on 2026-11-21.

How well does Claude Code work on a non-Claude model?

On DeepSeek V4 Flash, Claude Code solved 16 of 113 tasks in AgentField's DeepSWE comparison, and CodeAF in senior-dev mode solved 62 on the same model. Every harness ran deepseek/deepseek-v4-flash-0731 through OpenRouter, with the official verifiers and 3 hours per task.

Harness, on DeepSeek V4 FlashSolved of 113Cost per taskCost per solved issue
CodeAF senior-dev (v0.5.0)62, 54.9%22 cents39.9 cents (1x)
Codex CLI (0.154.0)51, 45.1%37 cents2.1x
Claude Code (2.1.267)16, 14.2%19 cents3.4x

Task by task, CodeAF solved 51 tasks Claude Code missed, and Claude Code solved 5 that CodeAF missed (head to head). Claude Code with Claude models was not part of this comparison, so this says how the harness does on DeepSeek, not how Claude Code does on Claude.

When is a coding agent built for any model simpler?

A coding agent built for many models is simpler when the reason you want a proxy is the model, not Claude Code. CodeAF connects these providers with no base URL or alias mapping: OpenRouter signs in through your browser, DeepSeek takes a key, and Ollama needs none (README).

bash
curl -fsSL https://agentfield.ai/get/codeaf | bash
codeaf

First setup starts with a provider chooser, and later codeaf connect lists every model service and codeaf connect <service> adds one (connections). Each handed-off task runs on its own branch with a crew of three seats, each of which can be a different model, and every call is priced before it runs, with $5 per task and a $500 daily backstop by default (budgets). More on this setup: a coding agent for any model.

How to choose

Choosing a route depends on whether you want Claude Code itself or a different model: five routes cover those cases, and only one of them, OpenRouter with Anthropic models, is guaranteed by the provider.

  • Choose Claude Code with OpenRouter when you want Claude models billed through OpenRouter; that is the case OpenRouter guarantees.
  • Choose Claude Code with DeepSeek's endpoint when you want to keep Claude Code's interface and try DeepSeek, and accept the features DeepSeek ignores.
  • Choose ollama launch claude when you want Claude Code's interface on a local or Ollama cloud model with at least a 64k context window.
  • Choose LiteLLM or claude-code-router when you already run a proxy for your team, or need models no provider exposes in Anthropic format.
  • Choose CodeAF when you want any model as a first-class option, a model per seat, spend limits and parallel tasks, with no proxy to maintain.
  • Stay on plain Claude Code when you use Claude models: its IDE surfaces, hooks and plugins are more mature (CodeAF vs Claude Code).

Questions people ask

Can I run Claude Code with a local LLM?

Yes, through Ollama: ollama launch claude starts it, or set ANTHROPIC_BASE_URL=http://localhost:11434, ANTHROPIC_AUTH_TOKEN=ollama and run claude --model <model>. Anthropic does not support non-Claude models in Claude Code, and Ollama recommends a context length of 64k or higher.

How do I use Claude Code with OpenRouter?

Set ANTHROPIC_BASE_URL="https://openrouter.ai/api", ANTHROPIC_AUTH_TOKEN to your OpenRouter key and ANTHROPIC_API_KEY="", then run /logout if you were signed in and check /status. OpenRouter guarantees it only with Anthropic's own models.

How do I run Claude Code with DeepSeek?

Set ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic and ANTHROPIC_AUTH_TOKEN to your DeepSeek key, and map the model variables to deepseek-flash as DeepSeek's Claude Code page shows. DeepSeek ignores prompt caching (cache_control) and does not support MCP tool blocks.

Is Claude Code good with DeepSeek models?

In AgentField's DeepSWE comparison, Claude Code 2.1.267 on DeepSeek V4 Flash solved 16 of 113 tasks. CodeAF in senior-dev mode solved 62 and Codex CLI 51 on the same model.

What is a Claude Code alternative that works with any model?

CodeAF is an open-source terminal coding agent by AgentField that runs any model and many tasks at once, each on its own branch. It takes OpenRouter, DeepSeek, GLM, Kimi, MiniMax, Qwen, a Codex plan, Ollama and any OpenAI-compatible endpoint directly, with no proxy.

Sources

Last updated 2026-11-21.