Run Claude Code on Ollama or DeepSeek — No Anthropic Bill Required
Personal use case: The
claudemodel is really too expensive. SinceClaude Codenatively only supports theAnthropicAPI format, this article documents how to connect local models or other models (DeepSeek, etc.) toClaude Code.
Via Claude Code Router (CCR): Connect the Claude Code CLI to Ollama (local models) or DeepSeek (cloud models), enabling Claude Code to run with non-Anthropic models.
Table of Contents
- Principle Overview
- Installing Claude Code Router
- Configuring the Ollama Provider
- Configuring the DeepSeek Provider
- Configuring Claude Code to Connect to CCR
- Verifying the Connection
- Advanced: Routing Rules and Virtual Models
- Common Troubleshooting
- Reference Links
1. Principle Overview
Architecture Diagram
┌─────────────────┐ Anthropic Messages API ┌──────────────────────────┐
│ │ ──────────────────────────────▶ │ │
│ Claude Code │ /v1/messages │ Claude Code Router │
│ (CLI / VSC) │ ◀────────────────────────────── │ (localhost:3456) │
│ │ │ │
└─────────────────┘ └──────────┬───────────────┘
│
┌──────────────────────────────────────┼──────────────────────────┐
│ │ │
▼ ▼ ▼
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Ollama │ │ DeepSeek API │ │ OpenAI API │
│ (localhost) │ │ (Cloud) │ │ (Other Compat) │
│ :11434/v1 │ │ api.deepseek │ │ │
└──────────────────┘ └──────────────────┘ └──────────────────┘
Workflow
- Claude Code natively only supports the Anthropic Messages API format (
/v1/messages) - Claude Code Router runs locally, exposing an Anthropic-compatible endpoint at
http://127.0.0.1:3456 - By setting
ANTHROPIC_BASE_URL=http://127.0.0.1:3456, Claude Code sends all API requests to CCR - CCR performs protocol conversion internally: Translates the Anthropic Messages format into the OpenAI Chat Completions format (supported by both Ollama and DeepSeek)
- The response is then translated back from the OpenAI format to the Anthropic format and returned to Claude Code
Key Facts
| Item | Description |
|---|---|
| Protocol sent by Claude Code | Anthropic Messages API (/v1/messages) |
| Protocol supported by Ollama | OpenAI Chat Completions API (/v1/chat/completions) |
| Protocol supported by DeepSeek | OpenAI Chat Completions API (/v1/chat/completions) |
| Role of CCR | Protocol translation gateway, translating between the two formats |
| Authentication method | Credentials passed via ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY |
2. Installing Claude Code Router
System Requirements
- macOS 10.15+ / Windows 10+ / Linux (supports AppImage)
- Claude Code CLI installed
Download and Install
- Visit the GitHub Releases page
- Download the installation package for your system:
- macOS:
.dmgfile - Windows:
.exeinstaller - Linux:
.AppImagefile
- macOS:
- Install and launch the application
First Launch
After launching, CCR creates a configuration file at:
- macOS / Linux:
~/.claude-code-router/config.json - Windows:
%APPDATA%\Claude Code Router\config.json
3. Configuring the Ollama Provider
Prerequisites
- Ollama installed
- At least one model pulled, for example:
ollama pull llama3.1
ollama pull qwen2.5
ollama pull deepseek-r1:7b
- The Ollama service is running (default listening on
http://127.0.0.1:11434)
Configuration via CCR Interface
- Open the CCR desktop application
- Go to Providers → Click Add Provider
- Fill in the following information:
| Field | Value |
|---|---|
| Provider Name | Ollama |
| Endpoint (Base URL) | http://127.0.0.1:11434/v1 |
| Protocol | openai_chat_completions |
| API Key | Leave blank (or fill in ollama arbitrarily) |
| Models | Enter the names of models you have pulled, e.g., llama3.1, qwen2.5 |
- Click Save
Why is the Ollama endpoint
:11434/v1? Starting from version 0.1.32, Ollama natively supports an OpenAI-compatible API at the path/v1/chat/completions. CCR uses theopenai_chat_completionsprotocol to convert Anthropic requests and send them to this endpoint.
Optional: Configuration via Deeplink
You can also add it quickly via a URL Scheme:
ccr://provider?name=Ollama&base_url=http%3A%2F%2F127.0.0.1%3A11434%2Fv1&api_key=ollama&models=llama3.1,qwen2.5&protocol=openai_chat_completions
Opening this link in a browser will cause CCR to pop up a confirmation dialog.
Testing the Ollama Connection
Verify that Ollama's OpenAI-compatible API is working correctly from the terminal:
curl http://127.0.0.1:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "llama3.1",
"messages": [{"role": "user", "content": "Hello"}]
}'
It should return a JSON response containing a choices field.
4. Configuring the DeepSeek Provider
Prerequisites
- Register on the DeepSeek Platform
- Obtain an API Key (create one in the console)
Configuration via CCR Interface
- Open the CCR desktop application
- Go to Providers → Click Add Provider
- Fill in the following information:
| Field | Value |
|---|---|
| Provider Name | DeepSeek |
| Endpoint | https://api.deepseek.com/v1 |
| Protocol | openai_chat_completions |
| API Key | sk-xxxxxxxxxxxxxxxxxxxx (your DeepSeek API Key) |
| Models | deepseek-chat, deepseek-reasoner |
- Click Save
Optional: Configuration via Deeplink
ccr://provider?name=DeepSeek&base_url=https%3A%2F%2Fapi.deepseek.com%2Fv1&api_key=sk-xxxxxxxxx&models=deepseek-chat,deepseek-reasoner&protocol=openai_chat_completions
DeepSeek Model Description
| Model ID | Description | Use Case |
|---|---|---|
deepseek-chat |
DeepSeek V3 / Latest chat model | Daily coding, code generation |
deepseek-reasoner |
DeepSeek R1 reasoning model | Complex reasoning, debugging analysis |
5. Configuring Claude Code to Connect to CCR
5.1 Start the CCR Gateway
- In the CCR desktop application, go to Server
- Click Start to start the gateway service
- Confirm the status: both endpoints should be running:
- Wrapper gateway:
http://127.0.0.1:3456 - Core gateway runtime:
http://127.0.0.1:3457
- Wrapper gateway:
💡 It is recommended to check Auto-start, so CCR will automatically start the gateway every time you boot up.
5.2 Create a Claude Code Configuration File
Method A: Global Configuration (Recommended)
Edit ~/.claude/settings.json (macOS/Linux) or %USERPROFILE%\.claude\settings.json (Windows):
{
"env": {
"ANTHROPIC_BASE_URL": "http://127.0.0.1:3456",
"ANTHROPIC_API_KEY": "ccr-local"
}
}
The value of
ANTHROPIC_API_KEYcan be any non-empty string — CCR, being a local gateway, does not validate this key, but Claude Code requires a value to bypass the login flow.
Method B: Project-Level Configuration
Create .claude/settings.local.json in the project root directory (this file is automatically gitignored):
{
"env": {
"ANTHROPIC_BASE_URL": "http://127.0.0.1:3456",
"ANTHROPIC_API_KEY": "ccr-local"
}
}
Method C: Shell Environment Variables (Temporary, Good for Testing)
export ANTHROPIC_BASE_URL=http://127.0.0.1:3456
export ANTHROPIC_API_KEY=ccr-local
5.3 Using CCR Profiles for Automatic Configuration (Recommended)
CCR provides a Profile feature for one-click configuration application:
- In CCR, go to Profiles
- Select Claude Code
- Select the target model (e.g.,
llama3.1configured in your Ollama) - Click Apply — this automatically sets the environment variables and opens Claude Code
5.4 Configuring CCR Routing
Set the following in the CCR Routing panel:
| Routing Item | Recommended Configuration |
|---|---|
| Default Provider | Select your configured Ollama or DeepSeek |
| Default Model | Select the specific model, e.g., llama3.1 or deepseek-chat |
You can also configure routing rules for different workloads:
- Background (background tasks) → Can use a cheaper model
- Thinking (reasoning tasks) → Can use a more powerful model
- Subagent (sub-agents) → Can use a more cost-effective model
6. Verifying the Connection
6.1 Quick Test (curl)
After configuring the environment variables, first test if the CCR gateway responds correctly using curl:
curl -X POST http://127.0.0.1:3456/v1/messages \
-H "Authorization: Bearer ccr-local" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "llama3.1", "max_tokens": 50, "messages": [{"role": "user", "content": "Say hello"}]}'
Note: The
modelname here must be consistent with the model name you previously added in CCR. For DeepSeek, usedeepseek-chat; for Ollama, use the model name you pulled, such asllama3.1.
If it returns JSON containing a content field, CCR is working correctly.
6.2 Launching Claude Code
cd your-project
claude
If everything is normal, Claude Code should skip the login screen and go directly into a session.
6.3 Checking Status
Run the following command in Claude Code:
/status
Check the following key information:
| Status Item | Expected Value |
|---|---|
Anthropic base URL |
http://127.0.0.1:3456 |
API key |
Should display ANTHROPIC_API_KEY (not Login method) |
6.4 Sending a Test Message
Try sending a simple message, for example:
Hello, what model are you running on?
If the CCR routing is configured correctly, you will receive a model reply, and you can see the request record in the CCR Dashboard.
7. Advanced: Routing Rules and Virtual Models
7.1 Multi-Model Routing
CCR supports routing different tasks to different models based on request characteristics:
| Routing Condition | Target Model | Use Case |
|---|---|---|
| Default | deepseek-chat |
Daily conversation and coding |
| Background | llama3.1 (local Ollama) |
Background tasks, code search |
| Thinking | deepseek-reasoner |
Tasks requiring deep reasoning |
| Long Context | deepseek-chat |
Processing large files |
Configuration method: Set it in CCR → Routing → Add Routing Rule.
7.2 Virtual Models
You can create virtual model names to simplify model selection:
llama3.1 → llama3.1 on Ollama
default-coding → deepseek-chat
default-reasoning → deepseek-reasoner
Configure this in CCR → Routing → Virtual Models.
7.3 Fallback Routing
When the primary model is unavailable, CCR can automatically switch to a fallback model:
Primary: deepseek-chat (DeepSeek)
Fallback: llama3.1 (Ollama, runs locally, no network required)
Configure this in Routing → Edit routing rule → Configure Fallback model.
7.4 API Key Rotation
For API services like DeepSeek, you can configure multiple API Keys for load balancing and failover:
In Providers → Edit DeepSeek → API Key field, use commas to separate multiple keys:
sk-key1,sk-key2,sk-key3
CCR will automatically rotate to the next key when a request fails.
8. Common Troubleshooting
8.1 Claude Code Still Shows the Login Screen
Cause: The CCR gateway configuration is not being read by Claude Code.
Solution:
- Confirm that both
ANTHROPIC_BASE_URLandANTHROPIC_API_KEYare correctly set - If using
settings.json, confirm the file path is correct:- Global:
~/.claude/settings.json - Project-level:
.claude/settings.local.json
- Global:
- Run
echo $ANTHROPIC_BASE_URLto check if the environment variable is effective - Run
/statusin Claude Code to see the actual base URL in effect
8.2 Connection Refused
Cause: The CCR gateway is not started.
Solution:
- Confirm the CCR desktop application is running
- In CCR → Server, confirm the Gateway status is "Running"
- Check if the port is occupied:
lsof -i :3456
8.3 Model Returns Errors or No Response
Cause: There may be multiple possible issues.
Solution Steps:
For Ollama:
# Check Ollama service status
ollama list
# Confirm the model is loaded
ollama run llama3.1
# Check Ollama logs
ollama serve
For DeepSeek:
# Directly test the DeepSeek API
curl https://api.deepseek.com/v1/chat/completions \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{"model": "deepseek-chat", "messages": [{"role": "user", "content": "hi"}]}'
8.4 401 Authentication Error
Cause: The API Key is not being passed correctly.
Solution:
- If using
ANTHROPIC_API_KEY, CCR receives thex-api-keyheader - If using
ANTHROPIC_AUTH_TOKEN, CCR receives theAuthorization: Bearerheader - In most cases, both work; just ensure the variable name in
settings.jsonmatches what CCR expects
8.5 Protocol Conversion Error
Cause: CCR may encounter incompatible fields when converting between Anthropic Messages ↔ OpenAI Chat Completions.
Solution:
- Set the environment variable in Claude Code:
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 - This causes Claude Code to send fewer experimental fields, reducing the chance of protocol conversion errors
- Add it to settings.json:
{
"env": {
"ANTHROPIC_BASE_URL": "http://127.0.0.1:3456",
"ANTHROPIC_API_KEY": "ccr-local",
"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
}
}
8.6 Checking CCR Logs
The Network Logs panel in the CCR desktop application can view all passing requests and responses, making it the best tool for troubleshooting.
8.7 Resetting Configuration
If you need a complete reset:
# Back up existing configuration
cp ~/.claude-code-router/config.json ~/.claude-code-router/config.json.bak
# Delete configuration (CCR will recreate it on next launch)
rm ~/.claude-code-router/config.json
# Clear Claude Code cache
rm -rf ~/.claude/cache
9. Complete Configuration Example
Final ~/.claude/settings.json
{
"env": {
"ANTHROPIC_BASE_URL": "http://127.0.0.1:3456",
"ANTHROPIC_API_KEY": "ccr-local",
"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
}
}
Startup Sequence
The correct startup sequence is:
- Start Ollama (if using local models):
ollama serve - Start CCR and ensure the gateway is in Running status
- Start Claude Code:
claude
10. Reference Links
- Claude Code Router GitHub — Project source code and Release downloads
- Claude Code Official Documentation - LLM Gateway — Claude Code's gateway protocol description
- Claude Code Official Documentation - Connect to LLM Gateway — Detailed guide for configuring
ANTHROPIC_BASE_URL - Claude Code Official Documentation - Gateway Protocol Reference — Gateway API protocol details
- Ollama Official Documentation — Running local models with Ollama
- DeepSeek Platform — DeepSeek API management
Disclaimer: Claude Code Router is a third-party open-source project, not officially maintained by Anthropic. When using non-Anthropic models to run Claude Code, some native Claude Code features (such as ultra-long context, thinking capabilities, tool streaming, etc.) may be limited due to protocol conversion. Always use this in compliance with your organization's security policies.