Skip to content

Cannot use Google-email Codex account after opening cc switch - Codex

Quick fix

A third-party key in ~/.codex/auth.json overrode ChatGPT login: add the official provider in CC Switch and switch back to restore login, and upgrade to…

Error output
只下载codex.app 使用谷歌邮箱登录可以使用,打开cc switch 之后只能走cc switch ,关闭cc switch 的codex 配置,也无法使用谷歌邮箱登录的codex账号
English translation

With only codex.app downloaded, logging in with a Google email works. After opening cc switch, everything goes through cc switch, and even with the cc switch Codex config turned off, the Google-email Codex account still cannot be used.

The root cause is how CC Switch handles `~/.codex/auth.json` and `~/.codex/config.toml` when switching Codex providers. Early versions wrote a third-party provider API key into `OPENAI_API_KEY` in `auth.json`; Codex Desktop then treated the session as `auth_mode="ApiKey"`, so the ChatGPT/OAuth login state became invalid and account-dependent features such as Fast mode and Remote Control stopped working (#3034). Conversely, when `auth.json` kept `auth_mode = "chatgpt"` and `OPENAI_API_KEY = null` while the key lived only in `experimental_bearer_token` in `config.toml`, `codex doctor` still showed ChatGPT auth, and usage could be billed to the ChatGPT account instead of the API project (#3596). Reports about the latter conflict: one user observed Remote Control sessions bypassing the custom provider and still consuming ChatGPT quota, but the same user later said it returned to normal with correct API billing without any changes, so it is unclear whether this is fully resolved. The maintainer said CC Switch 4.0 rewrote the Codex switching logic: third-party providers are always written as `[model_providers.custom]` + `experimental_bearer_token`, the official login is kept or staged according to settings, and `requires_openai_auth` is recomputed from the actual on-disk login state.

This problem has several variants: manually deleting `OPENAI_API_KEY` in the official provider editor does not persist and the key is rewritten on save (#3903; root cause is that `write_codex_live_for_provider` writes only `config.toml` when the submitted auth is empty, merged into #3566 for tracking); Codex usage/cost query does not display (#2776; root cause is the query path only read Claude `ANTHROPIC_*` environment variables while the Codex key is stored in `auth.OPENAI_API_KEY`, fixed in v3.16.1 via #3355); after switching to a custom provider, `codex resume` fails unless `-c 'model_provider="custom"'` is added (#6608; resume reads the provider recorded in the session rather than the current config value, no official fix yet); Codex Desktop model selector is blank (#5679; the reporter believes `/v1/models` returns `models[]` instead of the OpenAI `data[]` format, but another user cited the Codex 0.147 local cache structure to argue the internal contract is `models[]` + snake_case, and the real break may be a missing `OPENAI_API_KEY` environment variable causing an empty first fetch that is never retried — both claims remain undecided).

  1. If you were switched away and cannot get back to the official account: add an "official" provider in CC Switch and switch to it to restore the Google-email (ChatGPT) Codex login. See the FAQ section of the README (maintainer-confirmed approach, #1358).

  2. You can also edit files manually without CC Switch: keep the official login in `~/.codex/auth.json` (`auth_mode` set to `chatgpt`, `OPENAI_API_KEY` set to null), and put the relay URL and token into `base_url` and `experimental_bearer_token` under `[model_providers.OpenAI]` in `~/.codex/config.toml` (user-verified approach in #1358).

    ~/.codex/auth.json
    {
    "auth_mode": "chatgpt",
    "OPENAI_API_KEY": null
    }
    # ~/.codex/config.toml
    model_provider = "OpenAI"
    [model_providers.OpenAI]
    name = "OpenAI"
    base_url = "xxxx"
    wire_api = "responses"
    experimental_bearer_token = "xxxx"
    requires_openai_auth = true
  3. Upgrade to CC Switch v3.16.1 or later: that release fixed a custom provider key being written into `auth.json` and forcing `auth_mode="ApiKey"` (#3034), and fixed Codex usage queries failing because credentials were read only from `ANTHROPIC_*` (#2776, fix PR #3355).

  4. If billing or login state is still doubtful after upgrading, run `codex login status` and `codex doctor` to self-check: confirm `auth mode`, `stored API key`, `stored ChatGPT tokens`, and `reachability mode` match expectations (API billing should show `Logged in using an API key` / `reachability mode: API key auth`). If usage still lands on the ChatGPT account, report to #3596 with CC Switch and Codex versions plus doctor output (maintainer advice; 4.0 rewrote the Codex switching logic).

  5. If a leftover `OPENAI_API_KEY` in the official provider cannot be deleted and is auto-filled again after save: this is a known bug (#3903, merged into #3566 for centralized tracking). There is currently no workaround; watch #3566 for the fix.

  6. If the symptom is `codex resume --last` failing after switching to a custom provider while new sessions work: the temporary workaround is to explicitly pass `codex -c 'model_provider="custom"' resume --last` at startup (#6608; that issue is still open with no formal fix).

ToolCodex(Codex Desktop / codex CLI)
Version报告涉及 CC Switch 3.14.1 - 3.19.2;其中 #3034、#2776 在 v3.16.0/v3.16.1 修复,4.0 重写了 Codex 切换逻辑;#3903(残留 key 删不掉)与 #6608(resume 失效)在 3.19.2 上仍存在
PlatformsWindowsmacOS
After CC Switch takes over, I cannot get back to the Google-email Codex account. How do I fix it?
Add an official provider in CC Switch and switch to it to restore access (maintainer's own words; see the FAQ in the README). Or edit files manually: keep `auth_mode = "chatgpt"` and `OPENAI_API_KEY = null` in `auth.json`, and put the relay config into `experimental_bearer_token` in `config.toml`.
With "keep official login" enabled, after switching to a third party does billing go through the API key or ChatGPT quota? Any progress?
Unclear. One user observed local sessions billed to the third party while Remote Control sessions still consumed ChatGPT quota; the same user later reported it returned to normal without any changes. The maintainer recommends upgrading to the latest version and re-checking with `codex doctor`; if usage still lands on the ChatGPT account, post versions and output in #3596.
Why does `OPENAI_API_KEY` reappear after I delete it in the official provider and save?
This is a known bug (#3903): `write_codex_live_for_provider` writes `auth.json` only when the submitted auth contains login material. After the key is cleared the submission is empty, the old `auth.json` is kept as-is, and the editor reads the old value back. It has been merged into #3566 for centralized tracking; watch that issue for the fix.
Why is Claude Code usage statistics normal while Codex never shows?
This is issue #2776: the usage query path took credentials only from Claude `ANTHROPIC_*` environment variables, while the Codex key is stored in `auth.OPENAI_API_KEY`, so Codex queried with empty credentials and failed. It was fixed in v3.16.1 (#3355 introduced per-app credential resolution); just upgrade.
Is the blank Codex Desktop model selector an `OPENAI_API_KEY` problem?
Possibly related but undecided: #5679 argues CC Switch `/v1/models` returns `models[]` instead of the OpenAI `data[]` format and parsing fails; another user disputed that using the Codex 0.147 cache structure and observed `Missing environment variable: OPENAI_API_KEY` causing an empty first fetch after which `model/list` is not retried. The issue is still open.

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.