Skip to content

auth.json under .claude is forcibly replaced after a restart - Codex

Quick fix

Upgrade cc-switch to the latest version, or turn proxy takeover off before signing in officially, so a stale snapshot cannot overwrite official credentials.

Error output
只要退出cc switch,重启后.claude下的auth.json会被强制替换
English translation

Whenever I quit cc switch, auth.json under .claude is forcibly replaced after the restart

In 3.19.2 and earlier, cc-switch snapshots auth.json when proxy takeover is enabled, but that snapshot is not updated dynamically as you sign in officially. On quit or restart, the restore logic uses the stale snapshot — which contains a third-party API key — and overwrites the official credentials you just signed in with.

Separately, from 3.16.0 on cc-switch uses a new auth separation scheme: the official login state lives in auth.json while third-party API keys and similar settings live in config.toml. Switching frequently between official and third-party configurations makes it very easy for the auth state in those two files to overwrite or pollute each other if the snapshot or restore logic mishandles it.

  1. Upgrade cc-switch to the latest version. The fixed version checks the live auth.json before writing back and keeps genuine official login credentials rather than overwriting them from an old snapshot.

  2. If you cannot upgrade yet, use the workaround: turn Codex takeover off, sign in to your official ChatGPT account, then turn takeover on again — the snapshot then contains the correct login credentials.

  3. To disable API injection entirely and go back to an official account, add an official provider in the cc-switch preset providers and switch to it, then click File > Sign out in the app and sign in again.

ToolCodex
Version3.16.0 - 3.19.2
PlatformsWindowsmacOS
Why does OPENAI_API_KEY in auth.json become null after switching to the official config?
That is the new mechanism introduced in 3.16.0. auth.json holds only the official account login state (where OPENAI_API_KEY is null), while third-party API keys and endpoints live in config.toml. The file is not polluted.
Why does the usage query page vanish or fail after a while?
In early versions such as 3.16.2, the usage script could not read the third-party credentials from config.toml correctly. That was fixed in v3.16.3, after which the usage query retries automatically and reuses the correct credential resolution logic.

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.