codex-cli
Overview
codex-cli is a provider-specific Rust CLI for OpenAI/Codex workflows: Codex execution wrappers, auth/secret management, Codex diagnostics,
config output, and Starship rendering. Runtime wiring is owned by codex-cli adapters with shared nils-common::provider_runtime helpers
for common primitives.
Usage
Usage:
codex-cli <group> <command> [args]
codex-cli starship [options]
Groups:
agent prompt | advice | knowledge | commit
auth login | use | save | remove | refresh | auto-refresh | current | sync
diag rate-limits
config show | set
starship (options)
Help:
codex-cli help
codex-cli <group> help
Scope boundary
| Job | Primary owner |
|---|---|
Shared provider runtime helpers (auth/path/config/exec/error) |
nils-common::provider_runtime + codex-cli adapters |
| OpenAI/Codex auth, Codex prompt wrappers, Codex rate-limit diagnostics, Starship | codex-cli |
| Unsupported commands/groups | clap usage error (64) |
codex-cliowns only provider-specific OpenAI/Codex operations (agent,auth,diag rate-limits,config,starship).- Existing
codex-clicommands stay stable for provider-specific workflows. - Unknown groups/subcommands are deterministic usage errors (
64).
Commands
agent
prompt [PROMPT...]: Run a raw prompt throughcodex exec.advice [QUESTION...]: Request actionable engineering advice.knowledge [CONCEPT...]: Request a concept explanation.commit [-p|--push] [-a|--auto-stage] [EXTRA...]: Run the semantic-commit workflow.
auth
login [--api-key|--device-code]: Login via ChatGPT browser flow (chatgpt-browser, default), ChatGPT device-code flow (chatgpt-device-code), or API key flow (api-key).--api-keyand--device-codeare mutually exclusive (64on invalid usage).use <name|name.json|email>: Switch to a secret by name/name.json or email.save [--yes] <secret|secret.json>: Save activeCODEX_AUTH_FILEintoCODEX_SECRET_DIR. Secret files are normalized to.json; if target exists, interactive mode prompts for overwrite, while non-interactive and JSON mode require--yesto overwrite.remove [--yes] <secret|secret.json>: Remove a secret file fromCODEX_SECRET_DIR. Secret names are normalized to.json; interactive mode prompts for confirmation, while non-interactive and JSON mode require--yes.refresh [secret.json]: Refresh OAuth tokens.auto-refresh: Refresh stale tokens across auth + secrets.current: Show which secret matchesCODEX_AUTH_FILE.sync: SyncCODEX_AUTH_FILEback into matching secrets.
Auth examples:
codex-cli auth login: ChatGPT browser login.codex-cli auth login --device-code: ChatGPT device-code login.codex-cli auth login --api-key: OpenAI API key login.codex-cli auth save team-alpha: Save toteam-alpha.jsonand prompt before overwrite when applicable.codex-cli auth save --yes team-alpha.json: Force overwrite without prompt.codex-cli auth remove --yes team-alpha: Removeteam-alpha.json.
diag
rate-limits [options] [secret.json]: Rate-limit diagnostics. Options:-c/--clear-cache,-d/--debug,--cached,--no-refresh-auth,--json,--one-line,--all,--async,--jobs <n>.--cachedreads cache only. Freshness is controlled byCODEX_RATE_LIMITS_CACHE_TTL(default3m); stale cache is rejected unlessCODEX_RATE_LIMITS_CACHE_ALLOW_STALE=true.
config
show: Print effective configuration values.set <key> <value>: Emit a shell snippet for the current shell.
starship
starship [--no-5h] [--ttl <duration>] [--time-format <strftime>] [--show-timezone] [--refresh] [--is-enabled]: Render or refresh the Starship line. Default reset time uses local time without timezone;--show-timezoneadds the local offset.
JSON contract (service consumers)
- Human-readable text is the default output mode.
- Machine-readable JSON mode is explicit: use
--format json(preferred) or--jsonwhere supported for compatibility. - Contract spec:
docs/specs/codex-cli-diag-auth-json-contract-v1.md - Consumer runbook:
docs/runbooks/json-consumers.md - Covered surfaces:
diag rate-limits(single/all/async) andauth login|use|save|remove|refresh|auto-refresh|current|sync.
Environment
CODEX_ALLOW_DANGEROUS_ENABLED: gate foragentcommands (default:false).CODEX_CLI_MODEL:codex execdefault model (default:gpt-5.1-codex-mini).CODEX_CLI_REASONING:codex execdefault reasoning level (default:medium).CODEX_SECRET_DIR: secret directory path (default:~/.config/codex_secrets).CODEX_AUTH_FILE: active auth file path (default:~/.agents/auth.json).CODEX_SECRET_CACHE_DIR: secret timestamp cache directory. If unset, resolver order is:ZSH_CACHE_DIR/codex/secrets->ZDOTDIR/cache/codex/secrets->~/.config/zsh/cache/codex/secrets.CODEX_RATE_LIMITS_CACHE_TTL:diag rate-limits --cachedTTL (default:3m; supportss|m|h|d|wsuffixes or raw seconds).CODEX_RATE_LIMITS_CACHE_ALLOW_STALE: allow stale cache in--cachedmode (default:false).CODEX_RATE_LIMITS_DEFAULT_ALL_ENABLED: defaultdiag rate-limitsto--allwhen no target is provided (default:false).CODEX_STARSHIP_ENABLED: enable Starship output (default:false; settrueto enable).CODEX_STARSHIP_TTL: Starship cache TTL override (default:3m; supportss|m|h|d|wsuffixes or raw seconds).CODEX_AUTO_REFRESH_ENABLED: enableauth auto-refreshbehavior where applicable (default:false).CODEX_AUTO_REFRESH_MIN_DAYS:auth auto-refreshminimum token age threshold (default:5).
Dependencies
codexis required foragentcommands.gitis required foragent commit.semantic-commitandgit-scopeare optional foragent commit(fallbacks apply).
Exit codes
0: success and help output.64: usage or argument errors.1: operational errors.
Contract sign-off checklist
-
cargo test -p nils-codex-cli --test main_entrypoint --test dispatch -
rg -n "codex-cli\\.diag\\.rate-limits\\.v1|codex-cli\\.auth\\.v1" crates/codex-cli/docs/specs/codex-cli-diag-auth-json-contract-v1.md -
NILS_WRAPPER_MODE=debug ./wrappers/codex-cli unknown-groupexits64with clap usage error output.