Bottom line
📑Table of Contents
- Command Cheat Sheet — Navigate by Priority
- 🔴 Essential — The Basics to Master First
- CLI Subcommands
- Interactive Slash Commands
- Key Options and Flags
- Approval and Sandbox Modes — Codex’s Safety Model
- Practical Workflows — Combining the Commands
- AGENTS.md and config.toml — Configuration Basics
- Frequently Asked Questions (FAQ)
- Summary — Just Learn These Three First
- Use
codexinteractively andcodex execin CI or scripts -acontrols approval policy;-scontrols the sandbox boundary- Follow the guide in this order: cheat sheet, basics, safety, workflows
Codex CLI becomes easier to use once you separate interactive codex sessions from non-interactive codex exec runs. This guide walks from the commands you will use most to the -a approval policy and -s sandbox scope that shape safe automation.
Codex CLI has a lot of surface area: subcommands, interactive slash commands, and flags. The good news is that you only need to memorize a handful. I run this site’s fact-checking through codex exec, and that hands-on use is the basis for what I flag as essential here.
This guide organizes Codex CLI commands by priority and covers subcommands, interactive slash commands, key flags, and the approval/sandbox model — everything you actually need for day-to-day work.
📅 Last updated: August 2026
✅ Verified version: Codex CLI codex-cli 0.143.0 (as of August 2026)
📚 Also keep the official OpenAI Codex CLI reference open. Argument notation: <arg> is required, [arg] is optional. Codex CLI updates quickly, so confirm the latest arguments with codex --help or each subcommand’s --help.
What you’ll learn
- Everything organized by four priority levels — essential / useful / situational / good to know
- When to use
codexvs. non-interactivecodex exec - Interactive slash commands (
/init,/model,/review, and more) - The approval (
-a) and sandbox (-s) safety model - Practical workflows (CI runs, reviews, resuming sessions)
Command Cheat Sheet — Navigate by Priority
| Priority | In a nutshell | Command | How often |
|---|---|---|---|
| 🔴 Essential | Start an interactive session | codex "<prompt>" | Every time |
| 🔴 Essential | Run non-interactively (CI/scripts) | codex exec | When automating |
| 🔴 Essential | Set the sandbox scope | -s, --sandbox | Always mind it |
| 🔴 Essential | Set the approval policy | -a, --ask-for-approval | Always mind it |
| 🔴 Essential | Switch model / reasoning effort | /model | As needed |
| 🟡 Useful | Create AGENTS.md | /init | First time in a project |
| 🟡 Useful | Review changes | codex review / /review | Before committing |
| 🟡 Useful | Compact the conversation | /compact | Long sessions |
| 🟡 Useful | Resume the previous session | codex resume | Next-day pickup |
| 🟡 Useful | Apply the latest Codex Cloud diff | codex apply | Applying results |
| 🟢 Situational | Manage MCP servers | codex mcp / /mcp | Using MCP |
| 🟢 Situational | Manage plugins | codex plugin | Extending |
| 🟢 Situational | Run a local OSS model | --oss | Local LLMs |
| ⚪ Good to know | Diagnose the install | codex doctor | Troubleshooting |
| ⚪ Good to know | Check usage | /usage | Watching cost |
| ⚪ Good to know | Update Codex itself | codex update | Periodically |
🔴 Essential — The Basics to Master First
codex / codex “<prompt>” — Start an Interactive Session [Basics]
- Run
codexwith no arguments to launch the interactive TUI - Or pass a prompt to start immediately, e.g.
codex "refactor this" - If you don’t add a subcommand, options are forwarded to the interactive CLI
- Once started, give instructions in natural language and steer with slash commands
codex exec — Run Non-interactively (CI/Scripts) [Most Important]
- Aliased as
codex e. It runs without waiting for approvals, ideal for CI and scripts - Run one-shot, e.g.
codex exec "make the tests pass" --json(emit events as JSON),-o, --output-last-message <file>(write the final message to a file),--output-schema <file>(structured output)- Use
--skip-git-repo-checkto run outside a git repository
-s and -a.-s, –sandbox — Set the Sandbox Mode
read-only— read only (safest)workspace-write— allow writes inside the working directory (the recommended default)danger-full-access— no restrictions (including network; last resort)- Example:
codex exec --sandbox workspace-write "fix the build"
-a, –ask-for-approval — Set the Approval Policy
untrusted— ask for approval before running commandson-request— ask when the model decides it needs tonever— never ask (for automation; pair with a sandbox)
--yolo as the short form of --dangerously-bypass-approvals-and-sandbox. It disables both approval and the sandbox, so spell out -s and -a for normal work./model — Switch Model and Reasoning Effort
- In-session, use
/modelto pick the model and reasoning effort (low / medium / high / xhigh, etc.) - From the CLI, use
-m, --model <MODEL>(e.g.-m MODEL)
CLI Subcommands
Subcommands you run as codex <command>.
| Subcommand | What it does | When to use |
|---|---|---|
exec (e) | Run non-interactively | CI / scripts |
review | Run a code review non-interactively | Checking changes |
resume | Resume a past interactive session (--last for the most recent) | Next-day pickup |
fork | Fork a past session (--last for the most recent) | Trying an alternative |
apply (a) | Apply the latest diff generated by Codex Cloud chat to your working tree | Applying results |
mcp | Manage external MCP servers | MCP integration |
plugin | Manage Codex plugins | Extending |
login / logout | Manage authentication | Switching accounts |
update | Update Codex itself | Periodic updates |
doctor | Diagnose install, config, auth, and runtime health | Troubleshooting |
sandbox | Run a command inside the Codex sandbox | Safe execution |
cloud | Browse/apply Codex Cloud tasks (experimental) | Cloud workflows |
completion | Generate shell completion scripts | Initial setup |
archive / unarchive / delete | Manage saved sessions | History management |
features | Inspect feature flags | Checking features |
app / app-server | Launch the desktop app / run the app server (experimental) | App and MCP integration |
mcp-server / execpolicy | Run Codex as an MCP server / inspect experimental execution policy | Advanced integration and control |
Interactive Slash Commands
Commands you run with / during an interactive session (verified on codex-cli 0.143.0).
| Command | What it does |
|---|---|
/init | Create AGENTS.md (an instructions file for Codex) |
/status | Show the current session configuration |
/model | Choose the model and reasoning effort |
/permissions | Choose what Codex is allowed to do (approval/sandbox) |
/review | Review changes and surface issues |
/compact | Summarize the conversation to avoid the context limit |
/plan | Plan mode (plan before executing) |
/diff | Show the change diff |
/mcp [verbose] | List configured MCP servers |
/usage [daily|weekly|cumulative] | Show usage and remaining limits |
/goal [<objective>|clear|edit|pause|resume] | Set a goal and keep working until it’s met |
/prompts | Recall saved prompts |
/ide [on|off|status] | Toggle IDE context |
/raw [on|off] | Toggle raw scrollback mode |
/keymap [debug] | Keymap settings |
/feedback | Report an issue or feedback |
/new | Start a new conversation |
/clear | Clear the screen and context |
/logout | Sign out |
Key Options and Flags
Flags you’ll use most often with codex / codex exec.
| Flag | What it does |
|---|---|
-m, --model <MODEL> | Set the model (e.g. MODEL) |
-s, --sandbox <MODE> | Sandbox: read-only / workspace-write / danger-full-access |
-a, --ask-for-approval <POLICY> | Approval: untrusted / on-request / never |
-c, --config <key=value> | Override a value in ~/.codex/config.toml (e.g. -c model="MODEL") |
-i, --image <FILE> | Attach an image |
-p, --profile <NAME> | Select a config.toml profile |
-C, --cd <DIR> | Run in a specified working directory |
--add-dir <DIR> | Allow an additional working directory |
--search | Enable web search |
--oss / --local-provider | Run with a local OSS model |
--skip-git-repo-check | Run outside a git repository (exec) |
--json | Emit events as JSON (exec) |
-o, --output-last-message <FILE> | Write the final message to a file (exec) |
--output-schema <FILE> | Specify a structured-output schema (exec) |
--yolo | Short form of --dangerously-bypass-approvals-and-sandbox; normally avoid it |
--dangerously-bypass-approvals-and-sandbox | Disable approval and sandbox entirely (last resort) |
Approval and Sandbox Modes — Codex’s Safety Model
Codex CLI controls “how much to allow automatically” along two axes. Understanding them prevents accidents like unintended file changes or command execution.
The first axis is the sandbox (-s): how far Codex may reach into files and the network. The second is approval (-a): whether to ask a human when an action would exceed that limit.
- Safe defaults:
workspace-write+on-requestfor interactive work;workspace-write+neverfor automation (writes confined to the working directory) - Use
danger-full-accessor--dangerously-bypass-approvals-and-sandboxonly in a trusted, isolated environment - Try any command inside the sandbox with
codex sandbox <command>
--dangerously-bypass-approvals-and-sandbox disables both approval and the sandbox. It’s handy but accident-prone — stick to workspace-write or read-only for everyday use.Practical Workflows — Combining the Commands
Non-interactive runs in CI / scripts
codex exec --sandbox workspace-write --ask-for-approval never "fix the failing tests"- For structured output, combine
--output-schema schema.jsonwith--json - For a temp directory outside git, add
--skip-git-repo-check
Review changes → apply
codex review --uncommittedto review uncommitted changes (or/reviewin-session)- Apply the latest Codex Cloud diff to your working tree with
codex apply
Resume tomorrow / try an alternative
- The next day, run
codex resume --lastto resume the most recent session - To try a different approach, branch with
codex fork --last
AGENTS.md and config.toml — Configuration Basics
AGENTS.md— an instructions file for your project, generated by/initor on first run; it’s the equivalent of Claude Code’sCLAUDE.md~/.codex/config.toml— defaults for model, sandbox, profiles, etc. Override temporarily with-c key=value; switch profiles with-p- Credentials live in
~/.codex/auth.json(created bycodex login)
Frequently Asked Questions (FAQ)
▶What’s the difference between codex and codex exec?
codex launches an interactive TUI to work conversationally. codex exec (codex e) runs one-shot and non-interactively, which suits CI and scripts.
▶How do approval (-a) and sandbox (-s) differ?
The sandbox is “how far Codex may reach”; approval is “whether to ask a human when it exceeds that.” Use workspace-write + never for automation, and workspace-write + on-request for careful interactive work.
▶Should I use --yolo?
It is a short form of --dangerously-bypass-approvals-and-sandbox, which disables both approval and the sandbox. Spell out --sandbox workspace-write and the approval you want for normal work.
▶codex exec errors outside a git repository
Add --skip-git-repo-check. Codex assumes a git-managed directory by default.
▶A command doesn’t work, or I want the latest spec
Run codex doctor to diagnose, check codex --help or codex <sub> --help for current arguments, and codex update to update.
▶How is this different from Claude Code?
The philosophy is similar (a CLI agent with approval/sandbox), but the command set differs. If you come from Claude Code, read the Claude Code Commands guide alongside this as a mapping.
Summary — Just Learn These Three First
- 🔴 Just three: start with
codex "<prompt>", run non-interactively withcodex exec, set the safe scope with-s/-a - 🟡 Once comfortable:
/init,/review,/compact,codex resume,codex apply - 🟢 Look up the rest with
codex --helpwhen you need it. Bookmark this page as a reference - Confirm the latest spec with
codex --helpandcodex update(Codex CLI moves fast)
📚 Related reading
Author
krona23
Over 20 years in the IT industry, serving as Division Head and CTO at multiple companies running large-scale web services in Japan. Experienced across Windows, iOS, Android, and web development. Currently focused on AI-native transformation. At DevGENT, sharing practical guides on AI code editors, automation tools, and LLMs in three languages.
🔥 Most Popular
- Claude Desktop Won't Install? Windows & Mac Fixes That Worked (2026)
- Claude Pricing: Free, Pro, Max & Team Plans Compared (August 2026)
- Claude Cowork Automation — 5 Real Use Cases (2026)
- AI Code Editor Comparison 2026: 6 Tools Tested, Why I Use Zed + Claude Code
- Cursor Pricing 2026: Plans & Real Costs After 3 Years of Pro











Leave a Reply