Skip to main content
Codex CLI provides a powerful command-line interface for interacting with the Codex coding agent. You can run Codex interactively, execute tasks non-interactively, manage authentication, configure MCP servers, and more.

Interactive vs Non-Interactive

Interactive Mode (default):
codex
codex "create a todo app"
Non-Interactive Mode (exec command):
codex exec "explain this codebase"
codex exec --json "run tests"

Core Commands

codex

Run Codex interactively or with a prompt

exec

Run Codex non-interactively for automation

review

Run code reviews on commits or branches

Session Management

apply

Apply latest diff from Codex to working tree

resume

Resume a previous interactive session

fork

Fork a previous interactive session

Authentication

login

Authenticate with ChatGPT or API key

logout

Remove stored credentials

Integration & Tooling

mcp

Manage external MCP servers

mcp-server

Run Codex as an MCP server (stdio)

app-server

Start Codex as an app server for IDEs

Utilities

completion

Generate shell completion scripts

sandbox

Run commands within Codex sandbox

features

Inspect and manage feature flags

feedback

Submit feedback about Codex

debug

Debugging tools for app server

Global Flags

These flags work with most commands:
  • -c, --config <KEY=VALUE> - Override config.toml settings
  • -p, --profile <NAME> - Use a specific config profile
  • -m, --model <MODEL> - Specify the AI model to use
  • --oss - Use open-source/local model providers
  • --enable <FEATURE> - Enable a feature flag
  • --disable <FEATURE> - Disable a feature flag

Common Usage Patterns

Quick One-Off Tasks

codex exec "add error handling to utils.ts"
codex exec --json "list all API endpoints" > endpoints.json

Code Reviews

codex review --uncommitted
codex review --base main
codex review --commit abc123

Using Different Models

codex -m gpt-4.1 "complex refactoring task"
codex --oss --local-provider ollama "local task"

Configuration Overrides

codex -c sandbox_mode=workspace_write "build a CLI tool"
codex -p production exec "deploy to staging"

Exit Codes

Codex CLI uses standard exit codes:
  • 0 - Success
  • 1 - Error occurred during execution

Next Steps

Explore individual command documentation for detailed usage, flags, and examples.