AI agents

Codex CLI

Codex CLI

Codex CLI is OpenAI’s open-source coding agent for the terminal. It runs an interactive terminal UI (TUI) against your local repository, edits files and runs shell commands inside an OS-enforced sandbox, and can also run non-interactively in scripts and CI. A separate Codex cloud product runs tasks in OpenAI-managed containers; this section covers the local CLI.

Install

# macOS / Linux (install script)
curl -fsSL https://chatgpt.com/codex/install.sh | sh

# npm
npm install -g @openai/codex

# Homebrew
brew install --cask codex

On Windows, use the PowerShell installer:

powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"

Prebuilt binaries are also published on GitHub Releases. Re-running the same install command updates Codex; codex update self-updates when the installed release supports it.

First run and authentication

codex          # launch the interactive TUI
codex login    # sign in (browser-based ChatGPT OAuth by default)

You can sign in with a ChatGPT account (Plus/Pro/Business/Edu/Enterprise plans) or with an API key:

printenv OPENAI_API_KEY | codex login --with-api-key   # API key via stdin
codex login --device-auth                              # device-code flow
codex login status                                     # check auth state (exits 0 when logged in)

Credentials are cached at ~/.codex/auth.json or in the OS credential store. For automation, the CODEX_API_KEY environment variable provides single-run API-key auth. See Codex CLI terminal commands for the full command reference.

Quick start

# Interactive session with the recommended local combo
codex --sandbox workspace-write --ask-for-approval on-request

# One-shot non-interactive run (great for scripts)
codex exec "Summarize what this repo does"

# Resume your most recent session in this directory
codex resume --last

Inside the TUI, type / to open the slash-command popup and @ to attach files. Try /init to generate an AGENTS.md scaffold for your project, then ask Codex to explain the codebase.

In this section

FileWhat it covers
Codex CLI slash commandsEvery verified /command in the TUI, plus deep-dives on the most important ones
Codex CLI terminal commandsTerminal commands: codex, exec, resume, login, mcp, review, apply, cloud, and more
Codex CLI flagsGlobal and codex exec flags, grouped by purpose
Codex CLI configurationconfig.toml: location, key fields, profiles, precedence, project trust
Codex CLI project instructions (AGENTS.md)AGENTS.md discovery, overrides, size limits, and an example
Codex CLI subagentsSubagents: built-ins, custom agent TOML files, spawn/wait tools
Codex CLI skillsSkills (SKILL.md): structure, discovery, invocation, plugins
Codex CLI and MCP serversConnecting MCP servers with codex mcp add and config.toml
Codex CLI permissions, sandbox, and approvalsApproval policies, sandbox modes, platform notes, safety warnings
Codex CLI workflowsMini-workflows: understand, build, debug, refactor, review

Last verified: 2026-09-07

Official sources:

AI coding tools evolve quickly. If you find outdated information, please open an issue or pull request.