Skip to main content

首页 / Posts

[VS Code] Use ccr code to Connect Claude Code Without Switching Windows

A hands-on VS Code and Claude Code Router guide: configure CCR, set API keys in ccr ui, set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN, then launch Claude inside VS Code.

Rosetears·
··673 words·4 mins

1. Preparation
#

1. Install Claude Code CLI
#

Install the CLI globally with npm.

2. Install and start CCR
#

Install Claude Code Router (CCR) and run ccr start. When the output shows a local address such as [redacted-ip]:3456, the local CCR service has started.

CCR is like a reverse proxy: you tell Claude Code to send requests through CCR, and CCR decides which backend model service receives them.

2. Set the CCR API key
#

After CCR starts, configure an authentication key.

Config file paths:

  • Windows: %UserProfile%\.claude-code-router\config.json
  • macOS / Linux: ~/.claude-code-router/config.json

Find the "APIKEY": "" field and fill in a custom fake API key for local authentication, for example sk-ant-local-ccr-1234567890.

This is not the real large-model API key. It is a local access token used by CCR.

Then open the CCR UI with ccr ui, add the model service you want to use, and enter the real model API key in that provider configuration.


3. Redirect Claude Code to CCR with environment variables
#

Claude Code supports gateway and auth configuration through environment variables. Set:

  • ANTHROPIC_BASE_URLhttp://[redacted-ip]:3456
  • ANTHROPIC_AUTH_TOKEN → the APIKEY configured above

On Windows, use administrator PowerShell and setx for permanent variables, plus $env: assignments for the current window. On macOS/Linux, add export lines to your shell profile such as ~/.zshrc, then source it.

Verify with echo $env:ANTHROPIC_BASE_URL and echo $env:ANTHROPIC_AUTH_TOKEN on PowerShell, or echo $ANTHROPIC_BASE_URL and echo $ANTHROPIC_AUTH_TOKEN on macOS/Linux.


4. Verify CCR
#

  1. Make sure CCR is running with ccr start.
  2. Open a new VS Code terminal so it inherits the environment variables.
  3. Start Claude Code with claude.
  4. Run /status and /doctor to check the Anthropic Base URL and auth token source.

Expected status information includes the CCR base URL and ANTHROPIC_AUTH_TOKEN as the token source.


5. Integrate with VS Code
#

Recommended use: start claude inside the VS Code integrated terminal. If the status bar shows an IDE marker, the IDE integration is mounted. If you start from an external terminal, use /ide in the TUI to mount VS Code manually.

Running ccr code only starts the CLI. It does not automatically mount the VS Code extension. Start from the VS Code terminal for the best result.

Fix missing code command on Windows
#

If /ide cannot find VS Code, add VS Code’s bin directory to PATH and restart VS Code. The preserved PowerShell script below locates common install paths, updates the user PATH without overwriting existing values, verifies where.exe code, and restarts VS Code.

Preserved command, configuration, and prompt blocks
#

1
npm i -g @anthropic-ai/claude-code
1
2
npm i -g @musistudio/claude-code-router
ccr start
1
"APIKEY": "sk-ant-local-ccr-1234567890"
1
ccr ui
1
2
3
4
5
6
setx ANTHROPIC_BASE_URL "http://[redacted-ip]:3456"
setx ANTHROPIC_AUTH_TOKEN "sk-ant-local-ccr-1234567890"

# 当前窗口立即生效(可选)
$env:ANTHROPIC_BASE_URL="http://[redacted-ip]:3456"
$env:ANTHROPIC_AUTH_TOKEN="sk-ant-local-ccr-1234567890"
1
2
echo $env:ANTHROPIC_BASE_URL
echo $env:ANTHROPIC_AUTH_TOKEN
1
2
3
4
echo 'export ANTHROPIC_BASE_URL="http://[redacted-ip]:3456"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="sk-ant-local-ccr-1234567890"' >> ~/.zshrc

source ~/.zshrc  # 立即生效
1
2
echo $ANTHROPIC_BASE_URL
echo $ANTHROPIC_AUTH_TOKEN
 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
    ccr start
    ```

```bash
    claude
    /status     # 查看当前 Base URL、鉴权来源、代理配置等
    /doctor     # 运行系统诊断,核对“Anthropic Base URL”“Auth Token”是否生效
    ```

```yaml
	Anthropic Base URL: http://[redacted-ip]:3456
	Auth Token: ANTHROPIC_AUTH_TOKEN
	```

```bash
	claude
	```

```powershell
# 1) 自动定位 code.cmd 的路径(常见安装位置)
$codePaths = @(
  "$env:LOCALAPPDATA\Programs\Microsoft VS Code\bin",
  "C:\Program Files\Microsoft VS Code\bin",
  "$env:USERPROFILE\AppData\Local\Programs\Microsoft VS Code\bin"
)
$codeBinPath = $codePaths | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $codeBinPath) { Write-Host "❌ 未能在常见位置找到 VS Code 的 'bin' 目录。请手动添加到 PATH。"; return }
Write-Host "✅ 成功定位到 VS Code 'bin' 目录: $codeBinPath"

# 2) 添加到当前会话与用户永久 PATH(不覆盖原值)
$currentUserPath = [Environment]::GetEnvironmentVariable('PATH','User')
if ($currentUserPath -notlike "*$codeBinPath*") {
  $newUserPath = "$currentUserPath;$codeBinPath"
  [Environment]::SetEnvironmentVariable('PATH',$newUserPath,'User')
  $env:PATH = $newUserPath
  Write-Host "✅ 已将目录永久添加到用户 PATH。请重启 VS Code!"
} else {
  Write-Host "ℹ️ 目录已存在于 PATH 中,无需重复添加。"
}

# 3) 验证
where.exe code  # 应能输出 code.cmd 的路径

# 4) 彻底重启 VS Code(让新 PATH 被“集成终端”继承)
Start-Sleep -Seconds 1
taskkill /F /IM Code.exe 2>$null

Related tools

Related