123DevOps··10 min read

How to use OpenAI Codex: CLI, app, cloud, AGENTS.md, and PR reviews

A step-by-step Codex guide for developers and DevOps: where it runs, plans, installation, a first session, sandbox and approvals, an AGENTS.md for an infra repo, MCP, codex exec in CI, Codex Cloud, GitHub PR reviews, and safety practices.

AI

You step into the service folder, type codex, and write: “add a /healthz endpoint with a test.” The agent reads the code, makes a plan, edits the files, and asks for approval before running npm test. That is Codex, OpenAI’s coding agent. This guide goes from installation to automatic pull request reviews, written for people who look after code and infrastructure. For the full map of products, see the overview of OpenAI’s AI.

A heads-up: OpenAI changed many names and addresses in 2025 and 2026. The Codex docs now live at learn.chatgpt.com/docs. Always check the official pages before following any step.

What Codex is and where it runs

Codex is a coding agent: it reads your repository, edits files, runs commands, and proposes changes, inside a sandbox and under the approval rules you set. To understand the difference between completion, chat, and agents, read the post on AI coding assistants.

The same agent shows up in several places:

Where How to use it
ChatGPT desktop app Codex mode (macOS, Windows, and Linux)
Terminal The codex CLI, the focus of this guide
IDE Extension for VS Code, Cursor, and Windsurf (“Codex: Open Codex Sidebar”)
Web chatgpt.com/codex
Codex Cloud Tasks on OpenAI-managed computers
Mobile Codex in the ChatGPT app for iOS and Android

The standalone Codex app was folded into the new ChatGPT desktop app in July 2026, which is why the download is labeled “Download ChatGPT”. Xcode and JetBrains have their own integrations, and there are connections to Slack and Linear.

Plans

According to OpenAI’s docs, Codex is included in the ChatGPT Free, Go, Plus, Pro, Business, Edu, and Enterprise plans, with important differences:

  • According to the help center, the Free and Go plans get Codex in the desktop app only.
  • Starting with Plus, you also get web, CLI, the IDE extension, iOS, and cloud.
  • Codex Cloud is not included in Free or Go.

These rules change often; check the plans page before you decide.

Installation

The official docs list the standalone installer as the first option. On macOS or Linux:

# Official installer (recommended)
curl -fsSL https://chatgpt.com/codex/install.sh | sh

# Alternative with npm
npm install -g @openai/codex

# Alternative with Homebrew (note the --cask)
brew install --cask codex

On Windows, in PowerShell:

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

Before running a script with curl | sh, open the URL and read it. The CLI is open source (Apache-2.0) and lives at github.com/openai/codex.

First session, step by step

Animated illustration: a Codex session in the terminal, from installation to passing tests Animated illustration (not a real screenshot): installation with curl -fsSL https://chatgpt.com/codex/install.sh | sh, codex in the terminal, login with “Sign in with ChatGPT”, a request to add a /healthz endpoint with a test, a plan and edits to server.ts and tests/health.test.ts, an approval prompt to run npm test (Yes / Yes, don’t ask again this session / No, tell Codex what to do), 18 passing tests, and a reminder to review the diff before committing. The real interface may use different names and positions.

  1. Go to your project folder: cd ~/projects/infra-platform.
  2. Run codex.
  3. Choose Sign in with ChatGPT. This is the recommended path for paid plans (Plus, Pro, Business, Edu, and Enterprise).
  4. The alternative is an API key. It requires additional setup, is billed at API rates, and does not give you the cloud features, such as GitHub review and the Slack integration.
  5. Run /init to generate a draft AGENTS.md (see below) and review the result.
  6. Start with small, read-only tasks:
Explain the structure of this repository and which CI pipelines exist.
List the Terraform modules and which environments each one affects.
The Helm lint job is failing in CI. Find the cause and propose a fix, without applying it.

Give context (file, error, goal) and say what the agent must not do.

Sandbox and approvals

Codex controls risk with two independent settings. The sandbox defines what commands can touch. Use the --sandbox flag or the sandbox_mode key in the config file:

Sandbox mode What it allows When to use it
read-only Read files, change nothing Investigation and sensitive repositories
workspace-write Read and write inside the project folder Day-to-day development
danger-full-access Full access, no sandbox Only in a disposable VM or container

The approval policy defines when the agent stops and asks. Use --ask-for-approval (or -a) or the approval_policy key:

  • on-request: the agent asks for approval when it needs to step outside the sandbox limits;
  • never: it never asks, which only makes sense together with a restrictive sandbox;
  • there is also a granular policy. The old untrusted has been retired.

The Auto preset combines workspace-write with on-request and is a good default. Inside a session, use /permissions to switch modes.

Be extremely careful with the --dangerously-bypass-approvals-and-sandbox flag (alias --yolo). It turns off the sandbox and approvals at the same time: the agent runs any command, with all of your access, without asking. The docs themselves do not recommend it. On your machine, with cloud credentials and a production kubeconfig, it is an incident waiting to happen. If you truly need it, use it only in an isolated, disposable environment with no real secrets.

AGENTS.md: project instructions

AGENTS.md is a Markdown file that tells the agent how the project works, which commands to use, and what is forbidden. Codex builds its instructions in this order:

  1. The global file ~/.codex/AGENTS.md. If an AGENTS.override.md exists there, it takes priority.
  2. The AGENTS.md at the repository root.
  3. The AGENTS.md files in subfolders, from the root down to the current folder. The file closest to the current folder wins.

The combined set has a 32 KiB limit, controlled by project_doc_max_bytes. The /init command creates a skeleton for you to adjust.

AGENTS.md is not OpenAI-only: it is a convention shared across tools. Other agents, such as Claude Code, read the same file too, so one well-written AGENTS.md serves the whole team.

An example for an infrastructure repository:

# infra-platform

Terraform (AWS) and Helm charts for your-org's services.

## Layout
- terraform/modules/: reusable modules
- terraform/envs/{dev,staging,prod}/: one state per environment
- charts/: service Helm charts

## Commands
- Format: terraform fmt -recursive
- Validate: terraform -chdir=terraform/envs/dev validate
- Plan: terraform -chdir=terraform/envs/dev plan
- Lint charts: helm lint charts/*

## Rules
- NEVER run terraform apply or destroy. Show the plan and stop.
- NEVER use the production kubectl context. Only kind-dev.
- Do not read or edit .env files, prod *.tfvars, or secrets/.
- Every prod change goes through a PR with human review.
- Run fmt and validate before saying you are done.

Keep it short, write verifiable rules, and review the file like code.

MCP: connecting external tools

MCP (Model Context Protocol) is the open standard that connects agents to data and tools. In Codex, you add servers from the CLI:

# General form: codex mcp add <name> --env VAR=VALUE -- <stdio command>
codex mcp add context7 -- npx -y @upstash/context7-mcp

# List configured servers
codex mcp list

The configuration lives in ~/.codex/config.toml, or in .codex/config.toml inside the project (only for projects marked as trusted). Each server gets a [mcp_servers.<name>] table:

# ~/.codex/config.toml
sandbox_mode = "workspace-write"
approval_policy = "on-request"

[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]

[mcp_servers.internal_docs]
command = "npx"
args = ["-y", "@your-org/mcp-internal-docs"]
env = { DOCS_BASE_URL = "https://docs.example.com" }

Inside a session, /mcp shows the active servers. Treat each server as a dependency: trusted sources only, with minimal access. Do not store tokens in files that go into the repository.

Useful commands

Command What it does
/init Creates a draft AGENTS.md
/status Shows the session’s configuration and state
/model Switches the model used in the session
/permissions Switches sandbox and approval modes
/review Asks for a review of your local changes
codex exec "..." Runs a task non-interactively (scripts and CI)
codex resume Resumes a previous session

codex exec is the entry point for automation. An example for a pipeline, with a read-only sandbox:

# Generates a summary of changes without modifying files
codex exec --sandbox read-only "Summarize this branch's changes against main as bullet points."

In CI, authentication requires additional setup. Keep credentials in the pipeline’s secrets and check the docs. There is also a GitHub Action and the Codex SDK for more elaborate cases.

Codex Cloud and environments

In Codex Cloud, tasks run on OpenAI-managed computers, inside reusable environments set up for your repository. You start tasks from the desktop app (by choosing “Work in > Cloud”), from the web, or from your phone, and get the result back for review. It is useful for long or parallel tasks without tying up your machine.

GitHub PR reviews

With the ChatGPT Codex connector installed on GitHub, just comment @codex review on a pull request to ask for a review. You can also turn on automatic reviews for every PR. Reviews of GitLab merge requests are in preview.

Treat Codex’s comments as those of one more reviewer, not a final approval: the merge decision stays human. Signing in with an API key does not include this feature.

Billing, in general terms

  • Sign in with ChatGPT: usage counts against your plan, with limits that vary by subscription.
  • API key: pay-as-you-go at API rates, without the cloud features.

Limits and rules change often. Keep an eye on usage and check the official pricing page. If you are comparing tools, the Claude Code guide follows the same structure as this one.

Safety for DevOps

An agent that runs commands on your machine has the same power you do. Non-negotiable rules:

  • Never give the agent production credentials. Use dev or read-only cloud profiles and a kubeconfig without a prod context.
  • Review every diff before committing, like a teammate’s PR. AI output can be confidently wrong.
  • Use the sandboxes: read-only to investigate, workspace-write to edit, and full autonomy only in a disposable environment.
  • Do not paste secrets, customer data, or personal data into the prompt. Keep in mind privacy laws such as Brazil’s LGPD or the GDPR, and your company’s policy.
  • Check your plan’s privacy terms. On consumer plans, the “Improve the model for everyone” option (under Data controls) decides whether conversations can be used for training. Business, Enterprise, Edu, and the API are not used for training by default. This is not legal advice; when in doubt, ask your legal team.

Checklist

  • I installed with the official installer, npm, or brew install --cask codex
  • I confirmed which Codex surfaces my plan includes
  • I ran /init and trimmed the AGENTS.md, with explicit infra rules
  • I use the Auto preset or read-only; --dangerously-bypass-approvals-and-sandbox only in a disposable environment
  • I added MCP servers only from trusted sources, with no tokens in the repository
  • Reviews with @codex review complement, but do not replace, human review
  • The agent has no access to production credentials or contexts

Codex delivers the most when you treat it like a fast new teammate: clear context in AGENTS.md, the sandbox on, and a review of everything it hands you.

Get updates on new posts and stay in the loop!