Use Claude Code as the foundation for coding infrastructure, allowing you to decide how to interact with the model while enjoying updates from Anthropic.
This is a tool for routing Claude Code requests to different models, and you can customize any request.
npm install -g @anthropic-ai/claude-code
npm install -g @musistudio/claude-code-router
ccr code
~/.claude-code-router/config.json
file like this:{
"Providers": [
{
"name": "openrouter",
// IMPORTANT: api_base_url must be a complete (full) URL.
"api_base_url": "https://openrouter.ai/api/v1/chat/completions",
"api_key": "sk-xxx",
"models": [
"google/gemini-2.5-pro-preview",
"anthropic/claude-sonnet-4",
"anthropic/claude-3.5-sonnet",
"anthropic/claude-3.7-sonnet:thinking"
],
"transformer": {
"use": ["openrouter"]
}
},
{
"name": "deepseek",
// IMPORTANT: api_base_url must be a complete (full) URL.
"api_base_url": "https://api.deepseek.com/chat/completions",
"api_key": "sk-xxx",
"models": ["deepseek-chat", "deepseek-reasoner"],
"transformer": {
"use": ["deepseek"],
"deepseek-chat": {
// Enhance tool usage for the deepseek-chat model using the ToolUse transformer.
"use": ["tooluse"]
}
}
},
{
"name": "ollama",
// IMPORTANT: api_base_url must be a complete (full) URL.
"api_base_url": "http://localhost:11434/v1/chat/completions",
"api_key": "ollama",
"models": ["qwen2.5-coder:latest"]
},
{
"name": "gemini",
// IMPORTANT: api_base_url must be a complete (full) URL.
"api_base_url": "https://generativelanguage.googleapis.com/v1beta/models/",
"api_key": "sk-xxx",
"models": ["gemini-2.5-flash", "gemini-2.5-pro"],
"transformer": {
"use": ["gemini"]
}
},
{
"name": "volcengine",
// IMPORTANT: api_base_url must be a complete (full) URL.
"api_base_url": "https://ark.cn-beijing.volces.com/api/v3/chat/completions",
"api_key": "sk-xxx",
"models": ["deepseek-v3-250324", "deepseek-r1-250528"],
"transformer": {
"use": ["deepseek"]
}
}
],
"Router": {
"default": "deepseek,deepseek-chat", // IMPORTANT OPENAI_MODEL has been deprecated
"background": "ollama,qwen2.5-coder:latest",
"think": "deepseek,deepseek-reasoner",
"longContext": "openrouter,google/gemini-2.5-pro-preview"
}
}
background
think
longContext
/model
command. The format is: provider,model
, like this:/model openrouter,anthropic/claude-3.5-sonnet
You just need to install Claude Code Actions
in your repository according to the official documentation. For ANTHROPIC_API_KEY
, you can use any string. Then, modify your .github/workflows/claude.yaml
file to include claude-code-router, like this:
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issues:
types: [opened, assigned]
pull_request_review:
types: [submitted]
jobs:
claude:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Prepare Environment
run: |
curl -fsSL https://bun.sh/install | bash
mkdir -p $HOME/.claude-code-router
cat << 'EOF' > $HOME/.claude-code-router/config.json
{
"log": true,
"OPENAI_API_KEY": "${{ secrets.OPENAI_API_KEY }}",
"OPENAI_BASE_URL": "https://api.deepseek.com",
"OPENAI_MODEL": "deepseek-chat"
}
EOF
shell: bash
- name: Start Claude Code Router
run: |
nohup ~/.bun/bin/bunx @musistudio/claude-code-router@1.0.8 start &
shell: bash
- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@beta
env:
ANTHROPIC_BASE_URL: http://localhost:3456
with:
anthropic_api_key: "test"
You can modify the contents of $HOME/.claude-code-router/config.json
as needed.
GitHub Actions support allows you to trigger Claude Code at specific times, which opens up some interesting possibilities.
For example, between 00:30 and 08:30 Beijing Time, using the official DeepSeek API:
deepseek-v3
model is only 50% of the normal time.deepseek-r1
model is just 25% of the normal time.So maybe in the future, I’ll describe detailed tasks for Claude Code ahead of time and let it run during these discounted hours to reduce costs?
Now you can use deepseek-v3 models directly without using any plugins.
If you’re using the DeepSeek API provided by the official website, you might encounter an “exceeding context” error after several rounds of conversation (since the official API only supports a 64K context window). In this case, you’ll need to discard the previous context and start fresh. Alternatively, you can use ByteDance’s DeepSeek API, which offers a 128K context window and supports KV cache.
Note: claude code consumes a huge amount of tokens, but thanks to DeepSeek’s low cost, you can use claude code at a fraction of Claude’s price, and you don’t need to subscribe to the Claude Max plan.
Some interesting points: Based on my testing, including a lot of context information can help narrow the performance gap between these LLM models. For instance, when I used Claude-4 in VSCode Copilot to handle a Flutter issue, it messed up the files in three rounds of conversation, and I had to roll everything back. However, when I used claude code with DeepSeek, after three or four rounds of conversation, I finally managed to complete my task—and the cost was less than 1 RMB!
If you find this project helpful, you can choose to sponsor the author with a cup of coffee. Please provide your GitHub information so I can add you to the sponsor list below.
<table> <tr> <td><img src="/blog/images/alipay.jpg" width="200" /></td> <td><img src="/blog/images/wechat.jpg" width="200" /></td> </tr> </table>Thanks to the following sponsors for supporting the continued development of this project:
@Simon Leischnig (If you see this, feel free to contact me and I can update it with your GitHub information)
@duanshuaimin
@vrgitadmin
@*o (可通过主页邮箱联系我修改 github 用户名)
@ceilwoo
@*说 (可通过主页邮箱联系我修改 github 用户名)
@*更 (可通过主页邮箱联系我修改 github 用户名)
@K*g (可通过主页邮箱联系我修改 github 用户名)
@R*R (可通过主页邮箱联系我修改 github 用户名)
@bobleer
@*苗 (可通过主页邮箱联系我修改 github 用户名)
@*划 (可通过主页邮箱联系我修改 github 用户名)
@Clarence-pan
musistudio/claude-code-router
February 25, 2025
July 7, 2025
TypeScript