English | 中文
A multi-account switcher for the codex CLI.
It keeps account auth under ~/.codex-auto/accounts/, runs managed Codex sessions on top of your existing setup, and automatically rotates to the next account when the current one hits a rate limit.
- You have multiple Codex accounts available
- You don't want to manually edit
auth.jsonorconfig.toml - You want automatic account rotation and session recovery when quota is exhausted
- You want to keep your original Codex sessions, plugins, and MCP configuration
- Manage multiple account configurations
- Run
codex loginautomatically when adding a new account - Bootstrap a
defaultaccount from your existing Codex setup on first run - Import existing
auth.jsonandconfig.tomlfiles - Start managed runs even when the source
CODEX_HOMEhas not been initialized yet - Launch managed
codexsessions - Keep interactive Codex sessions usable in normal terminal workflows, including clean shell input after automatic rotation or forced stops
- Save a default start account for future runs
- Automatically switch to the next account on rate limit
- Recognize current Codex quota prompts, including upgrade/purchase messages with retry times
- Show retry times for accounts that are still waiting for quota to reset
- Bind each active managed session to its own recovery target across same-project and cross-project concurrent runs
- Resume only the session ID already bound to the current managed run instead of guessing from the latest session
- Give a fresh run a brief chance to capture its own recovery target before automatic recovery is abandoned
- If you cancel an interactive quota prompt with
Ctrl-C, exit that managed run cleanly instead of forcing an exhausted-accounts flow - Stop automatic recovery when the original session cannot be confirmed or its session ID is no longer valid
- Automatically send
Continueon resume - Log sessions and terminal transcripts
- Pass through all
codexarguments and subcommands (e.g.exec,review,--model,--full-auto)
- Node.js 18+
- macOS or Linux terminal environment; on Windows, run
codex-autoinside WSL instead of nativecmd.exeor PowerShell codexCLI installed and executablecodex loginandcodex resumeworking properly
Install globally via npm:
npm install -g codex-autoVerify the installation:
codex-auto --helpUpgrade to the latest version:
npm install -g codex-auto@latestUninstall:
npm uninstall -g codex-autoFor local development:
npm install
npm run build
npm linkStart a managed session right away:
codex-autoOn first run, if your source CODEX_HOME already has a usable login, codex-auto imports it as default automatically.
Add more accounts:
codex-auto add a
codex-auto add bList accounts:
codex-auto listWhen an account is still waiting for quota to reset, codex-auto list shows the retry time from Codex next to that account.
Start a managed session:
codex-autoStart with a specific account:
codex-auto --account bSave a default start account for future runs:
codex-auto use bStart from a custom source CODEX_HOME:
codex-auto --codex-home /path/to/.codexRemove an account:
codex-auto remove bAny arguments not recognized as codex-auto own commands (add, remove, list) are forwarded directly to codex:
# Pass a prompt
codex-auto "fix the login bug"
# Use a specific model
codex-auto --model o3 "refactor the auth module"
# Non-interactive exec mode
codex-auto exec "add unit tests"
# Full-auto with a specific account
codex-auto --account b --full-auto "migrate to TypeScript"
# Code review
codex-auto reviewAll passthrough invocations retain multi-account rotation: if the current account hits a rate limit, codex-auto automatically switches to the next account and resumes.
--account <name> is a one-run override. codex-auto use <name> changes the default start account for later runs.
If you already have account credentials, import them directly:
codex-auto add work --auth /path/to/auth.json --config /path/to/config.tomlRules:
--authimports account credentials--configimports account configuration- If
--authis not provided,codex loginruns automatically config.tomlis guaranteed to includecli_auth_credentials_store = "file"
codex-auto maintains its own data directory, by default at:
~/.codex-autoDirectory structure:
~/.codex/ # your original Codex home, kept intact
├── auth.json
├── config.toml
├── sessions/
└── ...
~/.codex-auto/
├── accounts/
│ ├── a/
│ │ ├── auth.json
│ │ ├── config.toml
│ │ └── meta.json
│ └── b/
├── instances/
│ └── <timestamp-pid-uuid>/
│ ├── auth.json
│ ├── config.toml -> ~/.codex/config.toml
│ ├── session_index.jsonl -> ~/.codex/session_index.jsonl
│ ├── sessions -> ~/.codex/sessions
│ └── ...
├── logs/
├── runs/
│ └── <run-id>.json
└── state.json
accounts/<name>/— per-account auth/config storageinstances/<id>/— per-run overlay used asCODEX_HOMEand reused across account switches in that runruns/<run-id>.json— current managed process status, bound session ID, and recovery statestate.json— account order, current index, default start account, last successful account, and the latest successfully bound session IDlogs/— session logs and terminal transcripts
For each managed run, codex-auto creates ~/.codex-auto/instances/<id>/, symlinks entries from the source CODEX_HOME, replaces only auth.json with a real copy from the selected account, and keeps reusing that overlay for the lifetime of the managed run. On quota switches it swaps only the overlay's auth.json, resumes the already bound session, and removes the overlay when the process exits. This keeps session history, plugins, MCP config, and other Codex state in the original home.
Interactive sessions keep the standard Codex terminal experience, including full-screen and split-pane workflows, while codex-auto continues automatic account rotation and session recovery in the background and returns control to your shell in a normal input state after a forced stop or quota-driven switch.
The current version only triggers a switch when a genuine rate-limit message is detected, avoiding false positives from warning-like output.
When a rate limit is hit:
- Mark the current account as exhausted
- Switch to the next available account
- Replace the current run overlay's
auth.jsonwith the next account - Resume only the session ID already bound to that managed run
- Run:
codex resume <session-id> ContinueIf a fresh run has already triggered quota handling but its recovery target is still catching up, codex-auto gives that run a short window to capture its own session ID before surfacing a recovery failure. If the current managed run still has not safely captured its own session ID, or if that bound session ID is no longer available, codex-auto stops automatic recovery and surfaces the failure instead of falling back to codex resume --last.
If an interactive quota prompt is already on screen and you press Ctrl-C, codex-auto treats that as a user cancel for the current managed run. It restores the terminal state and exits cleanly instead of continuing into automatic exhausted-account handling.
To prevent stale transcript interference, rate-limit detection switches to only the output after the most recent live prompt once startup or recovery has reached that prompt.
Concurrent run behavior:
- Multiple
codex-autosessions in different terminals for the same project each keep their own recovery binding - Multiple
codex-autosessions in different terminals for different projects also recover independently - Recovery decisions are always scoped to the active managed process, not to the latest project-level or global session
-
CODEX_AUTO_HOMEData directory forcodex-auto. Default:~/.codex-auto -
CODEX_HOMESource Codex home used as the overlay base. Default:~/.codex -
CODEX_AUTO_CODEX_BINPath to thecodexexecutable. Default:codex
Example:
CODEX_AUTO_HOME=/tmp/codex-auto \
CODEX_HOME=/Users/me/.codex \
CODEX_AUTO_CODEX_BIN=/opt/homebrew/bin/codex \
codex-auto --account a# Account management (codex-auto own commands)
codex-auto add <name>
codex-auto add <name> --auth /path/to/auth.json --config /path/to/config.toml
codex-auto list
codex-auto use <name>
codex-auto remove <name>
# Managed session (default)
codex-auto
codex-auto --account <name>
codex-auto --codex-home /path/to/.codex
# Passthrough to codex (all other arguments)
codex-auto [any codex arguments...]
codex-auto --account <name> [any codex arguments...]
codex-auto --codex-home /path/to/.codex [any codex arguments...]Install dependencies:
npm installBuild:
npm run buildTest:
npm testLink locally:
npm linkPack check:
npm pack --json- Rate-limit detection relies on known failure messages in terminal output, not official structured events
- If the underlying
codexsession ID has been lost,codex-autostops automatic recovery instead of falling back toresume --last - Account rotation is based on local state order, with no weighting, priority, or health checks
MIT