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.
codex exec "..."is the scripting entry point. Add--jsonto parse it.-sand-aset sandbox and approvals per run. They are independent.-c key=valueoverrides any config key for one run.codex resume --lastcontinues where you were;codex forkbranches instead.codex doctoris the first thing to run when anything is wrong.--full-autowas removed. Use-s workspace-write -a never./model,/permissions, and/statuschange things mid-session.
Subcommands
The ones you will use. Verified against codex --help, Codex 0.144, August 2026.
| Command | Does |
|---|---|
codex | Interactive session in the current directory |
codex "prompt" | Interactive, with an opening prompt |
codex exec "prompt" | Non-interactive. Run and exit. Alias codex e. |
codex review | Run a code review non-interactively |
codex resume | Resume a previous session. --last skips the picker. |
codex fork | Branch a previous session instead of continuing it |
codex apply | Apply the agent latest diff to your working tree as a git apply |
codex login | Authenticate. codex login status reports what you are signed in as. |
codex logout | Remove stored credentials |
codex mcp | Manage MCP servers: list, get, add, remove, login, logout |
codex sandbox | Run any command inside the Codex sandbox |
codex update | Update Codex in place |
codex doctor | Diagnose install, config, auth, and runtime health |
codex archive / unarchive / delete | Manage saved sessions by id or name |
codex completion | Generate shell completion scripts |
codex --version | Version. Include it in any bug report. |
Flags
Available on both the interactive command and exec.
| Flag | Values | Purpose |
|---|---|---|
-s, --sandbox | read-only, workspace-write, danger-full-access | Capability boundary |
-a, --ask-for-approval | untrusted, on-request, never | When it asks |
-m, --model | A model id | Model for this run |
-p, --profile | A profile name | Layer $CODEX_HOME/<name>.config.toml |
-c key=value | Any config key | Override anything. Parsed as TOML. |
-C, --cd | A path | Working root for the agent |
--add-dir | A path | Extra writable directory beside the workspace |
-i, --image | File paths | Attach images to the opening prompt |
--search | Enable the native web search tool | |
--strict-config | Error on config keys this version does not know | |
--dangerously-bypass-approvals-and-sandbox | No sandbox, no prompts. For externally sandboxed environments only. |
exec only.
| Flag | Purpose |
|---|---|
--json | Print 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 |
--ephemeral | Do not persist session files to disk |
--skip-git-repo-check | Allow running outside a git repository |
--ignore-user-config | Ignore config.toml; auth still uses CODEX_HOME |
--color | always, 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.
| Was | Now | Symptom if you use the old one |
|---|---|---|
--full-auto | -s workspace-write -a never | unexpected argument '--full-auto' found |
-a on-failure | Only untrusted, on-request, never | Invalid value for the flag |
[profiles.x] in config.toml | $CODEX_HOME/x.config.toml | Config 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.
| Command | Does |
|---|---|
/model | Choose the model and reasoning effort |
/permissions | Choose what Codex is allowed to do, and inspect the active sandbox |
/status | Show current session configuration |
/review | Review any changes and find issues |
/diff | Show the git diff, including untracked files |
/init | Generate an AGENTS.md scaffold in this directory |
/compact | Summarise the visible chat to free tokens |
/clear | Clear the terminal and start a fresh chat |
/copy | Copy the latest completed Codex output |
/skills | Browse and use skills |
/mcp | List configured MCP tools |
/memories | Configure memory use and generation |
/agent, /subagents | Switch the active agent thread |
/import | Import Claude Code setup, projects, and recent chats |
/rename, /archive, /delete | Manage the current session |
/exit | Exit 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
# 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.
| Job | Flags |
|---|---|
| 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
# 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"
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
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.