Codex CLI Subcommands: Complete Guide to the OpenAI Codex Command-Line Interface

The OpenAI Codex CLI provides 25+ subcommands ranging from exec and review for code execution, to mcp for server management, and resume for session continuity, all defined in the Subcommand enum in codex-rs/cli/src/main.rs.

The OpenAI Codex CLI is a powerful command-line interface that dispatches tasks through a modular architecture. Understanding the available Codex CLI subcommands is essential for leveraging its full capabilities, from non-interactive code execution to MCP server management and session control.

Complete List of Codex CLI Subcommands

The subcommands are defined in the Subcommand enum located in codex-rs/cli/src/main.rs. They are organized into functional categories below.

Core Execution and Review

  • exec – Run Codex non-interactively to execute a prompt, run a script, or perform automated tasks. Source: codex-rs/cli/src/main.rs (lines 86-89).
  • review – Execute a code-review operation without entering the interactive UI. Source: codex-rs/cli/src/main.rs (lines 90-92).

Authentication Management

MCP (Model Context Protocol) Integration

Application and Server Management

  • app-server – Run the Codex app-server or its tooling for code generation and schema export. Source: codex-rs/cli/src/main.rs (lines 105-107).
  • app – Launch the Codex desktop app on macOS (downloads installer if missing). Source: codex-rs/cli/src/main.rs (lines 108-111).

Session Management

Utilities and Tooling

  • completion – Generate shell completion scripts for Bash, Zsh, Fish, etc. Source: codex-rs/cli/src/main.rs (lines 112-114).
  • sandbox – Run a command inside a Codex-provided sandbox (Seatbelt on macOS, Landlock on Linux, or Windows token). Source: codex-rs/cli/src/main.rs (lines 115-117).
  • apply – Apply the latest diff produced by Codex as a git apply operation. Source: codex-rs/cli/src/main.rs (lines 125-128).
  • features – Inspect, enable, or disable feature flags defined in Codex. Source: codex-rs/cli/src/main.rs (lines 147-149).

Advanced and Internal Commands

  • debug – Internal debugging tools for app-server debugging and memory reset. Source: codex-rs/cli/src/main.rs (lines 118-120).
  • execpolicy – Exec-policy tooling to validate exec-policy files against a command. Source: codex-rs/cli/src/main.rs (lines 121-124).
  • responses-api-proxy – Internal proxy for the OpenAI responses API. Source: codex-rs/cli/src/main.rs (lines 139-141).
  • stdio-to-uds – Relay stdio to a Unix-domain socket (internal plumbing). Source: codex-rs/cli/src/main.rs (lines 143-145).

How Codex CLI Subcommands Are Structured

The CLI architecture follows a layered design centered on clap for parsing. The entry point is defined in codex-rs/cli/src/main.rs using the MultitoolCli struct:

/// Codex CLI – parses global options and dispatches to a subcommand.
#[derive(Debug, Parser)]
struct MultitoolCli {
    #[clap(subcommand)]
    subcommand: Option<Subcommand>,
    // ... global flags
}

The #[clap(subcommand)] attribute tells clap to parse the next token as one of the Subcommand enum variants. Each variant corresponds to a specific Codex CLI subcommand and delegates to its own crate (e.g., codex_exec, codex_app_server, codex_mcp_server).

Before dispatch, root-level flags (configuration overrides via -c, feature toggles via --enable/--disable) are merged into the subcommand's CliConfigOverrides through the prepend_config_flags function. This ensures consistent configuration hierarchy across all subcommands.

Practical Usage Examples

Run a Prompt Non-Interactively

Use the exec subcommand to execute a prompt without entering the interactive TUI:

codex exec "Write a Rust function that computes the nth Fibonacci number"

This delegates to ExecCli defined in codex-rs/exec/src/cli.rs and invokes codex_exec::run_main.

Perform a Code Review

Review a file directly from the command line:

codex review path/to/file.rs

Authenticate with OpenAI


# Read API key from stdin (secure method)

printenv OPENAI_API_KEY | codex login --with-api-key

# Or use device authentication flow

codex login --device-auth

Generate Shell Completions

codex completion --shell zsh > _codex

Run Commands in a Sandbox

Execute commands within platform-specific sandboxes:


# macOS Seatbelt sandbox

codex sandbox seatbelt -- ls -l /private

# Linux Landlock sandbox

codex sandbox linux -- ls -l /

Resume a Previous Session


# Interactive picker (default)

codex resume

# Resume the most recent session directly

codex resume --last

# Resume specific session by ID

codex resume my-session-id

Enable Feature Flags

codex features enable web_search_request

Summary

  • The Codex CLI provides 25+ subcommands defined in the Subcommand enum in codex-rs/cli/src/main.rs.
  • Core execution subcommands include exec for non-interactive prompts and review for code reviews.
  • Authentication is handled via login and logout.
  • MCP integration uses mcp for client management and mcp-server for running as a server.
  • Session management commands (resume, fork, cloud) enable workflow continuity across interactions.
  • Utility commands include completion, sandbox, apply, and features for shell integration, security, and configuration.
  • The architecture delegates each subcommand to specialized crates (e.g., codex_exec, codex_mcp_server) while maintaining global configuration consistency through CliConfigOverrides.

Frequently Asked Questions

What is the difference between codex exec and codex review?

The exec subcommand runs Codex non-interactively to execute prompts, scripts, or automated tasks, making it ideal for CI/CD pipelines or one-off commands. The review subcommand specifically initiates a code-review operation on a file or directory without launching the full interactive TUI, focusing on static analysis and feedback.

How do I resume a previous Codex session?

Use the codex resume subcommand. Without arguments, it launches an interactive picker to select from saved sessions. Add the --last flag to resume the most recent session immediately, or provide a specific session ID or name (e.g., codex resume my-session-id) to restore that exact state.

What does the codex mcp subcommand do?

The mcp subcommand manages external MCP (Model Context Protocol) servers, allowing you to configure and control external tools that extend Codex's capabilities. The related mcp-server subcommand starts Codex itself as an MCP server using the stdio protocol, enabling other MCP clients to invoke Codex functionality.

How are Codex CLI subcommands implemented in the source code?

All subcommands are defined as variants of the Subcommand enum in codex-rs/cli/src/main.rs. The CLI uses clap for parsing, with the MultitoolCli struct handling global flags. Each subcommand variant delegates to a dedicated crate (such as codex_exec for the exec command) via a match statement in the main dispatch logic, ensuring modularity and maintainability.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →