Skip to main content

Codex CLI — AI Coding in Your Terminal

Codex CLI is OpenAI's terminal-native AI coding assistant. This cheatsheet covers the most frequently used commands and configurations for daily workflows.

Updated: 2026-07-17·32 commands

Installation & Startup {#installation}

### One-liner install script ``bash curl -fsSL https://codex.sh/install | sh `

### Install via npm `bash npm install -g @openai/codex `

### Install via Homebrew (macOS) `bash brew install --cask codex `

### Verify installation `bash codex --version `

### Start interactive mode `bash codex `

### Launch web UI `bash codex app `

### Single prompt `bash codex "Write a Python Fibonacci function" `

### Download from GitHub Release `bash # Visit https://github.com/openai/codex/releases to download platform-specific binaries `

Chat Sessions {#chat-sessions}

### View help `bash /help `

### Clear session `bash /clear `

### View diff `bash /diff `

### Undo changes `bash /undo `

### Exit `bash /exit `

### Specify model `bash codex --model o4-mini `

Code Development {#code-development}

### Code review `bash /review `

### Auto-fix `bash /fix `

### Run tests `bash /test `

### Commit code `bash /commit `

### Generate tests `bash codex "Generate pytest tests for functions in utils.py" `

### Refactor code `bash codex "Refactor main.py to extract database logic into a separate module" `

### Generate documentation `bash codex "Generate Google-style docstrings for all public functions in project/" `

Configuration & Environment {#configuration}

### CODEX.md project config `markdown # .codex configuration — create CODEX.md in project root

Instructions

- Use TypeScript strict mode - All functions require JSDoc comments - Prefer const over let

Context

Project is a Next.js 14 App Router app using Prisma ORM.
`

### API Key authentication `bash export OPENAI_API_KEY="sk-xxxx" codex `

### ChatGPT sign-in `bash codex app # Sign in with your ChatGPT account in the browser that opens `

### Check version `bash codex --version `

### Config file location `bash # macOS: ~/Library/Application Support/codex/ # Linux: ~/.config/codex/ # Env variable: CODEX_DIR ``

Installation & Startup(9)

CommandLevel
curl -fsSL https://codex.sh/install | sh
One-liner install script
Basic
npm install -g @openai/codex
Install globally via npm
Basic
brew install --cask codex
Install via Homebrew (macOS)
Basic
codex
Start interactive session
Basic
codex app
Launch web user interface
Basic
codex <prompt>
Single-shot prompt for a direct answer
Basic
codex --version
Check installed version
Basic
curl -L -o codex https://github.com/openai/codex/releases/latest/download/codex-<platform>
Download binary from GitHub Release
Intermediate
codex doctor
Run diagnostics to verify environment and configuration
Basic

Chat Sessions(5)

CommandLevel
/help
View help information
Basic
/clear
Clear current session context
Basic
/diff
View diff of current changes
Intermediate
/undo
Undo the most recent change
Intermediate
/exit
Exit interactive session
Basic

Code Development(13)

CommandLevel
/review
Review current code changes
Intermediate
/fix
Auto-fix issues in the code
Intermediate
/test
Run tests
Intermediate
/commit
Generate commit message and run git commit
Expert
codex "为 utils.py 生成 pytest 测试"
Generate test cases
Intermediate
codex "重构 main.py,分离数据库逻辑"
Refactor code structure
Expert
codex "为 project/ 生成文档字符串"
Auto-generate code documentation
Intermediate
codex fork
Create a forked copy of the current project for isolated development
Intermediate
codex fork-reset
Reset fork branch state, discarding all local changes
Intermediate
codex pr-create
Create a Pull Request from current changes
Expert
codex review
AI-powered review of current code changes with suggestions
Intermediate
codex test
Run the project test suite
Intermediate
codex explain
Explain the functionality and logic of specified files or code snippets
Basic

Configuration & Environment(5)

CommandLevel
codex --model o4-mini
Specify a particular model
Intermediate
export OPENAI_API_KEY=sk-xxx && codex
Authenticate with API Key
Basic
CODEX.md
Project-level config file (project root)
Expert
codex --model o3
Run with o3 model
Intermediate
codex config show
View current Codex CLI configuration
Basic

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-17.