cheatsheets.zip

#Getting Started

Install & Run

$ npm install -g @openai/codex
$ npm install -g @openai/codex@latest   # upgrade

First run

$ codex                          # launch interactive TUI
$ codex "Explain this codebase"  # with initial prompt

On first run you'll be prompted to sign in via ChatGPT or an API key.

Programming

Shell completions

# Bash – add to ~/.bashrc
$ eval "$(codex completion bash)"

Authentication

$ codex login                # ChatGPT OAuth
$ codex login --device-auth  # device flow
# Pipe API key from env
$ printenv OPENAI_API_KEY | codex login --with-api-key
$ codex login status         # check auth state
$ codex logout               # remove credentials

#Subcommands

Command Reference

CommandAliasStatusDescription
codexStableLaunch interactive TUI
codex execcodex eStableRun non-interactively (scripting)
codex reviewStableNon-interactive code review
codex resumeStableResume a previous session
codex forkStableFork a session into new thread
codex applycodex aStableApply Cloud task diff locally
codex loginStableAuthenticate Codex
codex logoutStableRemove stored credentials
codex completionStableGenerate shell completions
codex featuresStableManage feature flags
codex appStableLaunch Codex desktop app
codex mcpExperimentalManage MCP servers
codex mcp-serverExperimentalRun Codex as an MCP server
codex cloudExperimentalBrowse and exec Cloud tasks
codex sandboxExperimentalRun cmds inside sandbox
codex debugExperimentalDebugging tools

Exec (Non-interactive)

# Basic non-interactive run
$ codex exec "Fix the race condition"
$ codex e "Add unit tests for utils"

# Prompt from stdin
$ echo "Explain main.go" | codex exec -

# Prompt-plus-stdin (0.118+): pipe data AND pass a prompt
$ cat error.log | codex exec "Diagnose this log" -

# Output options
$ codex exec --json "Audit security"
$ codex exec -o last.txt "Summarize"

# Resume a previous exec session
$ codex exec resume --last "Fix the bugs"
$ codex exec resume <SESSION_ID> "Implement"

#Global Options

All Flags

FlagValuesDescription
-m, --modelstringModel override (e.g. gpt-5.4)
-s, --sandboxsee belowSandbox policy
-a, --ask-for-approvalsee belowApproval policy
--full-autoflagworkspace-write + on-request
--yoloflagBypass all approvals/sandbox
-i, --imagepathAttach image(s) to initial prompt
-c, --configkey=valOverride a config value
-C, --cdpathAgent working directory
-p, --profilestringConfig profile name
--searchflagEnable live web search
--add-dirpathGrant extra directory write access
--ossflagUse local OSS provider
--local-providerlmstudio/ollamaSpecify OSS provider
--enablefeatureEnable a feature flag
--disablefeatureDisable a feature flag
--no-alt-screenflagInline TUI mode (no alt screen)
--remotews://host:portConnect to remote app server
--remote-auth-token-envENV_VARBearer token env var for remote WS
-V, --versionPrint version
-h, --helpPrint help

Usage Examples

# Specify model
$ codex -m gpt-5.4 "Refactor the auth module"

# Auto mode (low friction)
$ codex --full-auto "Run tests and fix failures"

# Attach a screenshot
$ codex -i mockup.png "Implement this UI"

# Override config inline
$ codex -c model="gpt-5.4-mini" "Quick scan"

# Live web search
$ codex --search "Find the latest async syntax"

# Set working directory
$ codex -C ~/projects/api "Review this codebase"

#Sandbox & Approvals

Sandbox Modes

read-onlyInspect only, no edits without approval
workspace-writeEdit workspace + run local commands
danger-full-accessNo restrictions (use in hardened envs)

Approval Policies

untrustedAsk before all non-trusted commands
on-requestAsk when going beyond sandbox boundary
neverNever ask; all commands run automatically

Presets

--full-autoworkspace-write + on-request
--yoloNo sandbox + No approvals

Use /permissions in the TUI to change modes mid-session.

#Slash Commands

Session Control

/modelSwitch model / reasoning effort
/fastToggle GPT-5.4 Fast mode
/permissionsAdjust approval mode
/personalitySet response style
/planEnter planning mode
/statusShow model, tokens, config
/compactSummarize to free context
/clearClear chat + start fresh
/newNew chat, keep CLI session
/forkFork current conversation
/resumeResume saved session
/exit / /quitExit the CLI

Review & Code

/reviewLaunch code reviewer
/diffShow Git diff
/copyCopy latest Codex output
/mentionAttach file to conversation
/initGenerate AGENTS.md scaffold

Tools & Debug

/agentSwitch active agent thread
/mcpList MCP tools
/appsBrowse connector apps
/experimentalToggle experimental features
/statuslineConfigure TUI footer
/psShow background terminals
/sandbox-add-read-dirAdd readable dir (Windows)
/feedbackSend logs to maintainers
/pluginsBrowse and manage plugins
/titleSet terminal title for session
/debug-configPrint config diagnostics
/logoutSign out of Codex

#Models

Available Models

ModelSpeedBest for
gpt-5.4★★★Default – coding + reasoning + workflows
gpt-5.4-mini★★★★★Subagents, light tasks, higher limits
gpt-5.3-codex★★★★Complex software engineering
gpt-5.3-codex-spark★★★★★Near-instant iteration (Pro only)

Select a Model

$ codex -m gpt-5.4 "Your prompt"
$ codex -m gpt-5.4-mini "Quick task"
$ codex --oss    # local Ollama / LM Studio
# Mid-session: type /model in the TUI

#Configuration

config.toml Keys

# ~/.codex/config.toml

# Model settings
model = "gpt-5.4"
model_provider = "openai"
model_reasoning_effort = "medium"  # low | medium | high

# Sandbox & approvals
sandbox_mode = "workspace-write"
approval_policy = "on-request"

# Web search: cached | live | disabled
web_search = "cached"

# Review model override
review_model = "gpt-5.4"

# TUI appearance
[tui]
theme = "dark"
alternate_screen = true

# Profile example
[profile.ci]
model = "gpt-5.4-mini"
approval_policy = "never"
sandbox_mode = "workspace-write"

Use -p ci to activate a profile.

Feature Flags

$ codex features list
$ codex features enable unified_exec
$ codex features disable shell_snapshot

# Per-session (not persisted)
$ codex --enable unified_exec
$ codex --disable shell_snapshot

Config Locations

~/.codex/config.tomlGlobal defaults
~/.codex/AGENTS.mdPersonal instructions
~/.agents/skills/Personal skills
.agents/skills/Repo-level skills
AGENTS.mdRepo instructions

#Customization

AGENTS.md

Persistent repo instructions, checked in alongside code:

## Build & test commands

- Install: `npm install`
- Test: `npm test`
- Lint: `npm run lint`

## Conventions

- TypeScript strict mode
- No PII in logs
- Auth middleware on all routes

## Review guidelines

- Flag unhandled promise rejections

When to add rules:

Skills

Reusable workflows packaged as SKILL.md:

my-skill/
  SKILL.md      ← metadata + instructions
  scripts/      ← optional helper scripts
  references/   ← optional documentation
  assets/       ← optional templates

Example SKILL.md:

---
name: commit
description: Stage and commit changes
  in semantic groups.
---

1. Stage files in logical groups.
2. Group: feat → test → docs → chore
3. Write concise commit messages.

MCP Servers

# Add a stdio server
$ codex mcp add myserver -- npx my-mcp-server

# Add an HTTP server
$ codex mcp add myserver \
    --url https://api.example.com/mcp

# With auth token
$ codex mcp add myserver \
    --url https://api.example.com/mcp \
    --bearer-token-env-var MY_TOKEN

# List / remove
$ codex mcp list
$ codex mcp remove myserver

# Run Codex itself as MCP server
$ codex mcp-server

#Session Management

Resume Sessions

$ codex resume           # session picker
$ codex resume --last    # most recent session
$ codex resume --all     # across all directories
$ codex resume <ID> "Continue fixing tests"

Sessions stored at ~/.codex/sessions/

Fork a Session

$ codex fork             # fork from picker
$ codex fork --last      # fork most recent
$ codex fork <SESSION_ID> "New direction"

Forking preserves the original transcript while starting a new branch.

Image Inputs

# Single image
$ codex -i screenshot.png "Fix this error"

# Multiple images
$ codex --image img1.png,img2.jpg "Compare"

# Or drag images into the TUI composer

Supported: PNG, JPEG and other common formats.

#Cloud & GitHub

Cloud Tasks

# Browse cloud environments
$ codex cloud

# Submit a cloud task
$ codex cloud exec --env <ENV_ID> "Fix bug"

# With multiple attempts (best-of-N)
$ codex cloud exec --env <ENV_ID> \
    --attempts 3 "Write failing tests"

# List recent tasks
$ codex cloud list

# Check task status
$ codex cloud status <TASK_ID>

# Show diff for a task
$ codex cloud diff <TASK_ID>

# Apply diff to local working tree
$ codex apply <TASK_ID>

GitHub Integration

# In a PR comment – trigger code review:
@codex review

# Custom focus:
@codex review for security regressions

# Delegate any task using PR as context:
@codex fix the CI failures
@codex add tests for the new endpoint

Enable in Codex Settings → Code review → your repo. Turn on Automatic reviews to review every new PR.

#Subagent Workflows

Subagents Guide

Offload noisy work to parallel agents to avoid context pollution and context rot:

codex "Review this branch with parallel agents.
Spawn one for security risks, one for test gaps, and one for maintainability. 
Wait for all three, then summarize findings with file references."

Subagent model guide:

RoleModelReasoning
Main coordinatorgpt-5.4medium
Fast explorationgpt-5.4-minilow
Security / logic reviewgpt-5.4high

Reasoning Effort

highComplex logic, security audits
mediumGeneral tasks (default)
lowSimple or speed-critical tasks

Set in config.toml:

model_reasoning_effort = "medium"

Or inline: -c model_reasoning_effort="high"

#Also See