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 codex vs. non-interactive codex 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

PriorityIn a nutshellCommandHow often
🔴 EssentialStart an interactive sessioncodex "<prompt>"Every time
🔴 EssentialRun non-interactively (CI/scripts)codex execWhen automating
🔴 EssentialSet the sandbox scope-s, --sandboxAlways mind it
🔴 EssentialSet the approval policy-a, --ask-for-approvalAlways mind it
🔴 EssentialSwitch model / reasoning effort/modelAs needed
🟡 UsefulCreate AGENTS.md/initFirst time in a project
🟡 UsefulReview changescodex review / /reviewBefore committing
🟡 UsefulCompact the conversation/compactLong sessions
🟡 UsefulResume the previous sessioncodex resumeNext-day pickup
🟡 UsefulApply the latest Codex Cloud diffcodex applyApplying results
🟢 SituationalManage MCP serverscodex mcp / /mcpUsing MCP
🟢 SituationalManage pluginscodex pluginExtending
🟢 SituationalRun a local OSS model--ossLocal LLMs
⚪ Good to knowDiagnose the installcodex doctorTroubleshooting
⚪ Good to knowCheck usage/usageWatching cost
⚪ Good to knowUpdate Codex itselfcodex updatePeriodically

🔴 Essential — The Basics to Master First

codex / codex “<prompt>” — Start an Interactive Session [Basics]

  • Run codex with 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-check to run outside a git repository
⚠️ In non-interactive mode, if you don’t set the sandbox and approval explicitly you may end up unexpectedly restricted — or unexpectedly permissive. Always mind -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 commands
  • on-request — ask when the model decides it needs to
  • never — never ask (for automation; pair with a sandbox)
💡 The current reference documents --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 /model to 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>.

SubcommandWhat it doesWhen to use
exec (e)Run non-interactivelyCI / scripts
reviewRun a code review non-interactivelyChecking changes
resumeResume a past interactive session (--last for the most recent)Next-day pickup
forkFork 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 treeApplying results
mcpManage external MCP serversMCP integration
pluginManage Codex pluginsExtending
login / logoutManage authenticationSwitching accounts
updateUpdate Codex itselfPeriodic updates
doctorDiagnose install, config, auth, and runtime healthTroubleshooting
sandboxRun a command inside the Codex sandboxSafe execution
cloudBrowse/apply Codex Cloud tasks (experimental)Cloud workflows
completionGenerate shell completion scriptsInitial setup
archive / unarchive / deleteManage saved sessionsHistory management
featuresInspect feature flagsChecking features
app / app-serverLaunch the desktop app / run the app server (experimental)App and MCP integration
mcp-server / execpolicyRun Codex as an MCP server / inspect experimental execution policyAdvanced integration and control

Interactive Slash Commands

Commands you run with / during an interactive session (verified on codex-cli 0.143.0).

CommandWhat it does
/initCreate AGENTS.md (an instructions file for Codex)
/statusShow the current session configuration
/modelChoose the model and reasoning effort
/permissionsChoose what Codex is allowed to do (approval/sandbox)
/reviewReview changes and surface issues
/compactSummarize the conversation to avoid the context limit
/planPlan mode (plan before executing)
/diffShow 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
/promptsRecall saved prompts
/ide [on|off|status]Toggle IDE context
/raw [on|off]Toggle raw scrollback mode
/keymap [debug]Keymap settings
/feedbackReport an issue or feedback
/newStart a new conversation
/clearClear the screen and context
/logoutSign out

Key Options and Flags

Flags you’ll use most often with codex / codex exec.

FlagWhat 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
--searchEnable web search
--oss / --local-providerRun with a local OSS model
--skip-git-repo-checkRun outside a git repository (exec)
--jsonEmit 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)
--yoloShort form of --dangerously-bypass-approvals-and-sandbox; normally avoid it
--dangerously-bypass-approvals-and-sandboxDisable 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-request for interactive work; workspace-write + never for automation (writes confined to the working directory)
  • Use danger-full-access or --dangerously-bypass-approvals-and-sandbox only 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

  1. codex exec --sandbox workspace-write --ask-for-approval never "fix the failing tests"
  2. For structured output, combine --output-schema schema.json with --json
  3. For a temp directory outside git, add --skip-git-repo-check

Review changes → apply

  1. codex review --uncommitted to review uncommitted changes (or /review in-session)
  2. Apply the latest Codex Cloud diff to your working tree with codex apply

Resume tomorrow / try an alternative

  1. The next day, run codex resume --last to resume the most recent session
  2. 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 /init or on first run; it’s the equivalent of Claude Code’s CLAUDE.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 by codex 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 with codex exec, set the safe scope with -s/-a
  • 🟡 Once comfortable: /init, /review, /compact, codex resume, codex apply
  • 🟢 Look up the rest with codex --help when you need it. Bookmark this page as a reference
  • Confirm the latest spec with codex --help and codex update (Codex CLI moves fast)
krona23

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.

DevGENT about →

Leave a Reply

Trending

Discover more from DevGENT

Subscribe now to keep reading and get access to the full archive.

Continue reading