OpenAI company mark

OpenAI · Coding assistant

Codex

Official website

A change can be only a few lines long and still leave you wondering what it might break. Codex can help you work through that question in the project itself: read the surrounding code, find the tests, make a proposed edit and run the tools you already use. It is OpenAI’s coding assistant, and this guide covers its command-line interface, or CLI, which runs in a terminal. We will start with the connection between a change and its tests, because understanding that connection makes the next edit easier to judge.

Ready guideDocumentation checked
In this guide 7 sections

Is it for you?

When it helps

  • Understanding how an unfamiliar part of a project works before you change it
  • Working through a bug fix and the regression test that should catch it if it returns

When to choose something else

  • A project you cannot yet build or test. Get those checks running before relying on Codex to verify a patch
  • Fully offline work with OpenAI’s hosted model service

Before you start

  • A local copy of the project and the dependencies needed to run its checks
  • A terminal on a supported system. The official setup page covers macOS, Linux and Windows
  • An account or API sign-in with CLI access, plus permission to send the project’s code to the selected service

Cost and access

Check the account you will use before starting a long session. CLI access, included usage and limits depend on that account; billing through an API key is separate from a ChatGPT subscription. The current access table explains what is included and when another charge may apply.

Check current access and pricing

Set it up

  1. Install Codex for your operating system

    On macOS or Linux, the command below downloads and runs the official installation script. Review the script before running it. Windows has its own instructions on the same setup page.

    Terminal command
    curl -fsSL https://chatgpt.com/codex/install.sh | sh
  2. Open the project you want help with

    Save your current work in Git, open the project directory in a terminal and run codex. Follow the sign-in flow available to your account. Having a saved starting point lets you see what Codex changes and return to the original code if you decide against the patch.

    Terminal command
    codex
  3. Decide what this session can do

    Use /permissions and /status to inspect the session’s access and settings. For an initial look around, the security guide also describes launching Codex read-only. A request to explain the code tells Codex what you want; read-only filesystem permissions prevent an unwanted edit while you are still discussing it.

How would you check this change?

Use a change you are already considering, preferably in a part of the project small enough to read yourself. Perhaps a bug fix looks straightforward, but you are unsure which test would catch the old behavior. Codex can help connect the reported problem, the code that produces it and the checks already in place. Name the function or file and explain the behavior you want before asking the question below.

What to ask

Before we change this code, help me work out how to check it. Find the relevant source and tests, explain what they already cover, and show where the behavior I described is tested or missing. Suggest a test that would distinguish the current behavior from the intended result. Wait for me before editing.

  1. Start on a disposable branch and run the relevant tests once. If they already fail, keep that result in view: you will need to distinguish an existing problem from anything the new change introduces. A clean starting diff also keeps unrelated edits out of the comparison.
  2. Read the files Codex points to. Does the proposed test actually reach the behavior you care about, with an input and expected result you can explain? If so, ask it to add the test. For a bug fix, a test that reproduces the bug before the fix gives you a much clearer comparison than one that simply passes afterward.
  3. Run the checks again and read the full diff, including changes outside the test file. You should be able to follow the test from its input to the assertion, the condition it checks. Keep the test and any accompanying fix only when that chain makes sense to you.

Before you rely on the result

You have a way to check the change and an explanation of why that check matters. The useful contribution may be a new test, or it may be discovering that the right test already exists. Either result gives you a firmer basis for the edit than asking Codex to change the code first and explain it later.

Go deeper

When setup keeps getting in the way

If each new task begins with missing dependencies or the same setup commands, a prepared cloud environment can save that repeated work. The Codex Cloud guide explains what belongs in reusable setup and what remains specific to an individual task. That distinction matters when a successful run depends on files left behind by an earlier session.

Read the guidance

Give the next reviewer enough to follow the change

The person reviewing your patch will need the same connection you just established between the behavior, the edit and the test. Keep the tested revision, commands and results with the change. The release-engineering guide follows that information into a release review, where a passing result is useful only if everyone knows what was actually checked.

Read the guidance

Other options to consider

Claude Code
A natural comparison if your team already has Claude access. Give it the same code question and compare the explanations and changes
Pi
Worth considering when the choice of model provider or the ability to change how the assistant works matters as much as the coding task

Sources and review

Based on official documentation reviewed September 30, 2026. The example is illustrative; this guide does not report an installation, benchmark or production test.

Documentation checked

Back to all tool guides