title: "Codex CLI Cheatsheet" last_updated: 2026-03-21 tested_with: codex-cli: "0.2.x" status: proven difficulty: beginner

Codex CLI Cheatsheet

Installation

npm install -g @openai/codex

Essential Commands

CommandDescription
codexStart interactive session in current directory
codex "prompt"Start session with an initial prompt
codex --approval-mode suggestAgent suggests commands but never executes (safest)
codex --approval-mode auto-editAgent can edit files, but shell commands need approval
codex --approval-mode full-autoAgent runs everything without asking (use with caution)

Approval Modes

ModeFile ReadsFile WritesShell Commands
suggest (default)AllowedNeeds approvalNeeds approval
auto-editAllowedAllowedNeeds approval
full-autoAllowedAllowedAllowed (sandboxed)

Key Config Files

FilePurpose
AGENTS.mdProject memory -- equivalent to Claude Code's CLAUDE.md. Conventions, build commands, architecture notes.
~/.codex/config.yamlUser-level configuration (default model, approval mode, etc.)
~/.codex/instructions.mdUser-level instructions applied to all projects

The Sandbox Model

Codex CLI uses network-disabled sandboxing for command execution, especially in full-auto mode:

  • Network access is disabled by default for all shell commands.
  • Commands run in a sandboxed environment using platform-specific isolation (macOS Seatbelt, Linux namespaces).
  • File writes outside the project directory are blocked in the sandbox.
  • The sandbox protects against accidental damage but is not a security boundary against adversarial prompts.

This means full-auto is safer than it sounds -- but you should still review diffs before committing.

Common Flags

FlagDescription
--approval-modeSet approval mode: suggest, auto-edit, full-auto
--modelSpecify model (default: o4-mini)
--quietSuppress non-essential output
--notifySend desktop notification when task completes
--no-project-docSkip loading AGENTS.md

Environment Variables

VariablePurpose
OPENAI_API_KEYAPI key for OpenAI access (required)
OPENAI_BASE_URLCustom API endpoint for proxies or compatible providers
CODEX_HOMEOverride default config directory (~/.codex)

Key Differences from Claude Code

AspectClaude CodeCodex CLI
ProviderAnthropic (Claude)OpenAI (o4-mini, o3, etc.)
Project memoryCLAUDE.mdAGENTS.md
Permission modelApproval per action type with allowlistsThree approval modes (suggest/auto-edit/full-auto)
SandboxNo built-in sandbox; relies on approval promptsNetwork-disabled sandbox for shell commands
Headless modeclaude -p "prompt"Not a primary workflow (interactive-first)
Context management/compact, /clear slash commandsAutomatic context management
Plan modeBuilt-in (Shift+Tab)Not a separate mode
Default modelClaude Sonneto4-mini
Config formatJSON (.claude/settings.json)YAML (config.yaml)

Quick Tips

  • Start with suggest mode until you trust the tool with your codebase.
  • Write an AGENTS.md with build commands and conventions, just like CLAUDE.md.
  • The sandbox blocks network access, so commands needing the internet (e.g., npm install) will fail in full-auto. Approve those manually.
  • Use --notify for long-running tasks so you can context-switch.
  • Codex CLI works well for focused, single-task sessions. Keep prompts concise.