codex-auth is a command-line tool for switching Codex accounts and provider profiles discovered from ~/.codex/config.toml.
Important
For Codex CLI and Codex App users, switch accounts, then restart the client for the new account to take effect.
If you use the CLI and want seamless automatic account switching without restarting, use the forked codext, an enhanced Codex CLI. Install it with npm i -g @loongphy/codext and run codext.
codex-auth works with these Codex clients:
- Codex CLI
- VS Code extension
- Codex App
For the best experience, install the Codex CLI even if you mainly use the VS Code extension or the App, because it makes adding accounts easier:
npm install -g @openai/codexAfter that, you can use codex login, codex login --device-auth, codex-auth login, or codex-auth login --device-auth to sign in and add accounts more easily.
Install with npm:
npm install -g @loongphy/codex-authYou can also run it without a global install:
npx @loongphy/codex-auth listnpm packages currently support Linux x64, macOS x64, macOS arm64, Windows x64, and Windows arm64.
Note
If you only installed @loongphy/codex-auth with npm, you do not need any legacy cleanup steps.
Older Bash/PowerShell GitHub-release installs could leave a standalone codex-auth binary outside npm's install path.
If you previously used those legacy installers, remove the leftover binaries and profile changes during migration.
If you are working from a local checkout and want a one-command rebuild/install of the current branch:
bash scripts/source-install.shIf ~/.local/bin is not already on your current PATH, use:
source scripts/source-install.shThat version installs Zig automatically if it is missing, builds the current source tree, installs codex-auth into ~/.local/bin, updates your shell profile for future shells, and also makes the command available immediately in the current shell.
If Zig is already installed and you only want the bare source build/install step, you can still run:
bash scripts/dev-install.shRemove the npm package:
npm uninstall -g @loongphy/codex-authFor non-npm installs on Linux/macOS/WSL2 only:
rm -f ~/.local/bin/codex-auth
rm -f ~/.local/bin/codex-auth-auto
sed -i '/# Added by codex-auth installer/,+1d' ~/.bashrc ~/.bash_profile ~/.profile ~/.zshrc ~/.zprofile 2>/dev/null || trueIf you used fish, also remove the old profile entry:
sed -i '/# Added by codex-auth installer/,+3d' ~/.config/fish/config.fish 2>/dev/null || trueFor non-npm installs on Windows only:
Remove-Item "$env:LOCALAPPDATA\codex-auth\bin\codex-auth.exe" -Force -ErrorAction SilentlyContinue
Remove-Item "$env:LOCALAPPDATA\codex-auth\bin\codex-auth-auto.exe" -Force -ErrorAction SilentlyContinue
[Environment]::SetEnvironmentVariable(
"Path",
(($env:Path -split ';' | Where-Object { $_ -and $_ -ne "$env:LOCALAPPDATA\codex-auth\bin" }) -join ';'),
"User"
)| Command | Description |
|---|---|
codex-auth list |
List all accounts |
codex-auth login [--device-auth] |
Run codex login (optionally with --device-auth), then add the current account |
codex-auth switch [<query>] |
Switch the active account or provider profile |
codex-auth remove [<query>|--all] |
Remove accounts |
codex-auth status |
Show auto-switch, service, target kind, and usage status |
| Command | Description |
|---|---|
codex-auth provider list |
List provider profiles scanned from ~/.codex/config.toml |
| Command | Description |
|---|---|
codex-auth import <path> [--alias <alias>] |
Import a single file or batch import from a folder |
codex-auth import --cpa [<path>] |
Import CLIProxyAPI (CPA) token JSON |
codex-auth import --purge [<path>] |
Rebuild registry.json from existing auth files |
| Command | Description |
|---|---|
codex-auth config auto enable|disable |
Enable or disable background auto-switching |
codex-auth config auto [--5h <%>] [--weekly <%>] |
Set auto-switch thresholds |
codex-auth config api enable|disable |
Enable or disable both usage refresh and team name refresh API calls |
codex-auth config list enable|disable |
Enable or disable refreshing every account before list output |
codex-auth listWhen codex-auth config list enable is on, list refreshes every account's usage via the API before rendering and stores the refreshed snapshots in registry.json. Later switch commands reuse that cached usage data in the picker. Provider profiles are scanned from ~/.codex/config.toml on each list and shown in the same table with PLAN=provider and - usage cells.
Interactive: shows accounts and provider profiles in one picker.
codex-auth switchBefore the picker opens, the current active account's usage is refreshed once so the selected row is not stale. If the active target is a provider profile, auth sync is skipped and ~/.codex/config.toml remains authoritative.
Non-interactive: fuzzy match by email, alias, provider label, or provider id.
codex-auth switch john # match any account containing "john"
codex-auth switch john@gmail.com # match by full or partial email
codex-auth switch work # match by alias set during import
codex-auth switch openrouter # match a scanned provider profileIf the keyword matches multiple targets, the command falls back to interactive selection. Press q to quit without switching.
codex-auth removeremove only deletes stored accounts. Provider profiles stay in ~/.codex/config.toml; edit that file directly if you want to add, change, or remove them.
Add provider blocks directly to ~/.codex/config.toml. codex-auth scans [model_providers.<id>] entries on each list, switch, and provider list.
# ~/.codex/config.toml
model_provider = "openrouter"
disable_response_storage = true
preferred_auth_method = "apikey"
[model_providers.openrouter]
name = "OpenRouter"
base_url = "https://openrouter.ai/api/v1"
wire_api = "responses"
experimental_bearer_token = "sk-test"
# then inspect or switch to it
codex-auth provider list
codex-auth switch openrouterAdd the currently logged-in Codex account:
codex-auth login
codex-auth login --device-authcodex-auth import /path/to/auth.json --alias personalScans all .json files in the directory:
codex-auth import /path/to/auth-exportsTypical output:
Scanning /path/to/auth-exports...
✓ imported token_ryan.taylor.alpha@email.com
✓ updated token_jane.smith.alpha@email.com
✗ skipped token_invalid: MalformedJson
Import Summary: 1 imported, 1 updated, 1 skipped (total 3 files)
stdout carries scanning, success, and summary lines. Skipped files and warnings stay on stderr.
CLIProxyAPI stores tokens as flat JSON under ~/.cli-proxy-api/. Import them directly without conversion:
codex-auth import --cpa # scan default ~/.cli-proxy-api/*.json
codex-auth import --cpa /path/to/cpa-dir # scan a specific directory
codex-auth import --cpa /path/to/token.json --alias bob # import a single CPA fileIf codex-auth list shows missing accounts or wrong usage data, the internal registry file may be out of sync with the actual auth files on disk. This command re-reads all auth files and rebuilds the registry from scratch:
codex-auth import --purge # rebuild from ~/.codex/accounts/*.auth.json
codex-auth import --purge /path/to/auth-exports # rebuild from a specific folderThis does not import new files. It repairs the registry index for auth snapshots that already exist on disk.
codex-auth statusEnable or disable:
codex-auth config auto enable
codex-auth config auto disableconfig auto enable prints the current usage mode after installing the watcher, so you can immediately see whether auto-switch is running with default API-backed usage or local-only fallback semantics.
Adjust thresholds:
codex-auth config auto --5h 12
codex-auth config auto --5h 12 --weekly 8
codex-auth config auto --weekly 8When auto-switching is enabled, a long-running background watcher refreshes the active account's usage and silently switches accounts when:
- 5h remaining drops below the configured 5h threshold (default
10%), or - weekly remaining drops below the configured weekly threshold (default
5%)
The managed background worker is long-running on all supported platforms:
- Linux/WSL: persistent
systemd --userservice - macOS:
LaunchAgent - Windows: scheduled task that launches the long-running helper at logon, restarts it after failures, has no 72-hour execution cap, and also starts it immediately on enable
API-backed fallback:
codex-auth config api enableLocal-only, no usage API calls:
codex-auth config api disableChanging config api updates registry.json immediately. api enable is shown as API mode and api disable is shown as local mode.
Refresh every account during list:
codex-auth config list enable
codex-auth config list disableWhen enabled, each list call refreshes usage for every stored account snapshot before printing the table. Accounts that fail to refresh keep their previous cached usage and print a warning.
If codex-auth is using local-only usage refresh, it reads the newest ~/.codex/sessions/**/rollout-*.jsonl file. Recent Codex builds often write token_count events with rate_limits: null. The local files may still contain older usable usage limit data, but in practice they can lag by several hours, so local-only refresh may show a usage limit snapshot from hours ago instead of your latest state.
- Upstream Codex issue: openai/codex#14880
You can switch usage limit refresh to the usage API with:
codex-auth config api enableThen confirm the current mode with:
codex-auth statusstatus should show usage: api.
Upgrade notes:
- If you are upgrading from
v0.1.xto the latestv0.2.x, API usage refresh is enabled by default. - If you previously used an early
v0.2prerelease/test build andstatusstill showsusage: local, runcodex-auth config api enableonce to switch back to API mode.
Verify with:
codex exec "say hello"This project is provided as-is and use is at your own risk.
Usage Data Refresh Source:
codex-auth supports two sources for refreshing account usage/usage limit information:
- API (default): When
config api enableis on, the tool makes direct HTTPS requests to OpenAI's endpoints using your account's access token. This enables both usage refresh and team name refresh. - Local-only: When
config api disableis on, the tool scans local~/.codex/sessions/*/rollout-*.jsonlfiles for usage data and skips team name refresh API calls. This mode is safer, but it can be less accurate because recent Codex rollout files often containrate_limits: null, so the latest local usage limit data may lag by several hours.
API Call Declaration:
By enabling API(codex-auth config api enable), this tool will send your ChatGPT access token to OpenAI's servers, including https://chatgpt.com/backend-api/wham/usage for usage limit and https://chatgpt.com/backend-api/accounts/check/v4-2023-04-27 for team name. This behavior may be detected by OpenAI and could violate their terms of service, potentially leading to account suspension or other risks. The decision to use this feature and any resulting consequences are entirely yours.