@enriquecardoza/dex
v0.2.0
Published
CLI to manage multiple Codex profiles and switch the active account safely.
Readme
dex
CLI to manage multiple Codex accounts by profile and promote one account to the default profile (~/.codex) used by Codex App + Codex CLI when CODEX_HOME is not set.
Install (npm)
npm i -g @enriquecardoza/dex
Commands
- Primary:
dex - Short alias:
cdex - Legacy alias:
codex-use
Main file
tools/codex-use
Core flow
- Save login per profile:
dex login personaldex login work
- Switch the active default account:
dex use personaldex use workdex use work --relaunch(recommended so Codex App refreshes the session automatically)dex use work --relaunch --from-action(for Actions: relaunches the app and closes the Terminal tab on success)
- Check usage/rate limits:
dex usagedex usage --jsondex limits work --refreshdex limits --allordex limits -a(compact limits view by profile)
Available commands
dex login <profile>dex use <profile> [--force] [--relaunch] [--from-action]dex add switch action [--platform <macos|darwin>] [--icon <icon>] [--command-name <dex|cdex|codex-use>] [--dry-run]dex delete switch action [--platform <macos|darwin>] [--dry-run]dex usage [--json]dex backup [--note "..."] [--dir <path>] [--delete]dex backup status [--dir <path>]dex backup init [--dir <path>]dex backup add remote <url> [--name <remote>] [--dir <path>]dex backup push [--remote <name>] [--branch <name>] [--dir <path>]dex backup restore [--dir <path>] [--relaunch] [--delete]dex limits [profile|default] [--all] [--json] [--refresh] [--live-only] [--allow-cache] [--backend <auto|wham|rpc>]dex limits doctor [profile|--all] [--refresh] [--allow-cache] [--backend <auto|wham|rpc>]dex listdex whoamidex status <profile> [--refresh] [--live-only] [--allow-cache] [--backend <auto|wham|rpc>]dex logout <profile>dex logout-default
Security notes
usecreates an automatic backup of~/.codex/auth.jsonin~/.codex/backups/.- Avoid switching accounts while there are active tasks in Codex App.
--forceexists for advanced cases and may interrupt in-flight sessions.--relaunchcloses and reopens Codex App so the UI reads the newauth.json.--from-actionis intended for Codex Actions: after a successful--relaunch, it tries to auto-close the current Terminal tab.usagereads local history from~/.codex/sessions.backupsnapshots~/.codex/sessionsinto a Git repo (default:~/codex-history-backup).backupis copy-only by default (no deletions). Use--deleteonly when you intentionally want mirror mode.limitsis live-first: directwham/usageAPI with profile token, then RPC fallback (account/rateLimits/read).
Quick troubleshooting when "the account did not change" in the app
- Run
dex list. - Check the legend:
[*]= the profile uses exactly the same token as~/.codex.[~]= sameaccount_id, but different token/identity.
- If you switch while the app is open, use
dex use <profile> --relaunch. - Run
dex whoamito seeActive profileplus email/plan/account.
Difference between whoami and status
whoami: quick view of the active profile in~/.codex(the account used by app/CLI by default).status <profile>: diagnostics for a specific profile in~/.codex-profiles/<profile>, including:- identity summary (
plan,default_org,email,account_id) - usage limits (
5handweekly) with remaining percentage, horizontal bar, and reset timing - readable credits summary (
credits: none,credits: unlimited,credits: balance ...) - Use
--refreshto force a fresh backend query before showing limits.
usage output
usageshows historical consumption from~/.codex/sessionsin a compact table.- Columns:
in(M),out(M),cach(M)(millions of tokens).out(M)includes reasoning. usage --jsonreturns the raw aggregate (totalsandmodels) for scripting.
limits output
limits <profile>(without--json) shows dashboard-style output:5handweeklybars, natural-language reset, and credits summary.limits --all/limits -ashows a compact table with columnsprofile,email,5h (reset),weekly (reset)and aCurrent default profileline.limits --jsonkeeps the raw JSON output from rate limits for scripting/automation.limits doctorprints backend diagnostics (whamandrpc), latency, error reason, selected backend, and cache age.- By default,
limits/statusdo not fall back to cache. They fail with live error when no backend responds. - Use
--allow-cacheto enable fallback from local snapshot (<profile>/cache/codex-use-rate-limits.json) when live backends fail. - Use
--backend wham|rpc|autoto force backend selection (autodefaults towhamfirst, thenrpc). - In
limits --all, cached rows are marked with~and(cached)in the email column. - In
status <profile>, cached fallback is explicitly shown asnote: showing cached limits snapshot (...). - Use
--live-onlyto explicitly force no-cache behavior (same as default unless--allow-cacheis passed). - Freshness states in
limits --all: ✓means a live backend responded and values are fresh.~means all live backends failed, but cached snapshot is being used (--allow-cache).network-error/rpc-errormeans live backends failed and no cache fallback was used.
backup status output
backup statusshows backup health in terminal-first format (key: value), including repo/git state, source vs backup file counts, session-id coverage, and pending copy/delete deltas.pending_copy_filesindicates what would be copied in default mode.pending_new_filesindicates brand-new rollouts not yet present in backup.pending_modified_filesindicates existing rollout files that changed (for example, more conversation appended to the same.jsonl).pending_mirror_deletesindicates what would be removed only in--deletemirror mode.runtime_unflushed_activityindicates there is fresh Codex runtime activity (logs_2.sqlite/state_5.sqlite) newer than the latestsessions/*.jsonlwrite.runtime_vs_sessions_lag_secondsindicates how far runtime activity is ahead of session-log writes.
backup commit notes
backupcommits now include aSession notessection with only new/changed rollouts since the previous backup commit (not a cumulative list).- Each note line includes rollout file, resolved title (when available), model, token total snapshot, and latest timestamp.
Generate Codex Actions
add switch actionreads logged profiles from~/.codex-profilesand writes per-profile switch actions into.codex/environments/environment.toml.- Platform support for now:
macos(alias:darwin, written asdarwinin the TOML file). - Example:
dex add switch action --platform macos- Preview only:
dex add switch action --dry-run- Delete generated switch actions for macOS:
dex delete switch action --platform macos
