Codex provider API keys overwrite each other after a restart or switch - CC Switch
Quick fix
Enable CC Switch local proxy takeover, or use experimental_bearer_token in config.toml, to bypass the auth.json sync defect.
Symptom
Section titled “Symptom”供应商 A 和 B 的 API Key 在重启/切换后互相覆盖。The API keys of providers A and B overwrite each other after a restart or a switch.
CC Switch has a two-way sync defect in how it maintains API keys between its database and the Codex live config file (~/.codex/auth.json). Because auth.json is a global singleton, switching provider, restarting the app, or creating a config makes the CC Switch backfill/autosync logic read a stale value or an official login state out of auth.json and write it back over the correct config for the current provider in the database. On top of that, the direct file-write path fails in some versions, so what the UI shows and the key actually in effect disagree. The defect produces several variants: a third-party key overwritten by an official OAuth login state, a newly created empty provider polluted by old live data, a leftover third-party key breaking OAuth after switching to an official provider, and the UI edit page showing values from long ago. The cluster also contains an unrelated translator bug: under wire_api=responses, a streaming tool_call's call_id is overwritten by a later empty delta, leaving the tool call hung.
Enable local proxy takeover (recommended). Turn the routing switch on in the CC Switch UI so requests go through the local proxy (127.0.0.1:15721, for example). That mode uses a separate in-memory config path and avoids the overwrite bug triggered by reading and writing auth.json directly.
Bypass with experimental_bearer_token. If you must use direct file-write mode, hard-code the token for the custom provider in the Codex config and turn requires_openai_auth off, bypassing the auth.json global singleton.
~/.codex/config.toml [model_providers.custom]requires_openai_auth = falseexperimental_bearer_token = "YOUR_API_KEY"Clean up and rebuild by hand. If the official OAuth login state is already lost, delete the OPENAI_API_KEY field from ~/.codex/auth.json by hand and run codex login in a terminal to restore the official login. When switching provider, always disable routing first.
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 7 real issues
- #3646Bug: 编辑第三方 Codex provider 时 API Key 字段显示陈年旧值(来自 auth.json)
- #4671[Bug] Codex(wire_api=responses)工具调用假死:function_call 的 call_id 在 output_item.done/response.completed 中被清空
- #4849供应商 API Key 保存后不写 auth.json,重启时被反向覆盖
- #5691Codex: 启用自定义供应商时,Live 配置被回填到新供应商的 DB 记录,覆盖已保存的 API Key 和参数
- #5946供应商切换时第三方 Key 被官方登录态覆盖的问题
- #6236[macOS] v3.19.2 切换 Codex 供应商不写入 ~/.codex/config.toml 与 auth.json,配置不生效
- #6384Switching from routing-enabled provider to official provider leaves stale API key in auth.json
- I saved the right API key in the UI — why does it revert to the old one after a restart?
- Because CC Switch reads the global value from ~/.codex/auth.json at startup and syncs it back into the database. If auth.json was never updated correctly, the old value overwrites the new one you saved in the UI. Enable proxy takeover mode to bypass this file sync logic.
- After switching to an official provider, Codex shows "OpenAI" in the bottom right and my ChatGPT account will not work. What now?
- A third-party OPENAI_API_KEY is left in auth.json, so Codex prefers API key auth and ignores the OAuth token. Clear the OPENAI_API_KEY field in auth.json by hand and run codex login again.
- Codex hangs after a tool call with a third-party model and reports unsupported call. What is that?
- A separate streaming translator bug. Under wire_api=responses, the CC Switch accumulation logic lets a later empty delta overwrite the call_id from the first chunk. There is no configuration workaround — use an official direct connection, or wait for the upstream fix.
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.