Skip to content

auth becomes {}, API Key lost - cc-switch Codex

Quick fix

If ~/.codex/auth.json is missing, saving the active Codex provider clears auth.OPENAI_API_KEY in the DB. Restore the key before saving or avoid saving.

Error output
重新查看数据库或再次打开编辑弹窗:auth 已变为 {},API Key 丢失。
English translation

Check the database again or reopen the edit dialog: auth has become {}, and the API Key is missing.

For the active Codex provider, the edit dialog reads live settings and replaces the initial form values entirely. EditProviderDialog.tsx calls getLiveProviderSettings when provider.id === currentId and overwrites the initial values with the live settings on success. The live auth comes from read_codex_live_settings(), which reads ~/.codex/auth.json directly and returns {} if the file is missing.

The only key restoration safeguard, reconcileCodexLiveAuth(), handles experimental_bearer_token in config.toml. When a custom provider authenticates through the Authorization request header, auth.json is missing, and config contains no experimental_bearer_token, auth in the initial form values is empty. Saving then overwrites and clears the stored auth.OPENAI_API_KEY in the DB. Once the key is cleared, the usage query logic in v3.20.3 also incorrectly classifies the provider as an official subscription, causing the saved custom usage query configuration to be reset and discarded.

  1. When editing the active Codex provider, if the auth field is empty, manually restore the API Key before saving. Alternatively, avoid saving this provider through the edit dialog for now to prevent empty auth from overwriting the credentials in the DB.

    ~/.codex/auth.json
    # 本机 auth.json 缺失时,live 配置返回 {},保存会清空 DB 中的 key
ToolCodex
Version3.20.1 - 3.20.3
PlatformsWindows
Why does the API Key disappear after I edit and save the active Codex provider?
The edit dialog replaces the initial form values entirely with live settings read from ~/.codex/auth.json. If that file is missing, it returns an empty object {}, and saving overwrites and clears the stored auth.OPENAI_API_KEY in the database.
Why did my custom usage query configuration also stop working?
After the key is cleared, cc-switch incorrectly classifies the provider as an official subscription. This causes the saved meta.usage_script, such as a custom balance query configuration, to be reset and discarded when the dialog opens. The preset template section is also filtered to show only official subscription templates.

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.