Agentic AI AcademyAgentic AI Academy

Cheat Sheet: CLI Flags & Subcommands

Every command-line option in one scannable place

Intermediate 11 minBuilder
What you'll be able to do
  • Be able to install and update the Codex CLI across npm, Homebrew, and the standalone scripts, and pick the right channel for your OS
  • Be able to read the `codex` command surface as subcommands (what you run) versus global flags (how it runs)
  • Be able to choose the correct `--sandbox` and `--ask-for-approval` values and explain why the two are independent
  • Be able to recognize the danger/bypass flags (`--yolo`, deprecated `--full-auto`) and when they are and aren't appropriate
  • Be able to use the feature/search and config-override flags (`--oss`, `--search`, `--enable/--disable`, `-c KEY=VALUE`) for one-off runs
  • Be able to locate the live source for any volatile value (model defaults, version, slash roster) instead of trusting a hard-coded number
At a glance

A dense, bookmarkable reference for the Codex command line: every subcommand, every global flag, the install/update channels, and the danger flags with their warnings. The organizing idea is that one root `codex` command branches into subcommands (what you do) and global flags (how it behaves), with two independent controls — approvals (WHEN it asks) and sandbox (WHERE it can write) — sitting on top. Volatile values like the default model live on the official live pages, which this lesson points you to rather than hard-coding.

  1. 1The shape of the command: one root, two axes
  2. 2Install & update
  3. 3Subcommands (the verbs)
  4. 4Global flags (the adverbs)
  5. 5Sandbox vs approval values (the two axes)
  6. 6Danger flags & the deprecated shortcuts
  7. 7TUI keys & where things live

The shape of the command: one root, two axes

Before the tables, fix the map in your head, because every flag below hangs off it. The Codex CLI is one root command, codex, that branches two ways:

  • Subcommands answer what you're doing: start an interactive session, run a headless task (exec), resume a thread, sign in, delegate to the cloud, manage MCP servers, run diagnostics. You pick exactly one subcommand per invocation (or none — bare codex launches the interactive TUI).
  • Global flags answer how it behaves: which model, which sandbox, when to ask for approval, which directory, which config overrides. Most global flags apply to codex and propagate to subcommands like exec.

Sitting across the top are two independent controls that you'll meet again and again:

  • --sandbox / -s = WHERE Codex may read, write, and reach the network (an OS-enforced boundary).
  • --ask-for-approval / -a = WHEN Codex must stop and ask a human.

They are related but not interchangeable — you set them separately, and the lesson on approvals goes deep on the combinations. Here we just catalog the values.

One discipline runs through this whole reference: Codex is fast-moving. Model names, the default model, the exact slash-command roster, per-plan limits, and the CLI version all rot. Where a value is volatile, this lesson teaches the concept and points you at the live page rather than freezing a number that will be wrong next month.

Key insight

Subcommand = verb, flag = adverb

Read codex exec -s workspace-write -m gpt-5.5 "..." as: do the exec thing (verb), and do it in workspace-write, with that model (adverbs). Separating the two halves makes the whole CLI legible.

Watch out

Don't trust hard-coded volatile values

Any model name, version number, price, or per-plan limit in any cheat sheet (including this one's examples) can be stale. Treat the live pages — developers.openai.com/codex/models, /codex/pricing, /codex/cli/slash-commands, and github.com/openai/codex/releases — as the source of truth.

Install & update

All channels install the same codex binary — the open-source CLI written in Rust. Pick by platform and preference.

bash
# npm (Node ≥ 16) — cross-platform
npm install -g @openai/codex     # SCOPED package; bare "codex" on npm is unrelated — do not install it

# Homebrew (macOS) — note it is a CASK
brew install --cask codex

# Standalone installer (macOS / Linux)
curl -fsSL https://chatgpt.com/codex/install.sh | sh

# Standalone installer (Windows PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
ChannelCommandNotes
npmnpm install -g @openai/codexScoped package, Node ≥ 16. The unscoped codex is a different, unrelated project.
Homebrewbrew install --cask codexIt is a cask, not a formula.
install.sh`curl -fsSL https://chatgpt.com/codex/install.shsh`
install.ps1`irm https://chatgpt.com/codex/install.ps1iex`
Prebuilt binaryDownload tarball from GitHub Releasese.g. codex-aarch64-apple-darwin.tar.gz; put codex on PATH.
  • Unattended installs: set CODEX_NON_INTERACTIVE=1 before the script.
  • Install target: CODEX_INSTALL_DIR overrides it (default ~/.local/bin; %LOCALAPPDATA%\Programs\OpenAI\Codex\bin on Windows).
  • Update: there is no separate updater — run codex update (a built-in subcommand) to check for and apply CLI updates.
  • Supported OS: macOS (Apple Silicon + Intel), Linux (x86_64 + arm64), Windows native (PowerShell sandbox) or WSL2. WSL1 was dropped at CLI 0.115 when the Linux sandbox moved to bubblewrap.

Tip

First run = sign in

After installing, just type codex. You'll be prompted to sign in with a ChatGPT account (recommended; uses plan-included usage) or with an OpenAI API key (usage-based billing). With an API key, "some functionality might not be available." Manage this later with codex login / codex logout.

Note

Pin the version in CI

Versions move fast (the GitHub Releases page lists frequent rust-v0.x tags). For reproducible CI, pin a specific version rather than installing latest, and check the live releases page: https://github.com/openai/codex/releases

Subcommands (the verbs)

Run one of these after codex (or none, to launch the interactive TUI). Stability and exact flags evolve — the canonical reference is https://developers.openai.com/codex/cli/reference.

SubcommandAliasWhat it does
codex [PROMPT]Launch the interactive terminal UI (optionally seeded with a prompt).
codex exec PROMPTcodex eRun a single task non-interactively and exit (CI/cron/scripting). Accepts stdin via -.
codex resume [SESSION_ID]Continue a previous interactive session. --last = most recent in cwd; --all = search beyond cwd.
codex fork [SESSION_ID]Start a new thread that preserves the original transcript.
codex loginSign in: browser OAuth (default), --device-auth, --with-api-key, --with-access-token; codex login status exits 0 when logged in.
codex logoutRemove stored credentials.
codex apply TASK_IDcodex aApply a Codex Cloud task's diff to the local repo.
codex cloud [QUERY]Interact with Codex Cloud tasks (--env ENV_ID, --attempts 1-4, codex cloud list).
`codex mcp {addlistget
codex mcp-serverRun Codex itself as an MCP server over stdio.
codex app [PATH]Launch the Codex Desktop app.
codex doctorGenerate a diagnostic report (--json, --summary, --all, --no-color, --ascii).
codex sandboxRun a command under Codex sandbox policies without the agent.
`codex features {listenabledisable}`
`codex completion {bashzshfish
codex updateCheck for and apply CLI updates.

codex vs codex exec is the split that matters most. Bare codex is interactive (a full-screen TUI). codex exec (alias e) is headless: it streams progress to stderr and prints only the final agent message to stdout (or JSONL events with --json), so RESULT="$(codex exec '...')" captures just the answer. Its default sandbox is read-only — opt into --sandbox workspace-write to let it edit files.

Example

Headless one-liners

Pipe context in and summarize: npm test 2>&1 | codex exec "summarize failing tests". Use stdin as the entire prompt: cat prompt.txt | codex exec -. Force structured JSON output: codex exec --output-schema ./schema.json -o out.json "...".

Note

Some subcommands are experimental

cloud, mcp, mcp-server, and sandbox are evolving and may change flags or behavior between releases. Re-check the live reference before depending on exact syntax in automation.

Global flags (the adverbs)

These apply to codex and propagate to most subcommands. PROMPT itself is an optional positional argument.

FlagShortValuesPurpose
--model-mmodel idOverride the configured model (e.g. -m gpt-5.5).
--config-cKEY=VALUE (repeatable)Override any config.toml value for this run (e.g. -c log_dir=./.codex-log).
--sandbox-sread-only | workspace-write | danger-full-accessSelect the sandbox policy (WHERE).
--ask-for-approval-auntrusted | on-request | neverSelect the approval policy (WHEN).
--cd-CpathSet the working directory before processing.
--add-dirpath (repeatable)Grant an extra writable directory alongside the workspace — preferred over dropping the sandbox.
--image-ipath[,path…]Attach image files to the initial prompt.
--profile-pprofile nameLayer a named profile (~/.codex/<name>.config.toml) on top of base config.

Feature / search / connection flags:

FlagValuesPurpose
--ossboolUse the local open-source model provider.
--searchboolEnable live web search (vs the cached default). Raises prompt-injection exposure.
--enable FEATURE / --disable FEATUREfeature (repeatable)Force a feature flag on/off for this run.
--strict-configboolError on unrecognized config fields instead of ignoring them.
--no-alt-screenboolDisable the TUI alternate-screen mode.
--remotews:// | wss:// | unix:// URLConnect the TUI to a remote app-server endpoint.

Note the difference: -c KEY=VALUE overrides a config key for one run; --enable/--disable toggles a named feature flag; --profile swaps in a whole overlay file. They compose — the precedence is CLI flags & -c overrides on top, then project config, then the profile, then user config.

Tip

`--add-dir` beats `danger-full-access`

When Codex needs to write somewhere outside the workspace, add just that directory with --add-dir /extra/path (repeatable) instead of removing the whole boundary with danger-full-access. Stay narrow.

Example

Composing flags

codex -m gpt-5.5 -s workspace-write -a on-request -C ./service --add-dir ../shared-lib -i mock.png "wire the new endpoint" selects the model, the sandbox, the approval mode, the cwd, an extra writable dir, and an image — all on one verb-less interactive launch.

Sandbox vs approval values (the two axes)

This is the pair people most often confuse. They are two independent controls: the sandbox is the OS-enforced boundary (WHERE), the approval policy is the human-pause rule (WHEN). You set them separately, and either can be tight while the other is loose.

--sandbox / -s (or sandbox_mode in config) — WHERE:

ValueMeaning
read-onlyInspect only; no edits or commands without approval. (Default for codex exec.)
workspace-writeRead + edit within the workspace + run routine local commands. Network is OFF by default in this mode (opt in). The low-friction local default.
danger-full-accessNo sandbox — removes filesystem and network boundaries.

--ask-for-approval / -a (or approval_policy) — WHEN:

ValueMeaning
untrustedAuto-runs only known-safe reads; everything else asks.
on-requestWorks inside the sandbox and asks to go beyond it. Recommended interactive default.
neverNo prompts; stays within the sandbox constraints.

The TUI bundles common pairings into presets: Read Only = read-only + on-request; Auto (the everyday default) = workspace-write + on-request; Full Access = danger-full-access + no approvals ("not recommended"). Note that on-failure is deprecated as an approval value.

Enforcement is real OS sandboxing: macOS Seatbelt (sandbox-exec); Linux/WSL2 bubblewrap + seccomp (with Landlock fallback); Windows native sandbox via PowerShell. If the platform can't enforce the policy, Codex refuses to run rather than run unsandboxed.

Key insight

WHERE and WHEN are orthogonal

You can run workspace-write (can edit) with untrusted approvals (asks a lot), or read-only (can't edit) with never (never asks). The sandbox limits capability; the approval policy limits autonomy. Don't collapse them into one mental dial.

Watch out

Network is off in workspace-write

By default workspace-write blocks outbound network (and blocks localhost/127.0.0.1 even when you opt in, as a DNS-rebinding defense). If a task needs the network, enable it explicitly in config — don't reach for danger-full-access just to get connectivity.

Danger flags & the deprecated shortcuts

Two more flags remove safety at once. Know them so you recognize them in someone else's command and never paste them blindly.

FlagAliasEffectWhen
--dangerously-bypass-approvals-and-sandbox--yoloDisables both the approval prompts and the sandbox — every command runs with no boundary and no human pause.Only inside a hardened, disposable container/VM. Never on your real machine against a repo you care about.
--full-autoDeprecated. Prints a warning; historically meant on-request approvals + workspace-write.Don't use it — set -s workspace-write -a on-request explicitly instead.

--yolo is the single most dangerous flag in the CLI: it is the union of danger-full-access (WHERE = everywhere) and never approvals (WHEN = never asks). Because sandboxing is Codex's primary defense against prompt injection — it's what stops a malicious instruction in a web page or MCP response from doing real damage — bypassing it means a single poisoned input can run arbitrary commands with your privileges.

If you genuinely need unattended autonomy, prefer the narrow tools: --add-dir to widen writes, config network opt-in for connectivity, and a real container around the whole thing. There is also no --undo and no /undo — rollback is your normal git workflow, because Codex surfaces every action in the transcript. Plan your escape hatch (a clean branch, committed state) before you loosen anything.

Watch out

`--yolo` removes your prompt-injection defense

Sandboxing is what prevents a prompt injection (from web results, MCP output, or any external content) from making harmful changes. --yolo removes it and the approval gate. Use it only in a throwaway VM/container you can burn down.

Note

There is no undo button

Codex has no /undo slash command and no --undo flag. Recovery is git: commit or stash before risky runs, review the transcript, and git restore / git reset if needed. Press Up to recover a prompt after canceling.

TUI keys & where things live

A few interactive shortcuts trip people up because they differ from other agent CLIs. Get these exactly right:

KeyAction
Ctrl+CCancel the current turn / close the session. (This is the interrupt — not Esc.)
Esc EscWhen the composer is empty: edit your previous message; keep pressing Esc to walk back the transcript, Enter to fork from that point.
Tab (while running)Queue follow-up text / slash / ! commands for the next turn.
Enter (while running)Inject new instructions into the current turn.
Ctrl+RReverse-search prompt history.
Ctrl+LClear the screen without a new conversation (distinct from /clear).
Ctrl+O / /copyCopy the latest completed output.
Ctrl+GOpen external editor ($VISUAL$EDITOR).
@Fuzzy file search over the workspace root; Tab/Enter inserts the path.
! (prefix)Run a local shell command, e.g. !ls.

State & logs live under CODEX_HOME (default ~/.codex/): config.toml, auth.json, sessions/, archived_sessions/, and log/ (codex-tui.log). Set RUST_LOG (error|warn|info|debug|trace, or targeted like codex_core=debug,codex_tui=debug) for verbose logging. The agent's project instructions live in AGENTS.md (Codex's cross-tool standard — not CLAUDE.md); scaffold one with /init.

For the in-session slash commands, the roster is large and evolving — type / to see the live popup, and treat https://developers.openai.com/codex/cli/slash-commands as canonical. Two corrections worth memorizing: the old /approvals is now /permissions, and /undo does not exist.

Watch out

Interrupt is Ctrl+C, not Esc

In Codex, Ctrl+C cancels the running turn. Esc Esc does something different — it edits your previous message. If you came from a tool where Esc interrupts, retrain that reflex now.

Tip

`codex doctor` first when something breaks

Before filing an issue, run codex doctor (add --json for a redacted machine-readable codex-doctor-report.json). It checks install, config, auth, runtime, Git, terminal, and threads — and is attached to /feedback uploads.

Try it: Build your own one-page Codex CLI cheat sheet

Goal: turn this reference into muscle memory by exercising each axis of the CLI yourself. 1) Install & verify. Install via your preferred channel (npm install -g @openai/codex, brew install --cask codex, or the install script), then run codex --version and codex doctor --summary to confirm a healthy setup. 2) Read the live surface. Open https://developers.openai.com/codex/cli/reference and note any subcommand or flag that differs from the tables here — the live page wins. 3) Exercise the two axes. In a throwaway git repo, launch codex -s read-only -a on-request and ask it a question (it should refuse to edit). Then relaunch codex -s workspace-write -a on-request and ask for a tiny edit; watch it ask before going beyond the workspace. Write one sentence on why network stayed off. 4) Try a headless run. From the shell: echo 'list the files and summarize the project' | codex exec - and confirm only the final message reaches stdout. 5) Override one config key. Run something with -c log_dir=./.codex-log and confirm the log lands there. 6) Find the volatile values. From https://developers.openai.com/codex/models and /codex/pricing, write down today's recommended default model and your plan's 5-hour limit — and note that these will change. 7) Produce the artifact. Condense all of this into a single-page cheat sheet of your most-used subcommands and flags, with the danger flags clearly marked 'container only.' Deliverable: that one-pager plus three sentences on the difference between sandbox and approval, and why Codex has no /undo.

Key takeaways

  1. 1The CLI is one root `codex` command that branches into subcommands (the verb — what you do) and global flags (the adverbs — how it runs); bare `codex` is the interactive TUI and `codex exec`/`e` is the headless one-shot.
  2. 2Install via `npm install -g @openai/codex` (scoped), `brew install --cask codex`, or the install.sh/install.ps1 scripts; update in place with `codex update`.
  3. 3Sandbox (`-s`: read-only | workspace-write | danger-full-access) and approval (`-a`: untrusted | on-request | never) are two independent controls — WHERE Codex can act and WHEN it must ask — not one dial.
  4. 4`--dangerously-bypass-approvals-and-sandbox` (`--yolo`) removes BOTH safety layers and should only run inside a disposable container; `--full-auto` is deprecated; there is no `/undo` (roll back with git).
  5. 5Reach for narrow flags before danger flags: `--add-dir` widens writes, `-c KEY=VALUE` overrides one config key, `--enable/--disable` toggles a feature, `--profile` overlays a config file, `--search` enables live (riskier) web search.
  6. 6Codex is fast-moving: the default model, full slash roster, per-plan limits, and CLI version all rot — read them from developers.openai.com/codex/models, /codex/pricing, /codex/cli/slash-commands, and github.com/openai/codex/releases, never from a frozen cheat sheet.

Quiz

Lock in what you learned

Check your understanding

0 / 4 answered

1.You want Codex to edit files in your project but you do NOT want it making any network requests, and you'd like it to pause and ask before going beyond the workspace. Which flags set this up?

2.A colleague's script uses `--dangerously-bypass-approvals-and-sandbox` (`--yolo`). What exactly does this flag do, and when is it appropriate?

3.Which install/update statement is correct?

4.You're in an interactive Codex session and want to stop the turn it's currently running. What's the correct key, and what does Esc Esc do instead?

Go deeper

Hand-picked sources to keep learning