Skip to main content

Introduction

Codex CLI is OpenAI’s local coding agent that you can run in your terminal. It can read code, modify files, and execute code on your machine in the directory you choose. It is open source and built in Rust for speed and efficiency. codex cli poster

Codex CLI documentation

Installation, usage, commands, and configuration reference

Codex CLI GitHub repository

Source code, release binaries, and contribution guide

Prerequisites

Make sure you have: Make sure your terminal environment supports:

Install Codex CLI

Run the following command in your terminal to install globally:
Verify the installation:

Configure Codex CLI

Create the Codex configuration file as follows:
Add the following to config.toml:
Model selection tips (Codex series):
    • gpt-5.2-codex: The default first choice and the most capable overall, suited to most real-world engineering tasks (refactoring, troubleshooting, cross-file changes, multi-step implementation).
    • gpt-5.1-codex: A stable general-purpose choice (between 5.2 and mini), suited to everyday development and as a team default.
    • gpt-5.1-codex-mini: Best for cost-effectiveness; suited to quick fixes, small changes, scaffolding, and simple problem diagnosis.
    • gpt-5.1-codex-max: Best for long or deep tasks; suited to large-scale refactoring, migrations, complex debugging, and long-running agent loops.
    • gpt-5-codex: A more “conservative/compatible” choice, suited to cases where you need to match older behavior or have specific cost/stability requirements.

Set environment variables

Set your API Key as an environment variable:
After configuration, we recommend restarting your terminal to make sure the environment variables take effect.

Get started

Go to your project directory and start Codex CLI:

Usage tips

1. Have it “understand” first, then “act”

We recommend splitting a complex request into two steps:
  1. Understand/explore: Have it first survey the architecture, entry points, dependencies, and key paths
  2. Implement/verify: Then have it change the code, run tests, and show the diff
For example:
Once you are happy with the plan, continue:
In interactive mode, Codex tends to explain its plan before executing, and lets you approve or reject at key steps.

2. Use /diff + /review often: review each round of changes like a PR

  • /diff: View working tree changes at any time (including files not tracked by Git), so you always know what changed.
  • /review: Start a dedicated reviewer that reads the diff you choose and gives prioritized suggestions, and does not touch your working tree.

3. Use /permissions to switch between “cautious” and “hands-off” at any time

Codex’s Approval modes are Auto, Read-only, and Full Access, and you can adjust them dynamically during a session with /permissions.

4. Remember to /compact in long conversations

After many rounds of conversation (especially cross-file refactoring or troubleshooting), the context keeps growing. /compact condenses the currently visible conversation into a summary, reducing token pressure while keeping key conclusions.

5. Put “long-term repository rules” in AGENTS.md

/init generates an AGENTS.md scaffold in the current directory, where you can write “this repository’s long-term preferences, conventions, and off-limits areas”. Common examples:
  • In this project, always communicate with the user in English.
  • Which test command to use by default
  • Code style / lint / commit conventions
  • Which directories/files must not be modified
  • Output format (must provide a diff, must provide migration steps, etc.)

Basic commands

1. Launch and run

On first run you will be prompted to log in: you can authorize with a ChatGPT account or use an API key. If you use API key mode, make sure the K_CODEX environment variable is set, and that config.toml has env_key = "K_CODEX" and base_url = "https://api.poixe.com/v1".

2. Common CLI flags (available at launch)

These flags are fully documented in the official Command Line Options.

3. Resume a session

Codex saves session records locally (for example in ~/.codex/sessions/), so you can pick up where you left off.

4. Non-interactive mode (CI/scripts): codex exec

Suited to automation: have it run checks, output results to stdout or JSONL, and write to files when needed.
The parameters of codex exec (such as --json, --output-last-message, --output-schema, and --yolo) are described in detail in the official documentation.

In-session slash commands

Typing / in an interactive session pops up a searchable list of commands. Here are the ones you will use most: The table above corresponds to the official Slash Commands documentation.

Notes

1. Don’t set the permission mode too wide (especially Full Access)

  • Auto (default): Reading, writing, and executing inside the directory is smooth, but it asks you again for anything outside the directory or involving the network
  • Read-only: Advisory only; it needs your approval before changing code or running commands
  • Full Access: Spans the whole machine and includes network access; use it sparingly, and only for repositories/tasks you trust completely
The behavior of these modes is defined in the official Features documentation.

2. Web search is cached by default, which does not mean “live web”

Codex’s web search is enabled by default, but it prefers an OpenAI-maintained cached index (cached) over fetching live pages; you can also enable live search with a flag. Even so, treat web results as “untrusted input” to guard against prompt injection.

3. Windows support is experimental

According to the official documentation, Codex CLI is more mature on macOS / Linux, and Windows support is still experimental; using it in a WSL workspace is recommended.

4. Use it inside a Git repository whenever possible

Many capabilities (such as /diff, review, and change tracking) depend on Git. If you run it in a non-Git directory, you can use --skip-git-repo-check when needed (mainly in codex exec scenarios).

5. “Behavior differences” under the Poixe gateway

Poixe is a relay layer and makes certain engineering trade-offs in stability, risk control, billing, and tool capabilities. If some capability is unavailable or behaves differently, first consult the relevant sections of Poixe’s compatibility and differences documentation.
Important:Poixe filters parameters related to reasoning.encrypted_content passed to the OpenAI Responses API, to avoid errors caused by encrypted reasoning fragments not being session credentials that work across organizations or Keys.For details, see Poixe’s Encrypted reasoning content filtering section.

FAQ

The first run guides you through login (ChatGPT OAuth / API key). If you use API key mode, confirm that:
  • The K_CODEX environment variable is set
  • env_key = "K_CODEX" is configured correctly in config.toml
This is usually caused by permissions or sandbox policy. Check the following in order:
  1. Whether /permissions is currently set to Read-only
  2. Whether you need to add the directory to the writable scope (--add-dir or configure writable roots)
  3. Whether the sandbox policy is restrictive (for example, --sandbox read-only blocks writing/executing)
This is by design: /review starts an “independent reviewer” that only reads the diff and outputs suggestions, and does not modify the working tree.You decide whether to adopt the suggestions and make the changes manually, or have Codex apply them as a regular task.
Use codex exec.
  • For machine-readable output: add --json
  • To write the final result to a file: use --output-last-message/-o
  • To continue a run: use codex exec resume ...
Add --search at launch to switch web_search from the default cached to live.Per the official documentation: --search sets web_search="live".