Repository navigation
Expand file tree
/
Copy pathrun-claude-code-router.sh
More file actions
executable file
·224 lines (214 loc) · 6.38 KB
/
Copy pathrun-claude-code-router.sh
File metadata and controls
executable file
·224 lines (214 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
CUR_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
source "${CUR_DIR}/.env"
# vllm model lives in docker/vllm-configs/*.yaml (selected by VLLM_CONFIG), not in .env
VLLM_SERVED_MODEL="$(sed -n 's/^model:[[:space:]]*//p' "${CUR_DIR}/docker/vllm-configs/${VLLM_CONFIG:-qwen3.6-35b-a3b-fp8.yaml}" | head -n1 | xargs)"
if [[ -z "${VLLM_SERVED_MODEL}" ]]; then
echo "ERROR: cannot read model from docker/vllm-configs/${VLLM_CONFIG:-qwen3.6-35b-a3b-fp8.yaml}" >&2
exit 1
fi
bash "$CUR_DIR/install-bun.sh"
if [[ "max-inference" == "${AGENT_INFERENCE_SERVER}" ]]; then
mkdir -p ~/.cache/max_cache
fi
if [[ "openrouter" != "${AGENT_INFERENCE_SERVER}" && "z-ai" != "${AGENT_INFERENCE_SERVER}" ]]; then
docker compose -f "$CUR_DIR/docker-compose.yaml" up --force-recreate -d --wait --wait-timeout 3600 ${AGENT_INFERENCE_SERVER}
fi
mkdir -p ~/.claude-code-router
CCR_ACTIVE_MODEL="${AGENT_INFERENCE_SERVER}/${AGENT_MAIN_MODEL}"
CCR_BACKGROUND_MODEL="${AGENT_INFERENCE_SERVER}/${AGENT_BACKGROUND_MODEL}"
cat <<EOT > ~/.claude-code-router/config.json
{
"LOG": true,
"LOG_LEVEL": "error",
"API_TIMEOUT_MS": 3600000,
"NON_INTERACTIVE_MODE": false,
"HOST": "127.0.0.1",
"PORT": 3456,
"routerEndpoint": "http://127.0.0.1:3456",
"Providers": [
{
"name": "max-inference",
"api_base_url": "http://127.0.0.1:8100/v1/chat/completions",
"api_key": "max-inference",
"models": ["noctrex/MiniMax-M2-REAP-139B-A10B-MXFP4_MOE-GGUF"]
},
{
"name": "ds4-sparkinfer",
"api_base_url": "http://127.0.0.1:8000/v1/chat/completions",
"api_key": "ds4-sparkinfer",
"models": [
"${ATLAS_MODEL}"
]
},
{
"name": "atlas",
"api_base_url": "http://127.0.0.1:30003/v1/chat/completions",
"api_key": "atlas",
"models": [
"${ATLAS_MODEL}"
]
},
{
"name": "paroquant",
"api_base_url": "http://127.0.0.1:30002/v1/chat/completions",
"api_key": "paroquant",
"models": [
"${PAROQUANT_MODEL}"
]
},
{
"name": "vllm",
"api_base_url": "http://127.0.0.1:30001/v1/chat/completions",
"api_key": "vllm",
"models": [
"${VLLM_SERVED_MODEL}"
]
},
{
"name": "sglang",
"api_base_url": "http://127.0.0.1:30000/v1/chat/completions",
"api_key": "sglang",
"models": [
"${SGLANG_MODEL}"
]
},
{
"name": "llama.cpp",
"api_base_url": "http://127.0.0.1:8090/v1/chat/completions",
"api_key": "llama.cpp",
"models": [
"${AGENT_MAIN_MODEL}",
"${AGENT_BACKGROUND_MODEL}",
"unsloth/Qwen3.5-120B",
"unsloth/Qwen3.5-27B",
"unsloth/GLM-4.7-Flash-30B",
"Qwen/Qwen3-Coder-Next-80B-Q8",
"noctrex/Qwen3.5-35B",
"noctrex/Qwen3-Next-80B"
]
},
{
"name": "bonsai",
"api_base_url": "http://127.0.0.1:8091/v1/chat/completions",
"api_key": "bonsai",
"models": [
"${AGENT_MAIN_MODEL}",
"${AGENT_BACKGROUND_MODEL}"
]
},
{
"name":"z-ai",
"api_base_url": "https://api.z.ai/api/paas/v4/completions",
"api_key": "${ZAI_API_KEY}",
"models": [
"glm-5.1",
"glm-4.7"
]
},
{
"name": "openrouter",
"api_base_url": "https://openrouter.ai/api/v1/chat/completions",
"api_key": "${OPENROUTER_API_KEY}",
"models": [
"mistralai/devstral-2512:free",
"xiaomi/mimo-v2-flash:free",
"google/gemini-3.1-flash-lite-preview",
"google/gemini-3.1-pro-preview-customtools",
"minimax/minimax-m2.5",
"x-ai/grok-4.1-fast",
"z-ai/glm-5",
"qwen/qwen3.5-flash-02-23",
"moonshotai/kimi-k2.5",
"deepseek/deepseek-v3.2-speciale",
"perplexity/sonar"
],
"transformer": {
"use": ["openrouter","tooluse"]
}
},
{
"name": "deepseek",
"api_base_url": "https://api.deepseek.com/chat/completions",
"api_key": "${DEEPSEEK_API_KEY}",
"models": ["deepseek-chat", "deepseek-reasoner"],
"transformer": {
"use": ["deepseek"],
"deepseek-chat": {
"use": ["tooluse"]
}
}
}
],
"Router": {
"builtInRules": {
"claude-code": { "enabled": true },
"codex": { "enabled": true }
},
"fallback": {
"mode": "retry",
"retryCount": 2,
"models": [
"${CCR_BACKGROUND_MODEL}"
]
},
"rules": []
},
"profile": {
"enabled": true,
"claudeCode": {
"enabled": true,
"model": "${CCR_ACTIVE_MODEL}",
"sonnetModel": "${CCR_ACTIVE_MODEL}",
"opusModel": "${CCR_ACTIVE_MODEL}",
"haikuModel": "${CCR_BACKGROUND_MODEL}",
"smallFastModel": "${CCR_BACKGROUND_MODEL}",
"fableModel": "${CCR_BACKGROUND_MODEL}",
"managedCompact": false,
"settingsFile": "~/.claude/settings.json"
},
"codex": {
"enabled": false,
"model": "${CCR_ACTIVE_MODEL}",
"providerId": "claude-code-router",
"providerName": "Claude Code Router",
"cliMiddleware": true,
"configFormat": "separate_profile_files",
"configFile": "~/.codex/config.toml",
"managedCompact": false,
"showAllSessions": false
},
"profiles": [
{
"id": "default-claude-code",
"name": "Claude Code",
"agent": "claude-code",
"enabled": true,
"scope": "global",
"surface": "auto",
"model": "${CCR_ACTIVE_MODEL}",
"sonnetModel": "${CCR_ACTIVE_MODEL}",
"opusModel": "${CCR_ACTIVE_MODEL}",
"haikuModel": "${CCR_BACKGROUND_MODEL}",
"smallFastModel": "${CCR_BACKGROUND_MODEL}",
"fableModel": "${CCR_BACKGROUND_MODEL}",
"managedCompact": false,
"settingsFile": "~/.claude/settings.json"
}
]
}
}
EOT
# claude CLI with CLAUDE_CONFIG_DIR=~/.claude looks for ~/.claude/.claude.json,
# but the real config lives at ~/.claude.json. Mirror it so ccr's profile wrapper works.
[[ -f ~/.claude.json ]] && cp ~/.claude.json ~/.claude/.claude.json
ccr stop || true
CCR_DB=~/.claude-code-router/config.sqlite
rm -f "$CCR_DB" "$CCR_DB-shm" "$CCR_DB-wal"
screen -L -Logfile /tmp/ccr-server.log -dmS ccr-server ccr start --no-open
sleep 2
screen -list
echo
echo "Web UI: http://127.0.0.1:3458"
echo "Gateway: http://127.0.0.1:3456"
echo "Prompt: ccr default-claude-code -- -p '...' | claude -p '...'"