Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Cheat sheet

Codex CLI cheat sheet

Codex CLI commands, codex exec for scripts, sandbox and approval modes, config.toml keys, resuming sessions and slash commands, checked against codex --help.

By Checked Intermediate
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On this page

The commands, flags, sandbox settings and config keys for the Codex CLI (the codex command), checked against codex --help for version 0.172.0 and OpenAI’s docs on 25 November 2026. Run codex in a Git repository, use /init to write an AGENTS.md, and keep the default Auto preset (workspace-write sandbox, on-request approvals) for everyday work.

Install and sign in

# Standalone installer (macOS, Linux); run it again to update
curl -fsSL https://chatgpt.com/codex/install.sh | sh

# Or a package manager
npm install -g @openai/codex
brew install --cask codex

# Sign in with ChatGPT (opens a browser), or use a key or device code
codex login
codex login --device-auth
codex login status

On Windows, run powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex" in a new PowerShell window. codex doctor checks the install, config, auth and runtime.

Commands

Command What it does
codex Start the interactive terminal UI
codex agents Browse and switch between sessions
codex "task" Start the UI with a first prompt
codex exec "task" (alias codex e) Run without interaction, for scripts and CI
codex review Review the current repository non-interactively
codex resume Pick a previous session; --last continues the latest
codex fork Copy an earlier session into a new one
codex apply (alias codex a) Apply the latest diff from a Codex cloud task to your working tree
codex mcp add / list / login Manage MCP servers
codex plugin Manage plugins
codex sandbox Run any command inside the Codex sandbox
codex features Inspect feature flags
codex cloud Browse Codex Cloud tasks and apply their changes locally (experimental)
codex update Update an install that supports self-update

Flags for codex and codex exec

Flag What it does
-m, --model <model> Choose the model
-s, --sandbox <mode> read-only, workspace-write or danger-full-access
-a, --ask-for-approval <policy> on-request (model asks when it needs to) or never; not an exec flag
--approve-for-me Send approval requests to automatic review, with the workspace-write sandbox
-C, --cd <dir> Use this directory as the working root
--add-dir <dir> Make another directory writable too
--worktree Run in a new managed Git worktree
-c key=value Override one config.toml value for this run
-p, --profile <name> Layer ~/.codex/<name>.config.toml over your config
-i, --image <file> Attach images to the first prompt
--search Live web search instead of the default cached results (interactive only)
--oss Use a local provider (--local-provider lmstudio or ollama)
--dangerously-bypass-approvals-and-sandbox No prompts and no sandbox; only inside an isolated VM

-p means --profile in Codex. It is not the print flag it is in Claude Code; the scripted mode is codex exec.

Scripted runs with codex exec

# Read-only by default: good for questions and reports
codex exec "Summarise the structure of this repository"

# Allow edits inside the workspace
codex exec --sandbox workspace-write "Fix the failing test in tests/date.test.ts"

# JSONL events on stdout, final message saved to a file
codex exec --json -o last-message.md "List the TODO comments and where they are" | jq

# Pipe content in; the prompt is the instruction, stdin is context
cat build.log | codex exec "Why did this build fail?"

# Continue the most recent non-interactive run in this folder
codex exec resume --last "Now run the linter and fix what it finds"

Other exec flags: --output-schema <file> (JSON Schema for the final answer), --ephemeral (save nothing to disk), --skip-git-repo-check (run outside a repository) and --ignore-user-config. To override the sandbox or folder of a resumed run, put --sandbox or -C before resume. --full-auto is no longer supported. In CI, give the key only to the Codex step with CODEX_API_KEY, never to the whole job.

Sandbox and approval modes

Preset Flags What happens
Read only --sandbox read-only --ask-for-approval on-request Reads and answers; asks before any change
Auto (default) --sandbox workspace-write --ask-for-approval on-request Edits and runs commands in the workspace; asks to go outside it or use the network
Auto review --approve-for-me, or -c approvals_reviewer=auto_review Same sandbox as Auto; a reviewer agent answers approval requests for you
Full access --dangerously-bypass-approvals-and-sandbox (alias --yolo) No sandbox and no approvals; only inside an isolated VM

Network access is off by default in workspace-write. Turn it on with sandbox_workspace_write.network_access = true. The old untrusted approval policy has been retired. Switch modes inside a session with /permissions.

config.toml keys people change

# ~/.codex/config.toml (user) or .codex/config.toml (project, trusted projects only)
model = "gpt-6.2-sol"
model_reasoning_effort = "medium"
approval_policy = "on-request"
sandbox_mode = "workspace-write"
web_search = "cached"          # "indexed", "live" or "disabled"

[sandbox_workspace_write]
network_access = false

[mcp_servers.docs]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]

Precedence, highest first: CLI flags and -c, project .codex/config.toml (closest folder wins), a --profile file, ~/.codex/config.toml, cloud-managed defaults, /etc/codex/config.toml. Your organisation can block values such as approval_policy = "never" in requirements.toml.

Slash commands

Command What it does
/init Write an AGENTS.md scaffold in this folder
/permissions Change what Codex may do without asking
/model Choose the model and reasoning effort
/plan Switch to plan mode before implementing
/goal Set a persistent target for a longer task
/review Review your working tree
/diff Show the Git diff, including untracked files
/compact Summarise the chat to free context
/status Model, approval policy, writable roots and context left
/mcp List MCP tools; /mcp verbose for server details
/skills Browse and use skills
/resume, /fork, /new Reopen, branch or restart a chat
/side (or /btw) Ask a side question in a separate chat
/approve Retry one action that automatic review denied
/import Bring over Claude Code or Cursor setup
/quit, /exit Leave the CLI

Keys

Key What it does
@ Search for a file and add its path
! then a command Run a shell command under the current sandbox
Enter while Codex works Add instructions to the current turn
Tab while Codex works Queue a prompt or command for the next turn
Esc Esc on an empty composer Edit your previous message and fork from there
Ctrl+R Search prompt history
Ctrl+O Copy the latest response
Ctrl+C Close the session

Files and folders

What Where
User config ~/.codex/config.toml (move it with CODEX_HOME)
Project config .codex/config.toml
Global instructions ~/.codex/AGENTS.md, or AGENTS.override.md to override it
Project instructions AGENTS.md in each folder from the repository root down to where you work
Skills .agents/skills/ in the repository; ~/.agents/skills/ for you
Rules for commands ~/.codex/rules/, checked with codex execpolicy check

Codex stops reading AGENTS.md files once they add up to project_doc_max_bytes, 32 KiB by default.

Common mistakes

Mistake Fix
codex exec edits nothing It is read-only by default; add --sandbox workspace-write
Using -p to print In Codex -p is --profile; use codex exec
Project config ignored Codex loads .codex/ only in trusted projects; trust the folder when asked, or pass --trust to exec
npm install fails inside the sandbox Network is off in workspace-write; enable it for the project or approve the command
danger-full-access to reach one more folder Use --add-dir instead
approval_policy = "untrusted" in an old config Retired; use on-request with read-only

Check your setup

codex --version
codex doctor
codex login status
codex mcp list
codex exec "List the files in this folder"

New to Codex? Start with your first Codex CLI session, and see Codex skills for the skill folders. The same reference for Anthropic’s agent is the Claude Code cheat sheet, and GitHub’s is the GitHub Copilot CLI cheat sheet. To run Codex in CI safely, follow headless coding agents in CI.

Check your understanding

Codex CLI commands quiz

codex exec and its read-only default, -p versus --profile, sandbox and approval presets, network access, extra folders, config precedence, trusted projects and AGENTS.md limits.

8 questions · pass mark 70%

Question 1 of 80 answered
  1. You run codex exec "Fix the failing test" in CI and nothing is edited. Why?

Checked against

  • Your first session with the Codex CLI

    Install it, choose a sandbox and approval mode, give it a well-scoped task in a repository and review its changes before you accept.

    TutorialBeginner30 min

  • Claude Code cheat sheet

    Claude Code slash commands, CLI flags, headless -p runs, permission modes including auto, keyboard shortcuts and config files, checked against Anthropic's docs.

    Cheat sheetIntermediate

  • GitHub Copilot CLI cheat sheet

    GitHub Copilot CLI slash commands, flags, keyboard shortcuts, permission rules and file locations on one page, checked against copilot --help and GitHub's docs.

    Cheat sheetIntermediate

  • Codex skills: Agent Skills in Codex, the ChatGPT app and automations

    How Codex finds skills in .agents/skills, how to install them with $skill-installer, what agents/openai.yaml adds, and how skills run in scheduled automations.

    Skill guideIntermediate

  • Sandbox

    An isolated environment that limits what an agent or its code can read, write or reach on the network, so any mistakes stay contained.

    Glossary

Back to top