codex-auth is a command-line tool for switching Codex accounts.
Install with npm:
npm install -g @loongphy/codex-authYou can also run it without a global install:
npx @loongphy/codex-auth listcodex-auth works with these Codex clients:
- Codex CLI
- VS Code extension
- Codex App
Important
For Codex CLI and Codex App users, switch accounts, then restart the client for the new account to take effect.
If you 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 App users can use codex-auth app, but it is not stable. See Details.
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-auth login, or codex-auth login --device-auth to sign in and add accounts more easily.
Detailed command documentation lives in docs/commands/README.md.
Note
This documentation is based on v0.3.x. Some commands described here may not be available in the current release.
To try the latest features, please install the alpha version via:
npm install -g @loongphy/codex-auth@nextIf you want to downgrade to v0.2.x, you may need to manually update the ~/.codex/accounts/registry.json:
"schema_version": 4| Command | Description |
|---|---|
codex-auth list [--live] [--active] [--api|--skip-api] |
List stored accounts and usage state |
codex-auth login [--device-auth] |
Run codex login, then add the current account |
codex-auth switch [--live] [--api|--skip-api] |
Switch the active account interactively |
codex-auth switch <query> |
Switch directly by row number or account selector |
codex-auth remove [--live] [--api|--skip-api] |
Remove accounts interactively |
codex-auth remove <query> [<query>...] |
Remove accounts by selector |
codex-auth remove --all |
Remove all stored accounts |
| Command | Description |
|---|---|
codex-auth import <path> [--alias <alias>] |
Import a single auth file or batch import a folder |
codex-auth import --cpa [<path>] |
Import CLIProxyAPI token JSON |
codex-auth import --purge [<path>] |
Rebuild registry.json from auth files |
codex-auth export [<dir>] |
Export stored account auth files |
codex-auth export --cpa [<dir>] |
Export CLIProxyAPI token JSON |
codex-auth clean |
Delete managed backup and stale account files |
| Command | Description |
|---|---|
codex-auth config live --interval <seconds> |
Configure live TUI refresh interval |
codex-auth list
codex-auth list --active
codex-auth switch
codex-auth switch 02
codex-auth remove work
codex-auth import /path/to/auth.json --alias personal
codex-auth list --skip-apiImportant
The app command is experimental and may never become a stable feature.
It is designed to enable seamless account switching without restarting the Codex App. By leveraging the CODEX_CLI_PATH environment variable, it dynamically injects our managed codext CLI to handle authentication on the fly.
The app command is constrained by ongoing changes in the official Codex App and Codex CLI. It may not always take effect and may also break your app.
| Command | Description |
|---|---|
codex-auth app [--id <id>] [--codex-cli-path <path>] |
Experimental: launch Codex App with detected defaults, CODEX_HOME, CODEX_CLI_PATH, and platform overrides |
Support seamless account switching including:
- New Chat
- Restoring or resuming an existing conversation
- Continuing a previously completed, interrupted, or manually stopped conversation
Remove the npm package:
npm uninstall -g @loongphy/codex-authAPI-backed refresh is the default. When you pass --skip-api, codex-auth reads the newest ~/.codex/sessions/**/rollout-*.jsonl file instead. 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
Run the API-backed default with:
codex-auth listRun one local-only command with:
codex-auth list --skip-apiVerify 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): 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. npm installs already satisfy the runtime requirement.
- Local-only: With per-command
--skip-api, 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 using the default API-backed refresh, 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.
