Get Started
Intelligent Automation

Codex CLI

AI-powered development directly in your terminal. The Codex CLI generates code, reviews pull requests, and deploys to staging — all without leaving the command line.

What Is Codex CLI

Codex CLI is the terminal-native interface to the Codex platform — AI code generation, review, and deployment in your shell.

Codex CLI brings the full power of the Codex platform into your terminal. It is a single binary that installs on Windows, macOS, and Linux and provides every platform capability through a consistent command interface. The Codex CLI understands your project structure, programming language, framework conventions, and even your personal coding style — it reads your codebase context to produce output that fits naturally alongside your existing code. Whether you are generating a new module, reviewing a pull request, debugging a test failure, or deploying to staging, the Codex CLI keeps you in flow without switching applications.

The Codex CLI maintains session context across commands. After running codex init in a project, every subsequent Codex CLI command automatically understands the language, framework, dependencies, and file structure of that project. This persistent awareness means you can generate a function, review the result, iterate on feedback, and deploy — all in a sequence of natural language commands without restating context at each step. The Codex CLI transforms your terminal from a command executor into an AI-powered development partner.

Codex CLI Command Reference

Every Codex CLI command at a glance — the complete command set for terminal-native AI development.

Command Description Example
codex init Initialize Codex in a project directory codex init --lang typescript
codex auth Authenticate with your Codex account codex auth --token $CODEX_API_KEY
codex generate Generate code from a natural language description codex generate "REST endpoint for user profiles"
codex review Review a diff or pull request for issues codex review --pr 142
codex test Generate and run tests for a module codex test --file src/auth.ts
codex fix Analyze and fix errors in a file codex fix --lint src/parser.go
codex deploy Deploy the current project to staging codex deploy --env staging
codex config View or edit project configuration codex config set lint.rules strict
codex team Manage team members and permissions codex team invite dev@company.com
codex channel Switch between stable and beta release channels codex channel set beta

Installing Codex CLI

Codex CLI installs in under thirty seconds across all three major platforms — one command, zero configuration.

Installing Codex CLI takes a single command on each platform. macOS users with Homebrew run brew install codex-gr/tap/codex. Windows users download the MSI installer from the download center — the installer adds the Codex CLI to the system PATH automatically and registers shell completion for PowerShell. Linux users on Debian-based distributions add the Codex APT repository and run apt install codex-cli. RPM-based distributions use the equivalent DNF repository.

After installation, verify the Codex CLI is working by running codex --version. Then authenticate: codex auth --token $CODEX_API_KEY. The Codex CLI stores your credentials securely in the operating system keychain or credential store. Shell completion for Bash, Zsh, Fish, and PowerShell is included — run codex completion --shell bash for setup instructions specific to your shell. The Codex CLI is now ready to use in any project directory.

Using Codex CLI for Code Generation

Describe what you need — the Codex CLI produces idiomatic, production-ready code that fits your project's conventions.

The codex generate command is the primary interface for AI code production. You describe the feature or function you need in plain English, and the Codex CLI produces a complete implementation. The prompt can be a single sentence or a multi-paragraph specification — the Codex CLI handles both. Generated code respects your project's existing conventions: indent style, quote preferences, naming patterns, import organization, and error handling idioms. The Codex CLI shows a diff before writing changes, so you can review, modify, or reject each generation before it touches your files.

Codex CLI generation supports targeted output through flags. Use --file to write output to a specific path. Use --test to automatically generate corresponding tests alongside the implementation. Use --dry-run to preview output without writing files — useful for evaluating whether the generated code matches your expectations before committing to it. The Codex CLI also supports generation from input files: pipe a spec document or ticket description into codex generate --stdin to produce code from structured requirements.

Codex CLI for Code Review

Run a comprehensive code review on any diff or pull request with a single Codex CLI command — results in seconds.

The codex review command analyzes code changes for logic errors, security vulnerabilities, performance regressions, and style violations. Point it at a pull request with codex review --pr NUMBER, a local diff with codex review --diff HEAD~1, or a specific file with codex review --file src/module.ts. The Codex CLI produces a structured report: summary, categorized findings (critical, warning, suggestion), line-specific annotations, and suggested fixes with before-and-after diffs.

Codex CLI review integrates with CI/CD pipelines through its exit codes and JSON output mode. A clean review exits with code 0. Review with only warnings exits with code 1. Review with critical findings exits with code 2. This makes it straightforward to gate deployments on Codex CLI review results: add codex review --pr $PR_NUMBER --fail-on critical to your CI pipeline and merges are blocked until critical issues are resolved. The Codex CLI JSON output mode produces machine-parseable results for custom dashboards and notification systems.

Codex CLI vs. Desktop Application

Codex CLI provides the same core capabilities as the desktop application through a faster, scriptable, keyboard-driven interface.

Both the Codex CLI and the Codex desktop application access the same platform capabilities — code generation, review, testing, and deployment. The difference is interface philosophy. The Codex CLI optimizes for speed and composability: every command is a single line, output can be piped to other tools, and the entire platform is scriptable through shell scripts and CI configuration. The desktop application optimizes for visual exploration: team dashboards, configuration management with forms instead of YAML, and drag-and-drop project organization. Many teams use both — Codex CLI for daily development and automation, the desktop app for team management and analytics.

The Codex CLI shines in automation scenarios. You can script an entire workflow: codex generate "REST endpoints for the inventory service" && codex review --diff HEAD~1 && codex test --all && codex deploy --env staging. This single pipeline generates code, reviews it, runs tests, and deploys to staging — all without human intervention between steps. The Codex CLI is also the only interface available in headless environments like CI runners and remote development servers. For developers who live in the terminal, the Codex CLI eliminates context switching entirely — everything happens in the shell where you already work.

Scripting and Automation with Codex CLI

Codex CLI is built for automation — JSON output, structured exit codes, and environment variable configuration make it a first-class CI/CD citizen.

Every Codex CLI command supports --output json for machine-parseable results. Combined with structured exit codes, this makes the Codex CLI suitable for any automation scenario. A pre-commit hook can run codex review on staged changes and reject commits with critical findings. A CI pipeline can generate boilerplate for new microservices, run the full test suite, review the diff, and deploy if all checks pass. A scheduled job can analyze the entire codebase weekly and produce a quality report for the engineering leadership team.

Environment variables control the Codex CLI configuration in automated environments. Set CODEX_API_KEY for authentication, CODEX_PROJECT to specify the project context, and CODEX_LOG_LEVEL to control verbosity. These variables eliminate the need for interactive prompts in automated environments. The Codex CLI also supports configuration files at the project, user, and system levels — precedence rules ensure CI pipelines can override user preferences without modifying committed configuration. For teams running Codex CLI in Docker containers, the official Docker image comes pre-configured with sensible defaults for headless operation.

Frequently Asked Questions

What is Codex CLI and how does it work?

Codex CLI is a terminal-native interface that brings AI-powered code generation, review, debugging, and deployment into your command line — it analyzes your codebase and responds to natural language commands.

The Codex CLI operates as a local binary that communicates with the Codex platform over an encrypted connection. When you run a command like codex generate "build a payment processing module", the Codex CLI captures your project context — file structure, language, dependencies, coding conventions — and sends it along with your prompt to the Codex inference engine. The engine produces code that fits naturally into your project, and the Codex CLI presents it as a diff for your review. Session context persists across commands, so follow-up generations and reviews build on the same understanding of your codebase. The Codex CLI is open-source and available on the download center for all major platforms.

How do I install the Codex CLI?

One command per platform — Homebrew on macOS, MSI installer on Windows, APT/RPM on Linux. Shell completion is configured automatically during installation.

Installation of the Codex CLI is designed to be as fast and frictionless as the tool itself. macOS: brew install codex-gr/tap/codex. Windows: download the MSI from the download center and run it — the installer handles PATH configuration and PowerShell completion registration. Debian/Ubuntu Linux: add the Codex APT repository using the provided script, then apt install codex-cli. Fedora/RHEL: add the DNF repository and dnf install codex-cli. After installation, authenticate with codex auth — the Codex CLI opens your browser for OAuth2 authentication and stores credentials securely.

What are the most useful Codex CLI commands?

The core Codex CLI commands are generate, review, test, fix, and deploy — together they cover the entire development lifecycle from creation to production.

Most Codex CLI users build muscle memory around five commands. codex generate creates code from descriptions — this is the entry point and most-used command. codex review analyzes changes for issues — many users run this before every commit. codex test generates and runs tests — particularly useful for filling test coverage gaps. codex fix targets specific errors and produces corrections — faster than manual debugging for common issue patterns. codex deploy pushes to the configured staging environment — closing the loop from generation to delivery in a single terminal session.

How does Codex CLI compare to using the Codex desktop application?

Codex CLI is faster and scriptable — same platform capabilities, terminal-native interface. The desktop app adds visual dashboards and drag-and-drop configuration management.

The Codex CLI and desktop application provide identical access to code generation, review, testing, and deployment. Choose the Codex CLI if you prefer keyboard-driven workflows, need to script and automate Codex operations, or work in environments without a graphical interface (CI runners, remote servers). Choose the desktop application if you want visual team dashboards, prefer forms over YAML for configuration, or manage projects through drag-and-drop organization. Many engineering teams use both — developers run Codex CLI in their terminals, while engineering managers use the desktop app to monitor team velocity and configure shared project settings. The two interfaces stay synchronized through your Codex account.

Can I script and automate with Codex CLI?

Codex CLI is designed for automation — JSON output, structured exit codes, and environment variable configuration make it a first-class citizen in CI/CD pipelines and shell scripts.

Every Codex CLI command produces machine-parseable output with --output json. Exit codes follow conventions: 0 for success, 1 for warnings, 2 for errors. This predictable behavior lets you build automation confidently — a pre-commit hook that blocks critical issues, a CI step that generates boilerplate and reviews it, a deployment pipeline that gates on review results. Environment variables like CODEX_API_KEY and CODEX_PROJECT replace interactive prompts in automated environments. The Codex CLI configuration file system supports layered settings — CI pipelines can override project defaults without modifying committed configuration files.

Explore the Codex Platform

Whether you are looking to download Codex for the first time, explore the Codex CLI for terminal-native development, or understand how Codex AI transforms your engineering practice, the platform provides integrated tools for every stage of software delivery. The AI code generation engine produces idiomatic code across 40+ languages, while intelligent code review catches bugs before they reach production. Teams can automate testing with the integrated testing suite, debug efficiently with automated debugging, and enforce quality standards with deep code analysis.

Developers integrating Codex into their toolchain start with CLI installation and IDE plugin setup for their preferred editor. The comprehensive API enables custom automation, CI/CD pipeline integration connects Codex to your deployment workflow, and Docker containerization simplifies environment configuration. For deeper integration, see the full documentation covering every feature in detail.