codex-switch is a tiny zero-dependency CLI for switching Codex between:
- API key mode
- OAI subscription login mode
It swaps these active Codex files:
~/.codex/config.toml~/.codex/auth.json
with saved mode files:
- API mode:
config.toml.apiandauth.json.api - OAI mode:
config.toml.oaiandauth.json.oai - Compatibility files:
config.toml.openaiandauth.json.openaiare also supported
One-line install:
curl -fsSL https://raw.githubusercontent.com/Catherina0/codex-switch/main/install.sh | bashIf codex-switch is not found after installation, add this to your shell profile:
export PATH="$HOME/.local/bin:$PATH"Then restart the terminal or run:
source ~/.zshrcYou can also install from a clone:
git clone https://github.com/Catherina0/codex-switch.git
cd codex-switch
make installFirst, save the mode you are currently logged in with:
codex-switch initThe tool will ask:
Which mode are the current active Codex files using?
1) oai - ChatGPT/OAI subscription login
2) api - API key login
Choose [1/oai, 2/api]:
Then log in with the other Codex mode and run the same command again:
codex-switch initCheck that both modes are ready:
codex-switch doctorDaily switching:
codex-switch api
codex-switch oaiAfter a successful switch, codex-switch restarts Codex automatically so the new auth files are loaded.
Before switching, codex-switch tries to identify the current active mode and writes the current active config.toml and auth.json back to that mode's saved files. This keeps refreshed OAI/ChatGPT tokens from being overwritten by an old auth.json.oai snapshot on the next switch.
The automatic save preserves saved custom provider definitions, so OAI mode can still open conversations that were created with an API provider.
Skip the automatic save when needed:
codex-switch --no-auto-save api
CODEX_SWITCH_AUTO_SAVE_CURRENT=0 codex-switch oaiSkip the restart when needed:
codex-switch --no-restart api
CODEX_SWITCH_RESTART=0 codex-switch oaiCheck current status:
codex-switch statusFor scripts or users who already know the current active mode:
codex-switch init api
codex-switch init oaiOverwrite an existing saved mode:
codex-switch init api --force
codex-switch init oaiThe older openai command name remains an alias, but new usage should prefer oai.
By default, Codex files live in ~/.codex.
Use CODEX_HOME:
CODEX_HOME=/path/to/.codex codex-switch statusOr use --codex-home:
codex-switch --codex-home /path/to/.codex status
codex-switch --codex-home /path/to/.codex oaiPaths with spaces are supported.
Before switching modes, codex-switch backs up the active files with a timestamp:
config.toml.backup-YYYYMMDD-HHMMSS-before-api
auth.json.backup-YYYYMMDD-HHMMSS-before-api
It never prints the contents of config.toml or auth.json.
codex-switch status
codex-switch init
codex-switch init api
codex-switch init oai
codex-switch switch api
codex-switch switch oai
codex-switch --no-restart api
codex-switch --no-auto-save api
codex-switch api
codex-switch oai
codex-switch doctor
codex-switch --version
codex-switch --helpmake testThe test suite covers:
- interactive initialization
- non-interactive initialization
- switching both modes
- automatic Codex restart after switching
- timestamped backups
.oaimode files and.openaicompatibility files- missing mode failure behavior
- paths with spaces
CODEX_HOME--codex-home
make distRelease artifacts are written to dist/.
rm -f "$HOME/.local/bin/codex-switch"Or, from a clone:
make uninstall