Switch between multiple Codex CLI accounts without splitting local chat/session history.
codex-auth-switcher keeps one shared CODEX_HOME (sessions/history/state stay intact) and switches only credentials.
Using separate CODEX_HOME directories per account fragments local context. This tool avoids that by storing per-account credential snapshots in a separate state directory and applying one profile at a time to the same CODEX_HOME.
- Account profiles with fast switching
- Shared sessions/history/state across profiles
- Support for Codex auth storage modes:
file,keyring,auto - Profile-aware
loginandlogoutflows - Manual and bulk token refresh (
refresh,refresh --all,switch --refresh) - Usage limits fetch per profile with clean window/reset display in local timezone, including a
(current)marker on the active profile (limits,limits --all) - Token health inspection (
inspect) - Health and repair diagnostics (
doctor) - Machine-readable output for scripting (
--json) - Shell completions for
bash,zsh,fish
- Go
1.26.0 codexCLI installed and available onPATH
make build-smallOr:
go install github.com/sasanktumpati/codex-auth-switcher@latestManual small build (without make):
CGO_ENABLED=0 go build -trimpath -ldflags='-s -w -buildid=' -o codex-auth-switcher .# 1) Create two profiles from current active Codex auth
codex-auth-switcher create personal
codex-auth-switcher create work
# 2) Switch profiles (shared CODEX_HOME remains unchanged)
codex-auth-switcher switch personal
codex-auth-switcher switch work --refresh
# 3) Verify
codex-auth-switcher list
codex-auth-switcher inspect work
codex-auth-switcher limits --all
codex-auth-switcher doctor --json# Inspect overall health
codex-auth-switcher doctor
# Use structured output in scripts
codex-auth-switcher list --json
codex-auth-switcher limits --all --json
codex-auth-switcher doctor --jsoncreate <profile> [--empty]
delete <profile>
list
current
save [profile]
switch <profile> [--refresh]
login <profile>
logout <profile>
refresh [profile]
refresh --all
limits [profile] [--all]
limits --all
inspect [profile]
doctor
version
completion <bash|zsh|fish>
codex -- <codex args...>
Global options:
--state-dir <path>(default:~/.codex-auth-switcher)--codex-home <path>(default:$CODEX_HOMEor~/.codex)--json(structured output for supported commands)
CODEX_HOME/sessions/...CODEX_HOME/session_index.jsonlCODEX_HOME/history.jsonlCODEX_HOME/state-db_<version>.sqlite
Codex active credentials are read/written according to Codex config mode:
file:CODEX_HOME/auth.jsonkeyring: OS keyring entry (Codex Auth, account derived from hashedCODEX_HOME)auto: keyring first, file fallbackephemeral: in-memory only (cannot be persisted by a profile switcher)
codex-auth-switcher profile snapshots:
~/.codex-auth-switcher/profiles/<name>.json~/.codex-auth-switcher/active_profile
Profile credential snapshots are encrypted at rest. The encryption key is stored in the OS keyring when available, with a 0600 file fallback if the keyring is unavailable.
New profile keys are also written to ~/.codex-auth-switcher/snapshot.key as a cross-platform recovery file, so profiles remain decryptable if macOS Keychain, Linux Secret Service, or Windows Credential Manager loses or denies access to the keyring entry.
Tokens are not permanent.
- Access tokens expire.
- Refresh tokens may also expire or be revoked.
- Refresh failure requires re-login.
This tool provides proactive refresh and retry-on-401 for usage requests, but it cannot make tokens never expire.
codex-auth-switcher completion bash > ~/.codex-auth-switcher.bash
echo 'source ~/.codex-auth-switcher.bash' >> ~/.bashrc
source ~/.codex-auth-switcher.bashcodex-auth-switcher completion zsh > ~/.codex-auth-switcher.zsh
echo 'source ~/.codex-auth-switcher.zsh' >> ~/.zshrc
source ~/.codex-auth-switcher.zshcodex-auth-switcher completion fish > ~/.config/fish/completions/codex-auth-switcher.fishVERSION: embedded CLI version for releases/buildsmain.go: CLI parsing and command dispatchinternal/doctor.go: consistency and safety diagnosticsinternal/manager.go: profile lifecycle and Codex passthroughinternal/auth.go: auth mode handling, refresh, limits, inspectinternal/storage.go: atomic persistence and utilitiesinternal/completion.go: shell completion generationinternal/limits_ui.go: clean limits rendering
go test ./...
go build ./...
go vet ./...- Auth storage modes (
file,keyring,auto,ephemeral): CODEX_HOMEresolution:- Session rollouts (
CODEX_HOME/sessions/...): - Session index (
CODEX_HOME/session_index.jsonl): - State DB path (
CODEX_HOME/state-db_<version>.sqlite): - Token refresh logic and expiry handling:
- OAuth refresh request details:
- Usage limits endpoint and auth headers:
- Unofficial tool. Not affiliated with, endorsed by, or sponsored by OpenAI.
- Use at your own risk.
- You are responsible for complying with OpenAI terms, policies, and any applicable laws.
- Credentials are sensitive. Review code, protect your machine, and understand your threat model before use.