{"slug":"codex-cli-reference","title":"OpenAI Codex CLI: Commands, Sandbox Modes, and Workflow Patterns","tags":["codex","openai","cli","agents","coding-assistant"],"agent_summary":"OpenAI Codex CLI quick reference — installation, authentication, sandbox modes (suggest/auto/full), slash commands, workflow patterns, and comparison with Claude Code equivalents.","trigger_phrases":["Codex CLI","OpenAI Codex","codex command","codex --yolo","Codex sandbox","Codex slash command"],"runnable":false,"markdown":"\n## Overview\n\nOpenAI Codex CLI is a terminal-based AI coding assistant. It runs in a project directory and can read files, write code, run commands, and iterate based on test output.\n\n## Installation\n\n```bash\nnpm install -g @openai/codex\n\n# Verify\ncodex --version\n```\n\nRequires Node.js 18+.\n\n## Authentication\n\n| Method | When |\n|--------|------|\n| ChatGPT login | Any ChatGPT subscription — browser OAuth redirect |\n| API key | No subscription, or programmatic access |\n\nPlans: Go ($8/mo), Plus ($20/mo), Pro ($100–$200/mo). Pro recommended for fast mode and high reasoning tasks.\n\n## Commands Quick Reference\n\n| Codex | Claude Code Equivalent | Description |\n|-------|----------------------|-------------|\n| `codex` | `claude` | Launch agent in current directory |\n| `codex --yolo` | `claude --dangerously-skip-permissions` | Full access, no approval prompts |\n| `codex --model o3` | `--model claude-opus-4-6` | Specify model |\n| `codex --quiet` | n/a | Minimal output, automation-friendly |\n\n## Sandbox Modes\n\nCodex runs in one of three modes, selected at startup:\n\n| Mode | Behavior | When to Use |\n|------|----------|-------------|\n| **suggest** (default) | Proposes changes, you approve each | Unfamiliar codebase, learning |\n| **auto** | Auto-applies low-risk changes, asks on risky ones | Day-to-day development |\n| **full** (`--yolo`) | No approvals, runs everything | Trusted projects, CI environments |\n\n## Slash Commands\n\nCodex supports slash commands in the interactive session:\n\n```\n/clear          — clear conversation context\n/history        — show conversation history\n/diff           — show uncommitted changes\n/files          — list files in context\n/model <name>   — switch model mid-session\n/quit           — exit\n```\n\n## Workflow Patterns\n\n### Pattern 1: Plan First, Then Build\n\n```bash\ncodex \"Create a plan for adding Stripe subscriptions to this Next.js app. \\\n       List all files that need to change. Don't write code yet.\"\n\n# Review the plan\ncodex \"Execute the plan. Write all the code.\"\n```\n\n### Pattern 2: Test-Driven Development\n\n```bash\ncodex \"Write tests for the UserService class first. \\\n       Then implement the class to make them pass.\"\n```\n\n### Pattern 3: Iterative Bug Fix\n\n```bash\ncodex \"Run the test suite and fix any failing tests. \\\n       Keep running until all tests pass.\"\n```\n\n### Pattern 4: Architecture Review\n\n```bash\ncodex --quiet \"Review the codebase structure and identify: \\\n               1. Circular dependencies \\\n               2. Missing error handling \\\n               3. Security risks \\\n               Output as a prioritized list.\"\n```\n\n## Model Selection\n\n```bash\ncodex --model o3                   # Best reasoning\ncodex --model o4-mini              # Fast, cost-efficient\ncodex --model gpt-4.1              # General purpose\n```\n\nCodex defaults to the model associated with your subscription tier. Pro subscribers get access to o3 and full context.\n\n## Context Management\n\nCodex loads files from the current directory into context. To control what's loaded:\n\n```bash\n# Add specific files\ncodex \"With context from src/auth/ and src/api/, refactor the auth middleware\"\n\n# Ignore patterns (via .codexignore or .gitignore)\necho \"node_modules/\" >> .codexignore\necho \"*.log\" >> .codexignore\n```\n\n## Non-Interactive Mode\n\nFor CI pipelines and automation:\n\n```bash\n# Run single task, no prompts\ncodex --quiet --yolo \"Run lint and fix all errors\"\n\n# With specific model\ncodex --quiet --model o4-mini \"Generate TypeScript types from schema.sql\"\n```\n\n## Comparison: Codex vs Claude Code\n\n| Feature | Codex | Claude Code |\n|---------|-------|-------------|\n| Underlying LLM | OpenAI GPT/o-series | Anthropic Claude |\n| Tool approval UI | Inline diffs | Interactive prompt |\n| Sub-agents | No | Yes (.claude/agents/) |\n| Skills system | No | Yes (.claude/skills/) |\n| Memory | Session only | Persistent (MEMORY.md) |\n| MCP support | No | Yes |\n| Hooks | No | Yes (PostToolUse, Stop) |\n| Best for | Code-heavy focused tasks | Orchestration, multi-step |\n\n## Agency Config (Codex Desktop)\n\nCodex Desktop reads config from `~/.codex/` including agent definitions and skill references. Agents are loaded at startup and not hot-reloaded — restart required after config changes.\n","html":"<h2>Overview</h2>\n<p>OpenAI Codex CLI is a terminal-based AI coding assistant. It runs in a project directory and can read files, write code, run commands, and iterate based on test output.</p>\n<h2>Installation</h2>\n<pre><code class=\"language-bash\">npm install -g @openai/codex\n\n# Verify\ncodex --version\n</code></pre>\n<p>Requires Node.js 18+.</p>\n<h2>Authentication</h2>\n<p>| Method | When |\n|--------|------|\n| ChatGPT login | Any ChatGPT subscription — browser OAuth redirect |\n| API key | No subscription, or programmatic access |</p>\n<p>Plans: Go ($8/mo), Plus ($20/mo), Pro ($100–$200/mo). Pro recommended for fast mode and high reasoning tasks.</p>\n<h2>Commands Quick Reference</h2>\n<p>| Codex | Claude Code Equivalent | Description |\n|-------|----------------------|-------------|\n| <code>codex</code> | <code>claude</code> | Launch agent in current directory |\n| <code>codex --yolo</code> | <code>claude --dangerously-skip-permissions</code> | Full access, no approval prompts |\n| <code>codex --model o3</code> | <code>--model claude-opus-4-6</code> | Specify model |\n| <code>codex --quiet</code> | n/a | Minimal output, automation-friendly |</p>\n<h2>Sandbox Modes</h2>\n<p>Codex runs in one of three modes, selected at startup:</p>\n<p>| Mode | Behavior | When to Use |\n|------|----------|-------------|\n| <strong>suggest</strong> (default) | Proposes changes, you approve each | Unfamiliar codebase, learning |\n| <strong>auto</strong> | Auto-applies low-risk changes, asks on risky ones | Day-to-day development |\n| <strong>full</strong> (<code>--yolo</code>) | No approvals, runs everything | Trusted projects, CI environments |</p>\n<h2>Slash Commands</h2>\n<p>Codex supports slash commands in the interactive session:</p>\n<pre><code>/clear          — clear conversation context\n/history        — show conversation history\n/diff           — show uncommitted changes\n/files          — list files in context\n/model &#x3C;name>   — switch model mid-session\n/quit           — exit\n</code></pre>\n<h2>Workflow Patterns</h2>\n<h3>Pattern 1: Plan First, Then Build</h3>\n<pre><code class=\"language-bash\">codex \"Create a plan for adding Stripe subscriptions to this Next.js app. \\\n       List all files that need to change. Don't write code yet.\"\n\n# Review the plan\ncodex \"Execute the plan. Write all the code.\"\n</code></pre>\n<h3>Pattern 2: Test-Driven Development</h3>\n<pre><code class=\"language-bash\">codex \"Write tests for the UserService class first. \\\n       Then implement the class to make them pass.\"\n</code></pre>\n<h3>Pattern 3: Iterative Bug Fix</h3>\n<pre><code class=\"language-bash\">codex \"Run the test suite and fix any failing tests. \\\n       Keep running until all tests pass.\"\n</code></pre>\n<h3>Pattern 4: Architecture Review</h3>\n<pre><code class=\"language-bash\">codex --quiet \"Review the codebase structure and identify: \\\n               1. Circular dependencies \\\n               2. Missing error handling \\\n               3. Security risks \\\n               Output as a prioritized list.\"\n</code></pre>\n<h2>Model Selection</h2>\n<pre><code class=\"language-bash\">codex --model o3                   # Best reasoning\ncodex --model o4-mini              # Fast, cost-efficient\ncodex --model gpt-4.1              # General purpose\n</code></pre>\n<p>Codex defaults to the model associated with your subscription tier. Pro subscribers get access to o3 and full context.</p>\n<h2>Context Management</h2>\n<p>Codex loads files from the current directory into context. To control what's loaded:</p>\n<pre><code class=\"language-bash\"># Add specific files\ncodex \"With context from src/auth/ and src/api/, refactor the auth middleware\"\n\n# Ignore patterns (via .codexignore or .gitignore)\necho \"node_modules/\" >> .codexignore\necho \"*.log\" >> .codexignore\n</code></pre>\n<h2>Non-Interactive Mode</h2>\n<p>For CI pipelines and automation:</p>\n<pre><code class=\"language-bash\"># Run single task, no prompts\ncodex --quiet --yolo \"Run lint and fix all errors\"\n\n# With specific model\ncodex --quiet --model o4-mini \"Generate TypeScript types from schema.sql\"\n</code></pre>\n<h2>Comparison: Codex vs Claude Code</h2>\n<p>| Feature | Codex | Claude Code |\n|---------|-------|-------------|\n| Underlying LLM | OpenAI GPT/o-series | Anthropic Claude |\n| Tool approval UI | Inline diffs | Interactive prompt |\n| Sub-agents | No | Yes (.claude/agents/) |\n| Skills system | No | Yes (.claude/skills/) |\n| Memory | Session only | Persistent (MEMORY.md) |\n| MCP support | No | Yes |\n| Hooks | No | Yes (PostToolUse, Stop) |\n| Best for | Code-heavy focused tasks | Orchestration, multi-step |</p>\n<h2>Agency Config (Codex Desktop)</h2>\n<p>Codex Desktop reads config from <code>~/.codex/</code> including agent definitions and skill references. Agents are loaded at startup and not hot-reloaded — restart required after config changes.</p>\n"}