Skip to content
OpenAI Codex CLI logo

OpenAI Codex CLI cheat sheet

$ codex OpenAI Official docs

Every command, flag and slash command for codex — OpenAI's open-source terminal coding agent (Rust) — a sandboxed TUI plus a headless `exec` mode. 17+ commands, verified July 2026.

Older guides get these wrong: --full-auto is removed (use --sandbox instead); the slash command is /permissions, not /approvals; and codex login --api-key is deprecated — pipe it: printenv OPENAI_API_KEY | codex login --with-api-key.

Install
curl -fsSL https://chatgpt.com/codex/install.sh | sh                  # macOS / Linux
powershell -c "irm https://chatgpt.com/codex/install.ps1 | iex"       # Windows
npm install -g @openai/codex                                         # npm
brew install --cask codex                                            # Homebrew
Start & run
codex                           # interactive TUI in the current dir
codex "refactor auth and add tests"   # TUI with an initial prompt
codex exec "fix the failing tests"    # headless / non-interactive
codex resume --last             # resume the most recent session
codex review                    # non-interactive review of current changes
codex login  ·  codex logout    # auth management

Key flags

FlagWhat it does
-m, --model <MODEL>Model to use (e.g. gpt-5.6)
-s, --sandbox <MODE>read-only · workspace-write · danger-full-access
-a, --ask-for-approval <p>untrusted · on-request · never (TUI)
-C, --cd <DIR>Set the agent's working root
-i, --image <FILE>Attach image(s) to the prompt
-c, --config key=valueOverride any config.toml value inline
--json(exec) stream JSONL events to stdout
-o, --output-last-message <FILE>(exec) write the agent's final message to a file
--dangerously-bypass-approvals-and-sandboxNo approvals, no sandbox — isolated envs only

In-session slash commands

CommandWhat it does
/modelChoose model and reasoning effort
/permissionsChoose approvals + sandbox
/initCreate an AGENTS.md for the project
/compactSummarize the conversation to avoid the context limit
/reviewReview current changes and find issues
/diff · /statusShow git diff · session config + token usage
/mcpList configured MCP tools
/newStart a new chat within the conversation
Config
# ~/.codex/config.toml   (CODEX_HOME overrides ~/.codex)
model = "gpt-5.6"
approval_policy = "on-request"      # untrusted | on-request | never
sandbox_mode  = "workspace-write"   # read-only | workspace-write | danger-full-access

[mcp_servers.docs]                  # external tools for the agent
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "/path"]

# auth: OPENAI_API_KEY, or `codex login` with a ChatGPT plan
Common one-liners
codex exec "fix the failing unit tests" --sandbox workspace-write
codex exec -m gpt-5.6 -o result.txt "summarize the changes on this branch"
codex exec --json --skip-git-repo-check "run the linter and report findings"
codex -i mockup.png "implement this screen"            # attach a UI mock

More CLI cheat sheets

Stop memorizing flags

Run OpenAI Codex CLI — and every other agent — from one app

TheVibeFather orchestrates OpenAI Codex CLI alongside every other coding CLI in one native macOS app. Bring the models you already pay for; keep your keys.