OpenAI Codex CLI cheat sheet
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.
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
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
| Flag | What 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=value | Override 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-sandbox | No approvals, no sandbox — isolated envs only |
In-session slash commands
| Command | What it does |
|---|---|
/model | Choose model and reasoning effort |
/permissions | Choose approvals + sandbox |
/init | Create an AGENTS.md for the project |
/compact | Summarize the conversation to avoid the context limit |
/review | Review current changes and find issues |
/diff · /status | Show git diff · session config + token usage |
/mcp | List configured MCP tools |
/new | Start a new chat within the conversation |
# ~/.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
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.
Claude Code
Gemini CLI
Aider
Goose
Qwen Code
Crush
Grok CLI
OpenHands CLI
Cline CLI
Roo Code CLI
Continue CLI