Guide

OpenAI Codex CLI: install, commands, config.toml and codex exec

Updated

Also in: Deutsch, Français, Español, Português

On this page

OpenAI Codex CLI is an Apache-2.0 licensed coding agent from OpenAI that runs locally in your terminal. Run codex interactively to inspect repositories, edit files, run local tools and review code, or codex exec non-interactively in scripts and CI pipelines. It reads ~/.codex/config.toml and project .codex/config.toml files, loads AGENTS.md instructions, and enforces boundaries with sandboxes and approval policies.

Logitech MX Creative Keypad running Orbtile with a Codex session waiting for attention

Where Codex CLI fits alongside OpenAI's other Codex surfaces

OpenAI offers Codex across several surfaces:

  • Codex CLI (codex): lightweight local coding agent in your terminal against your repository and local tools.
  • IDE extensions: available for VS Code, Cursor and Windsurf. The CLI and IDE extension share the same configuration layers.
  • Desktop app (codex app): run codex app or visit the Codex App page on chatgpt.com.
  • Codex Web (chatgpt.com/codex): cloud agent. codex cloud browses cloud chats, submits work to a configured environment, and applies results locally.

ChatGPT plans and API key access for Codex CLI

ChatGPT Work and Codex share pricing, credits and usage limits. The Free ($0 a month) and Go ($8 a month) plans include GPT-6 Luna at Standard speed in the desktop app, subject to rollout. You can use Codex CLI with a Plus ($20 a month), Pro, Business, Edu or Enterprise plan. An OpenAI API key also works in the CLI at API pricing, without cloud features such as GitHub review.

Run /status during an active Codex CLI session to see your remaining usage limits.

Install and update the OpenAI Codex CLI

Install the Codex CLI via the standalone installer script, a package manager, or GitHub Releases.

Standalone installers on macOS, Linux and Windows

On macOS or Linux, install or update from your shell:

curl -fsSL https://chatgpt.com/codex/install.sh | sh

On Windows, run in PowerShell to install or update:

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

Standalone installers download from https://releases.openai.com/codex and fall back to GitHub Releases if a download is unavailable. To force GitHub Releases, set CODEX_INSTALLER_USE_RELEASES_OPENAI_COM to false (0 or no also work):

curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_INSTALLER_USE_RELEASES_OPENAI_COM=false sh

In Windows PowerShell, set the same environment variable before running install.ps1:

$env:CODEX_INSTALLER_USE_RELEASES_OPENAI_COM='false'; irm https://chatgpt.com/codex/install.ps1 | iex

Package managers and GitHub Release binaries

  • npm: npm install -g @openai/codex to install.
  • Homebrew: brew install --cask codex to install.
  • GitHub Releases: download codex-aarch64-apple-darwin.tar.gz or codex-x86_64-apple-darwin.tar.gz (macOS), or codex-x86_64-unknown-linux-musl.tar.gz or codex-aarch64-unknown-linux-musl.tar.gz (Linux). Extract the platform-named executable and rename it to codex.

Update with codex update and check installation health

When your installed release supports self-update, codex update checks for and applies a Codex CLI update. You can also re-run the standalone installer. codex doctor reports on your installation:

codex update
codex doctor
  • Diagnostics (codex doctor): checks installation, configuration, authentication, runtime, Git, terminal, app-server and thread inventory health.
  • Diagnostic flags: pass --summary for grouped check rows, --network-only for connectivity checks, or --json for a redacted support report.

For version pinning and startup update settings, see Update Codex CLI and check the version.

Sign in and start a task

Run codex inside a Git repository. On first launch, choose Sign in with ChatGPT (Plus, Pro, Business, Edu or Enterprise) or configure an API key. Create Git checkpoints before and after runs to revert changes cleanly.

Interactive CLI commands and terminal workflows

Manage context, reviews, tools and permissions from your shell or an interactive session:

Command or flagWhat it does
codex resumeReopens a recent repo chat or searches local chats
codex --imagePasses a screenshot, diagram or design reference with the first prompt
codex --searchSwitches a run to live web search
codex mcpAdds local or remote MCP servers, authenticates, and inspects tools
codex cloudBrowses cloud chats, submits work to a configured environment, and applies results locally
codex completionGenerates a shell completion script for bash, zsh, fish, power-shell or elvish
/permissionsSets when Codex edits files or runs commands without asking; shows the active sandbox and writable roots

Two built-in workflows assist with larger changes:

  • Local code review: reviews uncommitted changes, a commit, or a base branch and reports prioritised findings without modifying your working tree.
  • Subagents: delegates focused investigations to specialised subagents and returns findings to the main session.

Global flags: sandboxes, --yolo mode and local models (--oss)

Pass global flags to codex. Most also apply to subcommands such as codex exec.

Global flagValuesBehaviour
--sandbox, -sread-only, workspace-write, danger-full-accessSelects the sandbox policy for model-generated shell commands
--ask-for-approval, -aon-request, neverControls when Codex pauses for human approval before running a command
--approve-for-me, --not-so-yolobooleanAutomatic approval review with on-request approvals and the workspace-write sandbox
--dangerously-bypass-approvals-and-sandbox, --yolobooleanRuns every command without approvals or sandboxing; only use inside an externally hardened environment
--ossbooleanUses a local open source model provider
--local-providerlmstudio, ollamaSelects the local provider used with --oss
--model, -mstringOverrides the configured model, such as gpt-6.1-sol
--worktreebooleanStarts in a new managed Git worktree for local execution
--cd, -C and --add-dirpathSets the working directory or grants extra directories write access

For low-friction local work, OpenAI suggests --sandbox workspace-write --ask-for-approval on-request. To run Codex CLI with local models through Ollama or LM Studio, pass --oss and --local-provider:

codex --oss --local-provider ollama

Customise themes, shell completions and the prompt editor

Customise the interactive terminal UI with built-in commands and shortcuts:

  • Syntax themes (/theme): previews themes and saves your choice to tui.theme in $CODEX_HOME/config.toml.
  • Custom .tmTheme files: place .tmTheme files in $CODEX_HOME/themes to add your own themes.
  • External prompt editor (Ctrl+G): opens the editor configured by VISUAL, or EDITOR when VISUAL is unset.
  • Shell completions: run codex completion zsh, or name bash, fish, power-shell or elvish instead.

Configure Codex with config.toml

Codex stores personal defaults in ~/.codex/config.toml and project overrides in .codex/config.toml (also accessible in the IDE extension via the gear icon under Codex Settings > Open config.toml).

Codex loads project .codex/ layers (config, hooks and rules) only in trusted projects; untrusted projects use only user and system configuration.

Configuration precedence

From highest precedence to lowest:

  • CLI flags and --config (-c) overrides
  • Project .codex/config.toml files, from project root to current directory (closest wins, trusted projects only)
  • Profile files via --profile profile-name (~/.codex/profile-name.config.toml)
  • User config (~/.codex/config.toml)
  • Cloud-managed config.toml defaults for the workspace
  • System config (/etc/codex/config.toml on Unix)
  • Built-in defaults

On managed machines, organisations can also enforce constraints via requirements.toml, such as disallowing approval_policy = "never" or sandbox_mode = "danger-full-access".

Common config.toml settings and feature flags

model = "gpt-6.1-sol"
model_reasoning_effort = "medium"
approval_policy = "on-request"
sandbox_mode = "workspace-write"
web_search = "cached"
personality = "none"

[shell_environment_policy]
ignore_default_excludes = false

[shell_environment_policy.filters]
"PATH" = "include"
"HOME" = "include"

[features]
prefer_mxc = true

Key config.toml options:

  • Model and reasoning: model sets the default model in the CLI and IDE, and model_reasoning_effort tunes how much reasoning effort the model applies.
  • Approvals: approval_policy sets when Codex pauses for approval, with values such as "on-request" or "never", and "untrusted" is retired.
  • Sandbox and permissions: sandbox_mode sets filesystem and network access, and the built-in profiles are :read-only, :workspace and :danger-full-access.
  • Web search: web_search defaults to "cached" (OpenAI cache, reducing prompt injection risk). Use "indexed" to gate access through the search index, "live" for current pages (same as --search, and default under full-access sandboxes like --yolo), or "disabled".
  • Communication style: personality = "none" drops the built-in Personality prompt section while keeping custom base instructions (friendly, pragmatic and /personality are retired).
  • TUI keymap and logs: [tui.keymap.global], [tui.keymap.composer] and [tui.keymap.chat] set shortcuts (empty list unbinds). log_dir sets the log path and enables plaintext codex-tui.log.
  • Shell environment: under [shell_environment_policy], ignore_default_excludes defaults to true. Set false to exclude variables containing KEY, SECRET or TOKEN, or set [shell_environment_policy.filters].
  • Feature flags: [features] toggles apps, goals, hooks, fast_mode, memories (off by default), multi_agent, remote_plugin, shell_snapshot, shell_tool and unified_exec, or pass codex --enable feature_name.

Layer custom instructions with AGENTS.md

Codex builds its AGENTS.md instruction chain once at session start:

  • Global instructions: in ~/.codex (or CODEX_HOME), Codex loads AGENTS.override.md first, falling back to AGENTS.md.
  • Project and nested instructions: walking from the project root (usually Git root) to your current directory, Codex loads at most one non-empty file per folder: AGENTS.override.md, then AGENTS.md, then names in project_doc_fallback_filenames.
  • Merge order and size cap: files concatenate from root down so closer instructions override broader rules, up to project_doc_max_bytes (32 KiB default in config.toml).

To audit loaded files, run codex -c log_dir=./.codex-log and check ./.codex-log/codex-tui.log. For sharing AGENTS.md with Anthropic's agent, see Share context between Claude Code and Codex.

Run scripts and CI pipelines with codex exec

Run Codex non-interactively with codex exec:

codex exec "summarise the repository structure and list the top 5 risky areas"

Key codex exec behaviours:

  • Stdout and stderr: progress streams to stderr while only the final message prints to stdout for piping or saving via -o <path> (--output-last-message <path>). Use --ephemeral to skip writing session rollout files.
  • Piping stdin: piped input serves as context when paired with a prompt argument, or as the entire prompt when you omit the argument or pass codex exec -.
  • Sandbox flags: codex exec runs in a read-only sandbox by default, and --sandbox workspace-write allows edits.
  • Automatic approvals: --full-auto is no longer supported. --approve-for-me routes approval requests through automatic review with the workspace-write sandbox.
  • Clean automation: --ignore-user-config skips $CODEX_HOME/config.toml, --ignore-rules skips .rules files, and --skip-git-repo-check bypasses the Git repo requirement. If an MCP server marked required = true fails to initialise, codex exec exits with an error.
  • Structured output: --json streams JSON Lines events (thread.started, turn.started, item.*, turn.completed, turn.failed, error). --output-schema ./schema.json enforces a JSON Schema.
  • Resuming runs: run codex exec resume --last "<prompt>" or codex exec resume <SESSION_ID> "<prompt>".
  • CI authentication: pass CODEX_API_KEY=<api-key> codex exec ... inline for a single run rather than as a job-level variable in workflows that run repository-controlled code, or use openai/codex-action@v1 in GitHub Actions, which starts a proxy for the API key.

Windows sandboxing: mxc, elevated and unelevated

On Windows, configure Codex's sandbox preference and legacy fallback in config.toml:

  • Prefer MXC (prefer_mxc): set prefer_mxc = true under [features] to prefer MXC when the device and policy support it.
  • Elevated fallback (elevated): set sandbox = "elevated" under [windows] as the legacy fallback implementation.
  • Unelevated fallback (unelevated): use unelevated only when elevated setup is unavailable and your organisation's policy permits it.
[windows]
sandbox = "elevated" # Legacy fallback

[features]
prefer_mxc = true

The codex sandbox subcommand runs arbitrary commands inside Codex-provided macOS, Linux or Windows sandboxes. For full Windows setup details, see Install Codex CLI on Windows: PowerShell, npm, sandbox and WSL.

Watch Codex CLI sessions on a keypad or phone with Orbtile

When running multiple codex terminals, codex exec scripts and desktop chats, Orbtile shows each session on a Logitech MX Creative Keypad, an iPhone (iOS 17+) or an Android phone (Android 8.0+) with Orbtile Mobile, paired with macOS 14.0 Sonoma+ (Apple silicon) or Windows 11 (x64).

  • Zero-install detection: Orbtile reads Codex's thread files and its own signals. Terminal codex, codex exec and desktop app chats each get a tile showing state, tool labels, waits and latest assistant text.
  • Urgency and colours: working sessions use cool blue and glow magenta-violet when waiting. Waiting sessions move to the front automatically, and key 9 jumps to the first waiting session.
  • Approvals from the pad: for compatible local desktop app chats, press Deny or hold Allow (0.6s) on command approvals and answer supported multiple-choice questions. Terminal codex command approvals offer Allow on the keys (decline in the terminal). codex exec runs do not ask for command approval (Codex 0.159.0), and other terminal waits show Answer on computer so tapping brings the session forward.
  • Optional hooks and SSH: for a compacting state and earlier updates, install optional hooks in Settings > Agents > Codex and trust them in Codex under Settings > Hooks. Orbtile also tracks remote Codex CLI sessions over SSH alongside Claude Code and ZCode CLI sessions. See Know when a Codex task is waiting for you and Watch Claude Code and Codex running on a remote server over SSH.

For the Codex keys and setup in one place, see the Codex keypad guide.

FAQ

How do I install the OpenAI Codex CLI?

On macOS or Linux, run the install.sh script from chatgpt.com/codex with curl and sh, or install with Homebrew or npm. On Windows, run the install.ps1 script from chatgpt.com/codex in PowerShell. Then run codex inside a project directory and sign in with your ChatGPT account or an API key.

Where does the OpenAI Codex CLI store its configuration and instructions?

Codex reads your personal settings from ~/.codex/config.toml and project overrides from .codex/config.toml in trusted repositories. It reads global custom instructions from ~/.codex/AGENTS.md and layers repository instructions from AGENTS.md and AGENTS.override.md files from the project root down to your working directory.

How does codex exec work in scripts and CI pipelines?

The codex exec command runs Codex non-interactively without opening the terminal interface. It streams progress to standard error, prints the final message to standard output, and runs in a read-only sandbox by default unless you pass workspace-write or danger-full-access with the sandbox flag.

Can I approve Codex CLI terminal commands from the Logitech MX Creative Keypad with Orbtile?

For terminal Codex command approvals, Orbtile offers Allow on the keypad by holding the Allow key for 0.6 seconds, while declining a command is done in the terminal. For compatible local Codex desktop app chats, the keypad offers both Allow and Deny for command approvals as well as answers to supported multiple-choice questions.