ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY set - cc-switch
Quick fix
Run claude daemon stop --any to kill leftover Claude background processes, then keep only one auth variable in env in ~/.claude/settings.json.
Symptom
Section titled “Symptom”Both ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY set · auth may not work as expectedWhen starting, switching provider, failing over, or restoring a session, cc-switch rewrites `~/.claude/settings.json` directly (and sometimes `~/.claude.json`), overwriting your config wholesale with the `env` fields takeover/proxying needs. Field-level merging was attempted in v3.11.0 and rolled back to full overwrite in v3.11.1 because of state conflicts (see #1570), so custom fields such as `hooks`, `enabledPlugins`, and `spinnerVerbs` are lost.
`ANTHROPIC_AUTH_TOKEN` injection has several variants of its own. With takeover enabled for a managed Codex provider, v3.16.2 fails to inject that field (#3632, #4157). And when you change auth method or restore a session from Agent View, the Claude daemon may hold on to the old auth state, leaving `ANTHROPIC_AUTH_TOKEN` and `ANTHROPIC_API_KEY` both present so Claude Code reports `Both ... set`. Separately, switching away from a deleted provider does not clean the old `env` out of `~/.claude.json`, so routing looks switched while requests still go to the old provider (#1096).
Run `claude daemon stop --any` in a terminal to stop every leftover Claude background process — one of them may still hold the old state after you change auth method.
Open `~/.claude/settings.json` and confirm `env` holds only one auth variable. If both `ANTHROPIC_AUTH_TOKEN` and `ANTHROPIC_API_KEY` are there, delete the one that does not match your current provider. With a routed/managed provider you can set `ANTHROPIC_AUTH_TOKEN` to `PROXY_MANAGED`.
// ~/.claude/settings.json{"env": {"ANTHROPIC_AUTH_TOKEN": "PROXY_MANAGED"}}Put custom fields you need to keep (`hooks`, `enabledPlugins`, `permissions`) into cc-switch general config: 编辑供应商 → 通用配置 → 从当前供应商提取 (Edit provider > General config > Extract from current provider), then tick the write-general-config option when switching. Do not edit `settings.json` directly and fight the cc-switch database.
Upgrade to v3.16.3 or newer, which fixes `ANTHROPIC_AUTH_TOKEN` not being injected during Codex/routing takeover and Claude Code therefore asking you to log in. If you cannot upgrade yet, add `"ANTHROPIC_AUTH_TOKEN": "PROXY_MANAGED"` to `env` by hand.
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 12 real issues
- #674每次重启电脑后,ccswich会覆盖claud code的setting.json,导致enabledPlugins字段被覆盖,插件无法正常使用
- #1096切换到已删除供应商时静默失败,导致配置状态不一致
- #1198CC Switch 启动后会立即改写 `~/.claude/settings.json`,导致用户自定义配置被覆盖/丢失
- #1570cc-switch 覆盖 settings.json 中的 spinnerVerbs 等自定义配置
- #2096故障转移/编辑模型会重置settings.json
- #2105配置项的API_KEY突然消失了,导致配置无法编辑且claude code提示需要登录
- #2440ubuntu系统claude路由无效,
- #3632添加 codex作为Claude Code供应商后提示需要登录(已开路由,settings.json正常)
- #4118Agent View 恢复会话时导致 ANTHROPIC_AUTH_TOKEN 与 ANTHROPIC_API_KEY 同时注入环境
- #4157使用GPT路由部分情况仍然不补全ANTHROPIC_AUTH_TOKEN
- #4200Claude Official leaves Claude Code in API Usage Billing mode
- #5217Claude Desktop问题:切换路由失败,配置文件不存在
- Does this force it to use the local one?
- Claude Code reads `~/.claude/settings.json` first, then `~/.claude/settings.local.json`, deep-merging so `settings.local.json` wins on a shared key. But some settings such as `statusline` may not take effect from `settings.local.json`, so use cc-switch general config to carry shared configuration.
- Is there a fix for this? Do I really have to redo the config file every time I switch model back and forth?
- From v3.16.3 on, takeover injects the `ANTHROPIC_AUTH_TOKEN` placeholder automatically, so switching model or provider no longer needs a manual `settings.json` edit. For custom hooks and plugins, general config carries them across providers.
Related problems
Section titled “Related problems”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.