Codex CLI commands and flags: the full reference

Codex has a small surface and it repays learning all of it, because most of the power sits in four flags and two subcommands. Verified against Codex 0.144 in August 2026.

By the Continuum team. We build a workbench that runs Claude Code, Codex, and their peers, so the model rates quoted here are the ones our own cost analytics ship with.

The short version

codex starts an interactive session, codex exec runs one prompt non-interactively, codex resume continues a previous session, and codex review runs a code review. The flags that matter are -s for sandbox, -a for approvals, -m for model, -p for a profile, and -c for arbitrary config overrides. --full-auto was removed, and the on-failure approval policy is gone.

What you need to know
  • codex exec "..." is the scripting entry point. Add --json to parse it.
  • -s and -a set sandbox and approvals per run. They are independent.
  • -c key=value overrides any config key for one run.
  • codex resume --last continues where you were; codex fork branches instead.
  • codex doctor is the first thing to run when anything is wrong.
  • --full-auto was removed. Use -s workspace-write -a never.
  • /model, /permissions, and /status change things mid-session.

Subcommands

The ones you will use. Verified against codex --help, Codex 0.144, August 2026.

CommandDoes
codexInteractive session in the current directory
codex "prompt"Interactive, with an opening prompt
codex exec "prompt"Non-interactive. Run and exit. Alias codex e.
codex reviewRun a code review non-interactively
codex resumeResume a previous session. --last skips the picker.
codex forkBranch a previous session instead of continuing it
codex applyApply the agent latest diff to your working tree as a git apply
codex loginAuthenticate. codex login status reports what you are signed in as.
codex logoutRemove stored credentials
codex mcpManage MCP servers: list, get, add, remove, login, logout
codex sandboxRun any command inside the Codex sandbox
codex updateUpdate Codex in place
codex doctorDiagnose install, config, auth, and runtime health
codex archive / unarchive / deleteManage saved sessions by id or name
codex completionGenerate shell completion scripts
codex --versionVersion. Include it in any bug report.

Flags

Available on both the interactive command and exec.

FlagValuesPurpose
-s, --sandboxread-only, workspace-write, danger-full-accessCapability boundary
-a, --ask-for-approvaluntrusted, on-request, neverWhen it asks
-m, --modelA model idModel for this run
-p, --profileA profile nameLayer $CODEX_HOME/<name>.config.toml
-c key=valueAny config keyOverride anything. Parsed as TOML.
-C, --cdA pathWorking root for the agent
--add-dirA pathExtra writable directory beside the workspace
-i, --imageFile pathsAttach images to the opening prompt
--searchEnable the native web search tool
--strict-configError on config keys this version does not know
--dangerously-bypass-approvals-and-sandboxNo sandbox, no prompts. For externally sandboxed environments only.

exec only.

FlagPurpose
--jsonPrint events to stdout as JSONL
-o, --output-last-message <FILE>Write the final message to a file
--output-schema <FILE>A JSON Schema constraining the final response
--ephemeralDo not persist session files to disk
--skip-git-repo-checkAllow running outside a git repository
--ignore-user-configIgnore config.toml; auth still uses CODEX_HOME
--coloralways, never, auto

What changed in 2026

Three things in this reference are different from every guide written before mid-2026. If a command you copied does not work, it is almost certainly one of these.

WasNowSymptom if you use the old one
--full-auto-s workspace-write -a neverunexpected argument '--full-auto' found
-a on-failureOnly untrusted, on-request, neverInvalid value for the flag
[profiles.x] in config.toml$CODEX_HOME/x.config.tomlConfig load error naming the legacy table

In-session slash commands

Type / in the composer to open the palette. These are the ones that change what the session does.

CommandDoes
/modelChoose the model and reasoning effort
/permissionsChoose what Codex is allowed to do, and inspect the active sandbox
/statusShow current session configuration
/reviewReview any changes and find issues
/diffShow the git diff, including untracked files
/initGenerate an AGENTS.md scaffold in this directory
/compactSummarise the visible chat to free tokens
/clearClear the terminal and start a fresh chat
/copyCopy the latest completed Codex output
/skillsBrowse and use skills
/mcpList configured MCP tools
/memoriesConfigure memory use and generation
/agent, /subagentsSwitch the active agent thread
/importImport Claude Code setup, projects, and recent chats
/rename, /archive, /deleteManage the current session
/exitExit the CLI

On Windows there are two more: /setup-default-sandbox configures the elevated agent sandbox, and /sandbox-add-read-dir grants read access to an extra directory.

Non-interactive mode

codex exec is the scripting interface.
# one shot
codex exec "summarise what changed in the last 10 commits"

# safe in CI: cannot write, cannot ask
codex exec -s read-only -a never "review the diff on this branch"

# cheap model for a mechanical job
codex exec -m gpt-5.6-luna "write a conventional commit message"

# read the prompt from stdin
git diff --cached | codex exec -

# machine-readable event stream, plus the final answer in a file
codex exec --json -o /tmp/answer.md "audit this package for unused exports"

Sensible pairings for automation.

JobFlags
Review a diff-s read-only -a never
Triage an issue-s read-only -a never
Apply a scripted refactor-s workspace-write -a never, after committing
Anything on untrusted input-s read-only, always
A reproducible CI run--ignore-user-config --ephemeral

Structured output

Point --output-schema at a JSON Schema file and the final message is constrained to that shape, which turns the agent into something a script can branch on rather than something a human has to read.

cat > /tmp/verdict.json <<'JSON'
{ "type": "object",
  "properties": {
    "risk": { "type": "string", "enum": ["low","medium","high"] },
    "reasons": { "type": "array", "items": { "type": "string" } }
  },
  "required": ["risk","reasons"] }
JSON

codex exec -s read-only -a never \
  --output-schema /tmp/verdict.json \
  -o /tmp/verdict-out.json \
  "assess the risk of the changes on this branch"

Reviewing, resuming, and forking

A code review without opening a session.
# staged, unstaged, and untracked
codex review --uncommitted

# everything on this branch against main
codex review --base main

# one commit
codex review --commit <sha>

# with your own instructions
codex review --base main "focus on error handling and missing tests"
Continuing yesterday work.
codex resume            # picker, filtered to this directory
codex resume --last     # straight back into the most recent
codex resume --all      # every session, not just this repo
codex fork --last       # branch it instead, leaving the original intact
The gap a terminal leaves: a session you started at the desk, continuing on the phone, instead of a run you have to walk back and check on.
Two session timelines sharing the same four turns of history: resume extends the same thread, while fork branches a second session and leaves the original untouched ONE HISTORY, TWO CONTINUATIONS YOU PICK IT UP HERE codex resume --last one session the same session id. the thread just gets longer. codex fork --last left as it was two sessions a new session id, carrying the same four turns behind it. Fork is for the point where two approaches are both worth trying.

Questions people ask

codex exec "your prompt" runs once and exits. Pair it with -s read-only -a never for anything in CI, and add --json if a script needs to parse the events.

Nothing, deliberately. Spell out the pair instead: -s workspace-write -a never. The old shorthand hid the fact that it loosened both the sandbox and the prompting at once.

Type /model. It changes both the model and the reasoning effort without restarting, and /status confirms what is actually active.

codex resume opens a picker filtered to the current directory, and codex resume --last goes straight into the most recent. Transcripts live as JSONL under ~/.codex/sessions/.

Resume continues the same session. Fork starts a new one from the same history, so you can try two approaches from a good starting point without losing either.

codex -c key="value". Any key from config.toml works, dotted paths reach nested tables, and the value is parsed as TOML with a fallback to a literal string.

Yes. Pass --output-schema with a JSON Schema file to constrain the final message, and -o to write it somewhere. --json additionally streams the whole event log as JSONL.

It diagnoses your local installation, config, auth, and runtime health in one command. Run it before you start debugging anything else, and paste it into any bug report.

Sources

Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.

  1. Codex developer commands reference
  2. OpenAI Codex documentation
  3. openai/codex on GitHub
Try it

Codex, with
a gauge.

Continuum drives Codex alongside Claude Code, with live quota per account and one spend view.

free app · your subscriptions · local-first