Codex CLI “commands” actually break down into three categories: subcommands run in the shell, global flags added at startup, and slash commands inside the terminal interactive interface. Mixing the three together most often leads to entering a command in the wrong place or assuming a one-time flag permanently changes configuration.
This article organizes common entry points by real task and separates permission and dangerous flags. Commands and available features change between versions; this article was checked against the official OpenAI Codex CLI page and developer command reference on 2026-08-27. In practice, always rely on current codex --help and the official page.
Distinguish the Three Command Types First
| Type | Input location | Example | Best for |
|---|---|---|---|
| CLI subcommand | Normal shell | codex login status | Login, session recovery, review, automation, and diagnostics |
| Global flag | After codex or a subcommand | codex --cd apps/site | Select directory, sandbox, approval, or model for this run |
| Slash command | Codex interactive interface | /status | View or adjust state in current session |
If you are not sure what the current version supports, start with:
codex --help
codex exec --help
Help output is more reliable than old articles or screenshots. Do not use dangerous flags from memory, and do not apply syntax from other OpenAI command-line tools to Codex CLI.
Starting the Interactive Interface and Limiting the Working Directory
Running codex in the project directory starts the terminal interactive interface:
cd /path/to/project
codex
You can also set the working directory explicitly with --cd (short form -C):
codex --cd /path/to/project
Paths are examples; confirm that the path points to the intended repository before running. The current OpenAI reference also lists --add-dir, which adds a writable directory outside the main workspace. Expand scope only when the task actually requires it; do not grant the whole parent directory just to reduce prompts.
For normal local work, the official reference gives this low-friction combination:
codex --sandbox workspace-write --ask-for-approval on-request
These flags only affect the current launch. To save long-term defaults, review config.toml separately; do not mistake a one-time command for permanent configuration.
Login, Checking Status, and Logging Out
Common authentication entry points are:
codex login
codex login status
codex logout
codex login starts the login flow, codex login status outputs the current authentication mode and exits with a success status when credentials exist; codex logout removes saved ChatGPT and API key authentication credentials.
The official reference also provides ways to read an API key or access token from standard input. Credentials should never appear in command history, script arguments, screenshots, or article examples. Automated environments should use controlled secret management and least privilege instead of writing keys into example .env files in the repository.
Resuming, Forking, and Organizing Sessions
To continue a historical session, use:
codex resume
codex resume --last
resume is suitable for continuing the original task and context. If you need to explore an alternative approach from an existing session while preserving the original conversation thread, use codex fork. Resuming and forking are not the same thing: the former continues, the latter creates a new branch.
In the interactive interface, /rename names the current session, /archive archives and exits, and /delete permanently deletes the current session and its descendants. Archive and delete have different recovery capabilities; confirm the target and impact before deleting.
Checking Status and Permissions During a Session
Inside the terminal interactive interface, the most important commands to remember first are:
/status
/permissions
/status is used to view the current session configuration, such as the active model, approval policy, writable scope, and token usage. /permissions is used to adjust actions Codex can perform without asking again. When starting a new repository, switching directories, or noticing that command behavior does not match expectations, check the status before deciding to expand permissions.
/model switches the current session model, and /compact compresses longer conversations to free context space. Models, reasoning options, and feature availability may vary by version, account, or environment. Choose from the current slash menu rather than relying on fixed defaults in articles.
Reviewing Changes and Viewing Diffs
Use these in the interactive interface:
/review
/diff
/review can guide work tree review, and /diff is useful for viewing exact file differences. In the shell, codex review can non-interactively review uncommitted changes, base branch differences, a specific commit, or custom review requirements.
Automated review results still need to be checked against the real Git diff, test output, and project rules. In particular, confirm that pre-task user changes are not overwritten, credentials or generated files are not included in the commit, and checks that were not executed are not written as “passed.”
Running Non-Interactive Tasks with codex exec
codex exec (short form codex e) is suited for scripts or CI tasks that need to run and exit:
codex exec --cd /path/to/project "Read the repository instructions and report the validation commands. Do not modify files."
The prompt can also be read from standard input. The current official reference provides --json to output line-delimited JSON events, and --output-last-message to write the final answer to a specified file. When downstream programs need to consume the result, use --output-schema to constrain the final output structure.
Non-interactive does not mean no boundaries. Explicitly choose an appropriate --sandbox, use minimal credentials in CI, and allow failure status to block subsequent releases. The official reference marks --dangerously-bypass-approvals-and-sandbox (alias --yolo) as a dangerous option, suitable only for runners already isolated by an external environment; it should not be the default command on local or shared build machines.
Common Interactive Shortcuts
In addition to slash commands, the current official reference records several high-frequency operations:
- Enter
@to search workspace files and add a path to the prompt; - Use
Ctrl+Rto search prompt history; - Use
Ctrl+Oor/copyto copy the most recently completed output; - Type
!at the start of a line to run local shell commands under the current sandbox and approval settings; - While Codex is working, press
Tabto queue a follow-up prompt or command for the next turn; - While working, press
Enterto inject a new instruction into the current turn; - Use
/exitorCtrl+Cto exit the session.
! does not bypass permissions. It only launches a local command from the interactive interface. Still verify the working directory, arguments, and impact first.
Diagnostics, Updates, and Feature Status
The current official command reference lists the following commands as stable entry points:
codex doctor
codex features list
codex update
codex doctor generates a diagnostic report covering installation, configuration, authentication, runtime, Git, terminal, and sessions. Use --json to output a processed machine-readable support report. Even so, check local paths and project context before sharing diagnostic files.
codex features list shows known features, maturity, and current effective state. codex update checks and applies updates only if the current installation supports self-update. Update methods can differ by installation channel, so if an update fails, return to the official CLI page to confirm.
Choosing Commands by Task
| Goal | Suggested entry point | What to check first |
|---|---|---|
| Enter a project for the first time | codex --cd <path> | Directory, Git status, AGENTS.md |
| Confirm login | codex login status | Authentication mode, do not print credentials |
| View current boundaries | /status, /permissions | Writable directories, approval, sandbox |
| Continue last task | codex resume --last | Confirm it is the same project and goal |
| Branch an exploration | codex fork | Whether the original session should be preserved |
| Review work tree | /review, /diff | Real diff and test results |
| Scripted read-only task | codex exec --sandbox read-only | Input, exit status, output format |
| Troubleshoot environment | codex doctor | Whether the report contains sensitive information |
If your project needs fixed build and acceptance rules, read the AGENTS.md guide first. If installation and first login are not complete, start with the Codex CLI installation tutorial.
FAQ
What is the difference between /status and codex login status?
/status shows runtime status such as model, permissions, and workspace within an interactive session. codex login status checks authentication mode in the shell. They solve different problems.
Do global flags permanently modify config.toml?
Usually not. --cd, --sandbox, --ask-for-approval, and -c key=value apply to the current invocation. To persist a setting, use the official configuration mechanism and review the changes.
Can I use --yolo directly in CI?
It should not be the default. The official reference only recommends considering the dangerous bypass option in already isolated runners. A safer approach is to choose an appropriate sandbox, limit writable directories and network access, use least-privilege credentials, and keep a manual release gate.
Are slash commands the same in all versions?
Not necessarily. Commands may vary by version, platform, account, or feature maturity. Type / in the current terminal interface and rely on the actual menu and official command reference.