Skip to content

ANTHROPIC_BASE_URL rewritten to 127.0.0.1:15721 (Claude Code)

Quick fix

With local routing on, ANTHROPIC_BASE_URL pointing at http://127.0.0.1:15721 is expected. Move shared fields into 通用配置 and restart Claude Code.

Error output
文件内容变成{
  "env": {
    "ANTHROPIC_BASE_URL": "http://127.0.0.1:15721",
    "ANTHROPIC_API_KEY": "PROXY_MANAGED"
  }
}
English translation

The file contents became { "env": { "ANTHROPIC_BASE_URL": "http://127.0.0.1:15721", "ANTHROPIC_API_KEY": "PROXY_MANAGED" } }

Per #2635: with routing off, cc-switch only changes the URL in settings.json to the selected provider. With local routing on, the chain becomes Claude Code -> cc-switch listening locally on http://127.0.0.1:15721 (possibly converting formats) -> the upstream provider, so ANTHROPIC_BASE_URL on the Claude Code side points at 127.0.0.1:15721. A maintainer explained in #2644 that switching Claude provider writes ~/.claude/settings.json as a whole: only the request address ANTHROPIC_BASE_URL and the key belong to the provider, while enabledPlugins, hooks, statusLine, and permissions have to travel through 通用配置 (general config) or they look wiped. But #3008 and #4096 also report a switch rewriting the current provider/model or backfilling live config over the old provider — so "expected wholesale write" and "unexpected overwrite" coexist. Anomalous data can be recovered from ~/.cc-switch/backups/.

The cluster holds a few more variants. #1050: older versions pinned ANTHROPIC_BASE_URL to http://localhost:5000; maintainers say v3.9.1 changed the default proxy port from 5000 to 15721 because of a macOS AirPlay conflict, and suggest verifying on v3.12.3. #927: Claude Code reads settings.json once at startup, so /status still shows the old URL after a switch until you restart. #2427: in OpenAI Chat Completions routing mode, the local routing URL and the upstream provider_endpoints.url must not both be 127.0.0.1:15721, or it self-references. #3311/#888: the VS Code plugin may read process.env or claudeCode.environmentVariables rather than ~/.claude/settings.json, and users report commenting out the old variable working for some while still failing on macOS for others.

  1. First confirm whether cc-switch local routing/proxy is on. If it is, ANTHROPIC_BASE_URL being http://127.0.0.1:15721 for Claude Code is expected — do not also set the upstream OpenAI-compatible address to that same local address. The upstream address belongs in the provider's provider_endpoints.url, so requests are not routed back into cc-switch itself.

    ~/.claude/settings.json
    {
    "env": {
    "ANTHROPIC_BASE_URL": "http://127.0.0.1:15721"
    }
    }
  2. If plugins, hooks, permissions, or statusLine disappear after a switch: go to 编辑供应商 -> 通用配置面板 -> 从当前供应商提取 (Edit provider > General config panel > Extract from current provider) and save those shared fields, then keep 写入通用配置 (write general config) ticked when creating or switching providers. The default provider imported at first launch, and the backups, may also still hold the original config.

  3. Restart Claude Code after switching provider before checking /status. Claude Code loads settings.json once at startup and does not hot-reload env.

  4. If ANTHROPIC_BASE_URL is stuck at http://localhost:5000 and will not change, upgrade cc-switch. Maintainers say that pinning was fixed in v3.9.1 (default proxy port 5000 -> 15721) and suggest verifying on v3.12.3.

  5. If the VS Code plugin does not apply or reports API Error: 400, check and comment out or delete the old claudeCode.environmentVariables, or mirror the same env you use in the terminal into your VS Code user settings. Some users say rolling the Claude Code plugin back from 2.1.156 to an earlier version recovers it, while #888 has reports of commenting out still failing on macOS — go by your actual OUTPUT / Claude VSCode logs.

    ~/Library/Application Support/Code/User/settings.json
    {
    "claudeCode.environmentVariables": [
    // { "name": "ANTHROPIC_BASE_URL", "value": "xxxxx" },
    // { "name": "ANTHROPIC_AUTH_TOKEN", "value": "x'x'x'x'x" }
    ]
    }
  6. If you suspect cc-switch backfilled the previous provider's config over the current one, stop switching back and forth immediately, restore from the daily database backup under ~/.cc-switch/backups/, and re-check against the reproduction steps in #4096.

ToolClaude Code
Versioncc-switch v3.10.3 起报告;localhost:5000 锁定称在 v3.9.1 修复、建议 v3.12.3 验证
PlatformsWindowsmacOS
With routing on and Claude enabled, why do I still see 127.0.0.1:15721/v1 under the Claude provider?
That is the local routing entry point: Claude Code sends Anthropic format to cc-switch on 127.0.0.1:15721, and cc-switch may convert the format before sending it to the selected provider. Do not also write that local address as the upstream third-party OpenAI-compatible address, or it self-references and fails.
/status still shows the old ANTHROPIC_BASE_URL after switching provider. Did cc-switch fail to write it?
Not necessarily. The root cause in #927 is that Claude Code loads settings.json once at startup: the file is updated but the running process still holds the old value. Restart Claude Code and look again.
My plugin config disappeared after switching provider.
A maintainer called this expected in #2644: a switch writes ~/.claude/settings.json as a whole, and shared fields have to go through 通用配置 (general config). Run 从当前供应商提取 (extract from current provider) first, then keep 写入通用配置 (write general config) ticked when switching. If fields still go missing, check the default provider and ~/.cc-switch/backups/.
claude works in the terminal but the VS Code plugin 400s or ignores the switch. What now?
#3311 analysed that the newer plugin's embedded SDK reads ANTHROPIC_BASE_URL from process.env, which a GUI launch does not have. Write claudeCode.environmentVariables by hand, or roll the plugin back from 2.1.156 to an earlier version as users report. In #888, commenting out the old variable worked for some and still failed on macOS for others — reports are inconsistent.

This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.