- Account metadata is read from
~/.codex/auth.json. - Quota snapshots are read from the
rate_limitsfield in~/.codex/sessions/**/*.jsonl. primarymaps to the 5H limit andsecondarymaps to the weekly limit; free accounts usually only expose the weekly limit, and missing values are shown asunknown.
A command-line tool for managing multiple Codex accounts, switching quickly, and tracking quota usage.
- Save the current account as a reusable profile.
- Switch by profile id, name, or email.
- Auto-switch to the profile with the highest weekly remaining quota (
--auto). - Use TUI selection when no selector is provided or multiple matches exist.
- Import profiles and perform WebDAV backup/restore.
- View quota snapshots for both 5H and weekly limits.
| Icon | Command | Description |
|---|---|---|
| 🧾 | codex-switch account |
Show current account info |
| 🩺 | codex-switch doctor |
Diagnose local environment and profile state |
| 🏷️ | codex-switch version |
Show version, git commit, and build date (single-line text; JSON supported) |
| 📊 | codex-switch usage |
Display quota overview for all saved profiles |
| 💾 | codex-switch profile save [name] |
Save current account auth as a profile |
| 🔁 | codex-switch profile use [name_or_email] |
Switch to profile (TUI when omitted or ambiguous) |
| 🤖 | codex-switch profile use --auto |
Select and switch to the best weekly quota profile |
| 📋 | codex-switch profile list |
List saved profiles |
| 🗑️ | codex-switch profile delete [name_or_email] |
Delete profile(s) by selector or TUI |
| 📥 | codex-switch profile import [path] |
Import auth.json or CPA JSON files |
| ☁️ | codex-switch profile backup |
Backup profiles to WebDAV |
| 🔄 | codex-switch profile restore |
Restore profiles from WebDAV |
| 💡 | codex-switch completions <shell> |
Generate shell completions |
Global flag for agents/CI:
--non-interactive: disable TUI interactions and return coded errors when interactive selection would be required.
cargo install --path .or build locally:
cargo build --release
# executable at target/release/codex-switchcodex-switch profile save
codex-switch usage
codex-switch profile useShow current profile summary:
codex-switch accountShow local diagnostic status (paths/files/profile count):
codex-switch doctor
codex-switch --format json doctorShow version, git commit, and build date in a single-line text format. JSON output is also available.
codex-switch version
codex-switch --format json versionHealth checks include:
- codex/switch directory existence
- profiles directory existence
- auth/state/rollback file presence
- state.json parse validity
- active profile file existence
- WebDAV configuration and connectivity (when backup config exists)
Show snapshot quota table:
codex-switch usageSave current ~/.codex/auth.json as profile:
codex-switch profile save
codex-switch profile save workSwitch by id/name/email or use interactive TUI:
codex-switch profile use
codex-switch profile use work
codex-switch profile use alice@example.com
codex-switch profile use --auto
codex-switch profile use -aList all profiles:
codex-switch profile listGet detailed info for a single profile (by id, name, or email):
codex-switch profile inspect abc123
codex-switch --format json profile inspect alice@example.comDelete by selection or exact name/email:
codex-switch profile delete
codex-switch profile delete work
codex-switch profile delete alice@example.comImport auth files:
codex-switch profile import /path/to/auth.json
codex-switch profile import --cpa /path/to/cpa.jsonWebDAV backup:
codex-switch profile backup
codex-switch profile backup --setup
codex-switch profile restore
codex-switch profile restore --setup- Active profile state is tracked in ~/.codex-auth-switch/state.json.
profile usewrites a rollback copy for safer switching.- JSON output is available with
--format json.
Exit codes:
| Code | Meaning |
|---|---|
0 |
Command completed successfully |
1 |
General runtime error |
2 |
Not found (E_NOT_FOUND) |
3 |
Interactive required (E_INTERACTIVE_REQUIRED) |
4 |
Ambiguous selector (E_AMBIGUOUS_SELECTOR) |
Machine-readable error prefixes in stderr:
E_NOT_FOUND: the requested profile, file, or resource does not exist.E_INTERACTIVE_REQUIRED: command requires interactive selection, but--non-interactiveis enabled.E_AMBIGUOUS_SELECTOR: selector matched multiple profiles and must be disambiguated by id.
When --format json is set, profile save, profile use, profile delete, and profile import all return a structured JSON object instead of a plain string:
{ "ok": true, "action": "use", "id": "abc123", "name": "work", "message": "已切换到 profile: work (id: abc123)" }Cancelled TUI operations return "ok": false with "action": "cancel" (exit code 0).
Recommended automation pattern:
- Run with
--non-interactive --format jsonwhenever possible. - If exit code
2(E_NOT_FOUND), the profile or file does not exist — create it first. - If exit code
4(E_AMBIGUOUS_SELECTOR), fetch candidates withprofile list --format jsonand retry byid. - If exit code
3(E_INTERACTIVE_REQUIRED), re-run with explicit selector (id/name/email) or--auto.