Claude Code Router guide: Ollama, OpenRouter and other models
Claude Code talks to Anthropic's API by default, but you can point it somewhere else by setting ANTHROPIC_BASE_URL and a credential. That is how people run Claude Code through OpenRouter, on local models with Ollama, or through Claude Code Router (CCR), an open-source local gateway that sits between Claude Code and many model providers and decides where each request goes. This guide covers all three, the exact settings, and the catch: Anthropic designs Claude Code for Claude models and does not support routing it to other models.

Source: Other LLM gateways, Claude Code docs
Ways to route Claude Code
| Route | What it is | Best for |
|---|---|---|
| Claude Code Router (CCR) | A free, MIT-licensed local gateway with a desktop app or CLI, listening on port 3456 | Switching between many providers, fallbacks, logs |
| Ollama | Runs local or Ollama cloud models behind an Anthropic-compatible API | Free local models, private code, offline work |
| OpenRouter | A hosted gateway with an Anthropic-compatible endpoint | Failover between Anthropic providers, team budgets |
| Your company's LLM gateway | Any gateway that speaks a supported API format | Central credentials, cost controls, audit logs |
Source: Other LLM gateways, Claude Code docs
What is Claude Code Router?
Claude Code Router, by musistudio on GitHub, describes itself as a local model gateway and control plane for coding agents. Despite the name it now serves Claude Code, Codex, OpenCode, Kimi CLI, Grok CLI and other agents. You add providers once, then route, fail over and watch every request. It supports OpenAI, Anthropic Messages, Gemini, OpenRouter, DeepSeek, Moonshot, Kimi Code, Mistral, Z.AI and custom compatible providers.
- Manage every agent and provider in one place instead of editing each tool's settings.
- Switch providers or models without changing how you work.
- Keep requests going with retries, pools of keys, key rotation and ordered fallback models.
- Add abilities to models that lack them, such as vision, web search and MCP tools.
- See request logs, the route each request took, latency, token use and cost estimates.
Source: Claude Code Router, GitHub
Install Claude Code Router
The desktop app is the recommended route. Open Providers, Add Provider, pick a preset or custom endpoint, enter the API key and choose models. Then open Server and click Start; the gateway listens on http://127.0.0.1:3456. In Agent Config, choose Claude Code, pick a model and apply the profile. Start Claude Code and check Logs to confirm which provider and model each request used.
For the command line, CCR needs Node.js 22 or newer:
npm install -g @musistudio/claude-code-router@latestccr ui
That opens a browser management screen at http://127.0.0.1:3458 with the same Providers, Server and Agent Profiles steps, while the model gateway stays on port 3456. There is also a Docker setup. To add conditions, retries, request rewrites or fallback models, open Routing.
Source: Claude Code Router, GitHub
Use Claude Code with Ollama
Ollama connects Claude Code to local and cloud models through its Anthropic-compatible API. The quickest start is one command:
ollama launch claudeOllama lists chat, commands, tool calling, file edits, subagents, web search, web fetch, vision and thinking as working with compatible models. Choose a model with enough context for your repository: for local models, Ollama recommends a context window of 64k tokens or more on larger repositories, or use its cloud models to run bigger ones without downloading them.
Manual Ollama setup
With Ollama running locally, set three variables and start Claude Code with a model:
export ANTHROPIC_AUTH_TOKEN=ollamaexport ANTHROPIC_API_KEY=""export ANTHROPIC_BASE_URL=http://localhost:11434claude --model qwen3.5
To use Ollama's cloud without installing Ollama, set ANTHROPIC_BASE_URL to https://ollama.com and ANTHROPIC_AUTH_TOKEN to your Ollama API key, blank ANTHROPIC_API_KEY, and pick a cloud model that supports tools. Ollama notes that basic chat and file edits work with compatible models, but hosted web search and advanced tool controls are not fully supported. For scripts and CI, ollama launch claude --model gemma4:cloud --yes -- -p "how does this repository work?" skips the menus and passes everything after -- to Claude Code.
Source: Claude Code, Ollama docs
Use OpenRouter for Claude Code
OpenRouter exposes an endpoint that behaves like the Anthropic Messages API, so Claude Code connects straight to it with no local proxy. OpenRouter pitches three benefits: automatic failover between Anthropic providers when one is down or rate-limited, organisation budget controls, and usage analytics. It warns that Claude Code through OpenRouter is only guaranteed to work with the Anthropic first-party provider, and recommends setting Anthropic as the top-priority provider.
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=""
Put those in your ~/.zshrc or ~/.bashrc and reload the shell, or put the same values in the env block of .claude/settings.local.json. Do not use a project .env file, which the native installer does not read. If you were signed in to Claude Code with an Anthropic account, run /logout once and relaunch. Then run /status: it should show ANTHROPIC_AUTH_TOKEN as the auth token and https://openrouter.ai/api as the base URL. Usage is billed from your OpenRouter credits.
Choose models through OpenRouter
Claude Code picks a model per kind of task, and you can override each one with ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL, ANTHROPIC_DEFAULT_FABLE_MODEL and CLAUDE_CODE_SUBAGENT_MODEL. OpenRouter notes that Fable is not offered in /model through OpenRouter unless you set ANTHROPIC_DEFAULT_FABLE_MODEL. Set CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 to see a model picker with OpenRouter's top-ranked models, some of which route to non-Anthropic providers.
Fast mode through OpenRouter
Anthropic's fast mode gives up to 2.5 times faster output at premium prices. On OpenRouter it is a fast service tier on supported models, including Claude Fable 5.2, Claude Opus 5.5, Claude Opus 5 and Claude Opus 4.8; Sonnet and Haiku have no fast tier. Request it with the :nitro model variant or a fast service tier, and OpenRouter falls back to standard endpoints, billed at standard rates, when the fast one is unavailable.
Source: Claude Code, OpenRouter docs
How routing works under the hood
Every route uses the same two settings. ANTHROPIC_BASE_URL tells Claude Code where to send requests, and a credential authenticates them. Gateways such as OpenRouter and Ollama use ANTHROPIC_AUTH_TOKEN, which Claude Code sends as an Authorization: Bearer header, while ANTHROPIC_API_KEY is sent as an X-Api-Key header. That is why the guides blank ANTHROPIC_API_KEY: it would otherwise compete with the token.
When several credentials are present, Claude Code picks in a fixed order: cloud provider settings first, then ANTHROPIC_AUTH_TOKEN, then ANTHROPIC_API_KEY, then an apiKeyHelper script, then CLAUDE_CODE_OAUTH_TOKEN, and finally your /login subscription. While a gateway credential is active, requests carry it instead of your claude.ai subscription. Setting only ANTHROPIC_BASE_URL, with no gateway credential, does not replace the subscription login. Run /status to see which one is in use.
Source: Authentication, Claude Code docs
For teams: an LLM gateway
Companies often route Claude Code through a gateway they already run. Anthropic lists what that gives you: provider keys stay on the server while developers hold gateway credentials, usage can be tracked per developer or team, budgets and rate limits sit in one place, every request can be logged for compliance, and the provider can change without touching developer machines. The trade-off is that the gateway becomes infrastructure to maintain, and one that does not forward new Claude Code features breaks them. Admins distribute the base URL and credentials through a managed settings file, and can set allowedProviders to customEndpoint so the gateway is the only destination. Anthropic also offers its own self-hosted Claude apps gateway with single sign-on.
Source: Other LLM gateways, Claude Code docs
The trade-offs of routing Claude Code
- Anthropic does not endorse, maintain or audit third-party gateways, and does not support routing Claude Code to non-Claude models.
- Claude Code is tuned for Claude models; OpenRouter itself warns it may not work correctly with other providers.
- Smaller local models can struggle with Claude Code's tool calls and long context, so give them a large context window.
- A plaintext API key in your shell profile is easy to leak in a dotfiles repository; OpenRouter suggests loading it from your system keychain.
- Cloud sessions always use your subscription; a base URL or key set in the cloud environment does not override it.
Source: Other LLM gateways, Claude Code docs
See every agent, whatever model it runs
Routing makes it easy to run one Claude Code on a local model and another on Claude, next to Codex and others. 10u is an AI coding agent dashboard that shows every Claude Code and Codex session side by side, each in its real terminal, marked Needs you, Working, Waiting or Parked. They do the building. You decide what gets built.

Questions people ask
- What is Claude Code Router?
- An open-source local gateway (musistudio/claude-code-router) that sits between Claude Code and model providers, routing each request with fallbacks and logging. It listens on port 3456 by default.
- Can I use Claude Code with Ollama?
- Yes. Run ollama launch claude, or set ANTHROPIC_BASE_URL to http://localhost:11434, ANTHROPIC_AUTH_TOKEN to ollama and ANTHROPIC_API_KEY to empty, then run claude with a model.
- How do I use OpenRouter with Claude Code?
- Set ANTHROPIC_BASE_URL to https://openrouter.ai/api, ANTHROPIC_AUTH_TOKEN to your OpenRouter key and ANTHROPIC_API_KEY to empty, run /logout if you were signed in, then check /status.
- Does Anthropic support Claude Code with other models?
- No. Anthropic does not support routing Claude Code to non-Claude models, and features may not work with them.
- Can Claude Code run fully offline?
- With Ollama running a local model, model requests go to your own machine instead of a cloud API. Choose a model that supports tool calling and set a context window of 64k tokens or more.