Claude Code error Auth conflict:Both a token and an API key are set - cc-switch
Quick fix
Remove primaryApiKey from ~/.claude.json or add "auth_mode": "bearer_only". Restore overwritten settings via default or manage shared settings with Common…
Symptom
Section titled “Symptom”Auth conflict:Both a token (ANTHROPIC_AUTH_TOKEN) and an API key (/login managed key) are set. This may lead to unexpected behavior.cc-switch rewrites Claude Code configuration files when switching providers, causing two types of problems: conflicting environment variables and overwritten settings.
Authentication conflicts: Selecting the second login option in Claude Code (API key login) creates a primaryApiKey field in ~/.claude.json. cc-switch only writes ANTHROPIC_AUTH_TOKEN to ~/.claude/settings.json. When both exist, Claude Code detects multiple authentication sources and reports Auth conflict. Some users resolved this by adding "auth_mode": "bearer_only" or deleting primaryApiKey. However, the maintainer noted that primaryApiKey is required for official keys, so deleting it may break official login.
Overwritten settings: cc-switch replaces configuration files instead of merging them. Different providers may require specific fields, such as CLAUDE_CODE_MAX_OUTPUT_TOKENS for LongCAT, that can cause side effects for other providers. The developer therefore chose full replacement over field-level merging. This can remove existing hooks, permissions, and env settings. The initial configuration is saved as the default provider and can be restored by switching back. Users must manually maintain settings shared across providers through Common Config.
404 error with a local llama.cpp deployment: cc-switch currently has problems supporting the llama.cpp /v1/messages endpoint. Temporarily use tools such as CherryStudio, or wait for an official fix.
Windows PowerShell (管理员) netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=15722 connectaddress=127.0.0.1 connectport=15721New-NetFirewallRule -DisplayName "WSL CCS Proxy 15722" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 15722
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 7 real issues
- #288switch provider will override some other variables in env
- #366为什么直接把我原有的配置全部覆盖了啊?
- #799关于绑定IP 127.0.0.1问题
- #913如何配置供应商类型
- #1049CC Switch配置模型后,终端Claude显示Auth conflict:Both a token (ANTHROPIC_AUTH_TOKEN) and an API key (/login managed key) are set. This may lead to unexpected behavior.
- #1370llama.cpp部署的模型无法使用
- #5669bug(claude-desktop): direct providers default to ANTHROPIC_AUTH_TOKEN
- My hooks and permissions settings disappeared after switching providers. Can I restore them?
- The initial configuration is automatically saved as the default provider. Switch back to default to restore it. Use Common Config afterward to maintain shared settings across providers and prevent them from being overwritten.
- I deleted primaryApiKey, but the warning persists. Why?
- Check whether ANTHROPIC_API_KEY or other authentication variables are set in your system environment. Also confirm that no old settings remain in ~/.claude/settings.json.
- WSL cannot connect to cc-switch on Windows and reports that the connection was refused. What should I do?
- v3.9.0+ supports changing the listening address to 0.0.0.0. After changing it, manually point ANTHROPIC_BASE_URL in WSL to the Windows LAN IP and ensure that Windows Firewall allows the port. Windows 10 users can switch to WSL2 mirrored networking (networkingMode=mirrored).
- A model deployed with llama.cpp returns 404 in cc-switch, but curl tests work. Why?
- This is a known issue. The cc-switch proxy layer may have compatibility problems with the llama.cpp response format. There is currently no official fix; temporarily use another client.
- Claude Desktop reports authentication failure after saving a provider, even though the key is correct. Why?
- cc-switch stores credentials as ANTHROPIC_AUTH_TOKEN by default, but Claude Desktop direct mode requires ANTHROPIC_API_KEY. Edit the provider and rename the field to ANTHROPIC_API_KEY.
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.