Direct answer
Organize commands around daily workflows instead of memorizing every flag, and treat the installed codex --help output as authoritative.
What this guide helps you solve
Query Codex CLI common commands, parameters and session recovery methods
Discover available capabilities from local help
Codex CLI is updated quickly, and articles cannot replace the help text of the current binary. First confirm the subcommand with top-level help, then run --help on the specific subcommand.
Strict configuration mode is suitable for discovering invalid or misspelled configuration fields, but you should first verify the impact of the upgrade in a non-production workspace.
codex --version
codex --help
codex exec --help
codex review --help
codex mcp --help
codex features listStart an interactive session with explicit context
Running codex without a subcommand opens the interactive interface. -C sets the working root, -m selects a model temporarily and -i attaches images; these flags apply only to the current invocation.
Additional writable directories must be provided explicitly via --add-dir; do not expand the entire sandbox just to access an adjacent directory.
codex -C /path/to/repo
codex -C /path/to/repo -m gpt-5.6-sol "解释当前测试失败,不要修改文件。"
codex -C /path/to/repo -i /path/to/screenshot.png "定位截图中的界面回归。"Restoring, forking and managing sessions
resume continues an existing session with its context, while fork starts a new branch of work from a historical session. Both support --last for the most recent session; run the selector without arguments when you need to inspect the available choices.
You still need to check the current repository and branches before restoring. The historical context will not guarantee that the working tree is exactly the same as last time.
codex resume
codex resume --last
codex fork --last
codex archive --help
codex unarchive --helpUse flags for one-time overrides
-c accepts TOML values and can override top-level or nested config.toml fields. Use a one-time override to test an assumption before deciding whether to make the setting persistent.
Sandbox and approval have dedicated -s and -a flags. Prefer those to the generic -c form because they make command intent clearer.
codex -m gpt-5.6-sol -s read-only -a untrusted
codex -c model_reasoning_effort=high "分析这个失败测试的根因。"
codex --enable goals
codex --disable goalsUse exec for scripts and review for code review
codex exec handles non-interactive calls and reads tasks from an argument or standard input. codex review focuses on repository changes and can inspect uncommitted work, changes relative to a baseline branch or a specific commit.
When automating, you must check the exit code and save the JSONL event separately from the final text; do not judge the task status by searching for natural language "success".
codex exec -C /path/to/repo "运行相关测试并解释失败,不要修改文件。"
codex review --uncommitted
codex review --base main
codex review --commit "$(git rev-parse HEAD)"Completion, upgrade and diagnosis
completion generates completion scripts based on the shell; the specific loading method is determined by the shell. update is used to upgrade installations that support self-update. If hosted by a package manager, the same upgrade channel should be maintained.
doctor checks installation, configuration, authentication and the runtime environment. Review its output before sharing it, and remove private paths or organization details from public tickets.
codex completion zsh > /tmp/_codex
codex update
codex doctor --summary
codex doctor --json > /tmp/codex-doctor.jsonOfficial sources and verification scope
This guide is based on public official documentation. Commands and configuration may change between client versions, so verify the linked sources before use.
Read the verification methodology