Skip to content

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.

Error output
Both ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY set · auth may not work as expected

When 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).

  1. 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.

  2. 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"
    }
    }
  3. 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.

  4. 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.

ToolClaude Code
VersionUnknown
PlatformsWindowsmacOSLinux
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.

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.