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.

AI CLI·54 commands·Last updated 2026-08-05
Back to AI CLI

Install & Auth 7

npm install -g @openai/codex
Install globally via npm (all platforms)
brew install --cask codex
Install on macOS via Homebrew
codex --version
Verify install and show version
codex login
Browser OAuth sign-in to ChatGPT
codex login --with-api-key
Read API key from stdin to log in
codex login --device-auth
Headless/SSH device-code login
codex logout
Sign out

Interactive Mode 5

codex
Start 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 --oss
Use 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 --oss
Pipe 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 resume
Resume the previous session
codex fork
Fork the previous session into a new thread
codex apply
Apply the latest diff as git apply (alias codex a)
codex --restore
Restore the previous session (some versions)
codex --history
Browse 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/repo
Set the working root directory (--cd)
codex -c
Override config.toml values
codex completion bash
Generate bash completion script

Sandbox & Approval 8

codex -s read-only
Sandbox read-only (default, safest)
codex -s workspace-write
Sandbox can write the working directory
codex -s danger-full-access
Full access (use cautiously in containers)
codex -a untrusted
Prompt for untrusted actions (default)
codex -a never
Never 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-sandbox
Fully bypass sandbox and approvals (in containers)

MCP & Codex Cloud 7

codex mcp list
List configured MCP servers
codex mcp add -- <args...>
Add a stdio MCP server
codex mcp add --url https://example.com/mcp
Add 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

/clear
Reset UI and conversation
/compact
Summarize conversation to free tokens
/new
Start a fresh conversation in the same session
/fork
Clone current conversation into a new thread
/diff
Show git diff including untracked files
/status
Show session config and token usage
/init
Generate an AGENTS.md project scaffold
/review
Code review of working-tree changes
/plan
Switch to plan (read-only) mode
/model
Choose model and reasoning effort
/permissions
Set what Codex can do without asking
/exit
Quit 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