The same applies to a desktop environment.
1. Prepare the node.js environment
1
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
1
2
| echo 'export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"' >> ~/.bashrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.bashrc
|
2. Install claude-code
1
| npm install -g @anthropic-ai/claude-code
|
3. Install claude-code-router
claude-code can currently only call Claude’s API. Using claude-code-router to start claude-code lets it connect to third-party APIs.
1
| npm install -g @musistudio/claude-code-router
|
- Configure the environment variables
1
2
| export API_BASE_URL=https://xxx.com/v1/chat/completions
export API_KEY=sk-xxx
|
- Generate the configuration file
1
| mkdir -p ~/.claude-code-router
|
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
| cat > ~/.claude-code-router/config.json <<EOF
{
"LOG": true,
"LOG_LEVEL": "trace",
"HOST": "127.0.0.1",
"PORT": 3456,
"API_TIMEOUT_MS": "600000",
"Providers": [
{
"name": "oneapi",
"api_base_url": "${API_BASE_URL}",
"api_key": "${API_KEY}",
"models": [
"deepseek-v3",
"deepseek-r1"
],
"transformer": {
"use": [
[
"maxtoken",
{
"max_tokens": 16384
}
]
]
}
}
],
"Router": {
"default": "oneapi,deepseek-v3",
"think": "oneapi,deepseek-r1"
}
}
EOF
|
Restart for it to take effect
For other configuration options, see https://github.com/musistudio/claude-code-router/blob/main/README_zh.md
4. Using claude code
The ccr code command provided by claude-code-router is used in exactly the same way as the claude command provided by claude-code.
4.1 Interactive
Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| Enter to confirm ยท Esc to exit
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โป Welcome to Claude Code! โ
โ โ
โ /help for help, /status for your current setup โ
โ โ
โ cwd: /root โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Overrides (via env): โ
โ โ
โ โข API timeout: 600000ms โ
โ โข API Base URL: http://127.0.0.1:3456 โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ >ๅธฎๆๆฃๆฅๅฝๅ่็นไธ GPU ๅก็็ถๆ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
|
4.2 Non-interactive
1
| ccr code -p "ๆไนๆ ท็ปk8s้็พค็ปญ่ฏไนฆ"
|
Output
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
| Service not running, starting service...
็ปKubernetes้็พค็ปญ่ฏไนฆไธป่ฆๆถๅไปฅไธๅ ไธชๆญฅ้ชค๏ผ
1. ๆฃๆฅๅฝๅ่ฏไนฆๆๆๆ๏ผ
```bash
kubeadm alpha certs check-expiration
````
2. ็ปญ่ฎขๆๆ่ฏไนฆ๏ผๆงๅถๅนณ้ข๏ผ๏ผ
```bash
kubeadm alpha certs renew all
```
3. ้ๅฏๆงๅถๅนณ้ข็ปไปถ๏ผ
```bash
docker restart $(docker ps | grep kube-apiserver | awk '{print $1}')
docker restart $(docker ps | grep kube-controller-manager | awk '{print $1}')
docker restart $(docker ps | grep kube-scheduler | awk '{print $1}')
```
4. ๆดๆฐ kubeconfig ๆไปถ๏ผ
```bash
kubeadm alpha kubeconfig user --org system:masters --client-name kubernetes-admin
```
5. ้ช่ฏๆฐ่ฏไนฆ๏ผ
```bash
openssl x509 -noout -text -in /etc/kubernetes/pki/apiserver.crt | grep Not
```
ๆณจๆ๏ผ
- ่ฟไบๆไฝ้่ฆๅจ master ่็นไธๆง่ก
- ๅฆๆๆฏ้ซๅฏ็จ้็พค๏ผ้่ฆๅจๆๆ master ่็นไธๆง่ก
- ็ปญ่ฎขๆไฝไธไผๅฝฑๅๆญฃๅจ่ฟ่ก็ pod ๅๆๅก
claude code router service has been successfully stopped.
|
If you need to run commands on the host, this approach does not work very well, because it requires manual confirmation and then terminates. If you are a non-root user, you can add --permission-mode bypassPermissions to skip the permission check.
The latest version already supports configuring a third-party API directly.
1
| vim ~/.claude/settings.json
|
1
2
3
4
5
6
7
| {
"env": {
"ANTHROPIC_AUTH_TOKEN": "sk-",
"ANTHROPIC_BASE_URL": "https://xxx.com",
"ANTHROPIC_MODEL": "default"
}
}
|