ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY both set - cc-switch
Quick fix
Open ~/.claude/settings.json, delete the duplicate auth variable so only the one your provider needs remains, save, and restart Claude Code.
Symptom
Section titled “Symptom”Both ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY set · auth may not work as expectedcc-switch writes auth fields into the `env` block of `~/.claude/settings.json` when switching between providers, and the previous auth field can be left behind during the switch. In #4919, switching from DeepSeek/MiMo to Codex left `ANTHROPIC_API_KEY` and `ANTHROPIC_AUTH_TOKEN` both present, so Claude Code printed `Both ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY set · auth may not work as expected`. It has been reported on 3.15.0 (#3455), 3.16.4 (#4715), and 3.16.5 (#4919). The reporter in #4919 noted conversations still worked despite the warning, so it does not necessarily break a session immediately — but auth behaviour has entered an unpredictable path.
The same class of environment variable handling has other variants: the DeepSeek usage query reading `env.ANTHROPIC_AUTH_TOKEN || env.ANTHROPIC_API_KEY` may still not see the saved key and reports `API key is empty` (#2986, which a maintainer says overlaps a group of problems fixed in v3.16.0/v3.16.1, without confirming this presentation specifically); with local routing enabled for DeepSeek/GLM, only `ANTHROPIC_DEFAULT_FABLE_MODEL` is replaced in `settings.json` while Haiku/Opus/Sonnet keep their old values (#4715); and some users still time out after creating `settings.json` by hand with `ANTHROPIC_AUTH_TOKEN`/`ANTHROPIC_BASE_URL` (#3455). Together these show environment variable injection into the same file behaves inconsistently across environments and provider combinations.
Back up and open `~/.claude/settings.json` (`C:\Users\<username>\.claude\settings.json` on Windows).
~/.claude/settings.json {"env": {"ANTHROPIC_AUTH_TOKEN": "PROXY_MANAGED","ANTHROPIC_BASE_URL": "http://127.0.0.1:15721"}}Check the `env` block. If `ANTHROPIC_AUTH_TOKEN` and `ANTHROPIC_API_KEY` are both present, delete the one your current provider does not need: keep `ANTHROPIC_AUTH_TOKEN` for an Anthropic-compatible relay such as DeepSeek/MiMo, and keep `ANTHROPIC_API_KEY` for Codex depending on its auth method.
Save, then restart Claude Code or switch provider again, and confirm `Both ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY set · auth may not work as expected` is gone. If the balance query still reports `API key is empty`, upgrade to v3.16.1 or newer and check again.
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 4 real issues
- Is there a workaround for this?
- Edit `~/.claude/settings.json` by hand and keep only one auth field in `env` (`ANTHROPIC_AUTH_TOKEN` or `ANTHROPIC_API_KEY`), delete the other, and restart.
- Does having both auth variables affect actual conversations?
- In #4919 the reporter could still converse normally, but Claude Code warns `auth may not work as expected` and auth behaviour is no longer as intended. Keep only one.
- Why do I still time out after following the manual settings.json approach?
- A user in #3455 reported it not helping. That may be an environment difference or a toggle not applying — confirm only the variable your current provider needs is present, and re-verify on v3.16.1+.
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.