Codex CLI Cheatsheet - OpenAI Terminal Coding Agent Full Reference
All Codex CLI terminal coding agent commands in one place — from install & login to non-interactive exec, sandbox approval, and MCP — organized by scenario. Copy and go.
Back to AI CLIInstall & Auth 7
npm install -g @openai/codexInstall globally via npm (all platforms)
brew install --cask codexInstall on macOS via Homebrew
codex --versionVerify install and show version
codex loginBrowser OAuth sign-in to ChatGPT
codex login --with-api-keyRead API key from stdin to log in
codex login --device-authHeadless/SSH device-code login
codex logoutSign out
Interactive Mode 5
codexStart an interactive TUI session
codex "Explain this codebase"Start the TUI with an initial prompt
codex --search "Fix the login bug"Enable live web search
codex -i ./screenshot.png "Implement this UI"Attach an image (comma-separate multiple)
codex --ossUse a local open-source model (Ollama, etc.)
Non-interactive (codex exec) 5
codex exec "Fix the failing tests"Non-interactive automation mode (alias codex e)
echo "Refactor utils" | codex exec --ossPipe input + local model
codex exec --json "List all API endpoints"Output JSONL for scripting
codex exec -o result.txt "Summarize the architecture"Save the final response to a file
codex exec --output-schema '{...}' "Extract config"Constrain output with a JSON Schema
Session Management 5
codex resumeResume the previous session
codex forkFork the previous session into a new thread
codex applyApply the latest diff as git apply (alias codex a)
codex --restoreRestore the previous session (some versions)
codex --historyBrowse past session history
Model & Config 5
codex -m gpt-5.4 "Complex task"Set the model (e.g. gpt-5.4 / gpt-5.4-mini)
codex -p openai "Generate a component"Load a named config profile
codex -C /path/to/repoSet the working root directory (--cd)
codex -cOverride config.toml values
codex completion bashGenerate bash completion script
Sandbox & Approval 8
codex -s read-onlySandbox read-only (default, safest)
codex -s workspace-writeSandbox can write the working directory
codex -s danger-full-accessFull access (use cautiously in containers)
codex -a untrustedPrompt for untrusted actions (default)
codex -a neverNever approve (for read-only exploration)
codex --full-auto "Complete the implementation"Auto-approve: workspace-write + on-failure
codex --yolo "Emergency fix"Skip all sandbox and approvals (dangerous)
codex --dangerously-bypass-approvals-and-sandboxFully bypass sandbox and approvals (in containers)
MCP & Codex Cloud 7
codex mcp listList configured MCP servers
codex mcp add -- <args...>Add a stdio MCP server
codex mcp add --url https://example.com/mcpAdd an HTTP MCP server
codex mcp get <name>Show server configuration
codex mcp remove <name>Remove a server
codex cloud exec --env "task"Submit a task to Codex Cloud
codex cloud exec --env --attempts 3 "task"Submit a task with retry attempts (1-4)
Interactive Slash Commands 12
/clearReset UI and conversation
/compactSummarize conversation to free tokens
/newStart a fresh conversation in the same session
/forkClone current conversation into a new thread
/diffShow git diff including untracked files
/statusShow session config and token usage
/initGenerate an AGENTS.md project scaffold
/reviewCode review of working-tree changes
/planSwitch to plan (read-only) mode
/modelChoose model and reasoning effort
/permissionsSet what Codex can do without asking
/exitQuit Codex CLI
💡 Tips
- For non-interactive automation always use `codex exec` + `--json` with CI pipelines for codegen/review — Codex's signature use.
- The default `--full-auto` auto-approves inside a network-disabled sandbox: safe and hands-off; it only exits the sandbox to ask when it needs network (e.g. npm install).
- Put project conventions in AGENTS.md (repo root or ~/.codex/); Codex merges and loads them automatically — more efficient than repeating them in prompts.
- For read-only exploration use `-a never -s read-only`: no prompts yet full file read access, ideal for audits/research.
Official References
Commands are compiled from the official docs below. Click to verify the latest usage.
Maintained by LaoHand
Publicly updated on Aug 5, 2026, continuously proofread against official docs.
Found an error? Report it
Wrong command or description? Open an issue to help us fix it.
Found an error? Report it