Short answer
Install it with npm, set your OpenAI API key, open a terminal in your project folder and type codex followed by what you want done, such as "fix the failing test." It reads your files, proposes changes and commands, and by default waits for your yes before it writes anything or runs anything.
Follow-up question How do its approval modes work?
Codex CLI is a free, open-source program from OpenAI that brings a coding assistant into your terminal, the text window where developers type commands. Unlike a chat window, it works directly on the files in your project: it can read them, propose edits, and run commands such as your tests. OpenAI released it on April 16, 2025, alongside its o3 and o4-mini models.
The name can be confusing. OpenAI had a model called Codex in 2021, which was retired in March 2023. The CLI is a separate, new tool; by default it uses o4-mini, and you can choose another model.
Before you start
You need:
- Node.js 22 or newer. Node is the program that runs JavaScript tools like this one.
- macOS 12 or later, or Linux (Ubuntu 20.04+ or Debian 10+). On Windows 11 it runs inside WSL2, Microsoft's built-in Linux environment.
- An OpenAI API key. Codex sends every request to OpenAI's models with it, so the usage appears on your API account.
- Git, recommended. Git keeps a history of your files, so you can undo anything Codex changes.
Worked example: fixing a bug
Install the tool once, then give it your key for this terminal session:
npm install -g @openai/codex
export OPENAI_API_KEY="your-key-here"
The README warns against sudo npm install -g; if npm refuses to install globally, fix npm's folder permissions instead. To keep the key across sessions, add the export line to your shell's settings file, such as ~/.zshrc.
Now imagine a small Python project with a prices.py file and a test that fails because a discount is applied twice. Go to the project folder and commit your current state first, so there is a clean point to return to:
cd ~/projects/shop
git add -A && git commit -m "Before Codex"
codex "The test in tests/test_prices.py fails. Find the cause, fix it, and run the tests."
Codex starts in Suggest mode, the default. It reads the files it needs and explains what it found. When it wants to change a file, it shows the proposed edit as a diff (the lines to remove and the lines to add) and asks for approval. When it wants to run a command such as pytest, it asks again. Type y to allow a step or n to refuse it; refusing leaves your files untouched.
For this kind of bug, a typical session looks like this (illustrative): Codex reads prices.py and the test, points out that apply_discount is called both in subtotal() and in total(), proposes deleting one call, then asks to run the tests and reports that they pass.
Check the result yourself before you move on:
git diff
pytest
git diff shows exactly what changed since your commit. If you dislike it, git checkout . puts the files back.
Once you trust the pattern, try Auto Edit, which lets Codex edit files without asking but still asks before running any command:
codex --approval-mode auto-edit "Add a test for a 0% discount and make sure it passes."
A few other tips from the README: running codex alone opens an interactive session, codex -q "..." runs once without the interactive screen, and -m picks a different model. You can also put standing instructions for a project, such as "use pytest, not unittest," in a codex.md file at the root of the repository, and personal ones in ~/.codex/instructions.md.
Try it: In a small project you know well, create one deliberate bug, commit, and ask Codex in Suggest mode to find and fix it. Refuse its first proposed edit with n and see how it responds, then accept the next one and review it with git diff.
How do its approval modes work?
The approval mode decides how much Codex may do without asking you. You set it with --approval-mode (or -a), or choose it when Codex first starts.
| Mode | Does without asking | Still asks before |
|---|---|---|
| Suggest (default) | Reads files in the project | Every file edit and every command |
| Auto Edit | Reads and edits files | Every command |
| Full Auto | Reads, edits and runs commands | Nothing |
Full Auto is the one to handle carefully. To limit the risk, Codex runs commands in that mode with network access turned off and confined to your current folder. On macOS it uses Apple's built-in sandbox, which makes almost everything outside the project read-only and blocks outbound connections. On Linux, the project recommends running Codex inside a Docker container, an isolated mini-system with a firewall. If you start Auto Edit or Full Auto in a folder that Git is not tracking, Codex warns you and asks for confirmation, because without Git there is no easy undo.
A sensible progression is to stay in Suggest mode until you understand how Codex works in your project, move to Auto Edit for routine changes you will review with git diff, and keep Full Auto for throwaway experiments in a separate folder. Whatever the mode, read the changes before you commit them: as TechCrunch notes, studies have found that code-writing models can miss security problems and sometimes introduce new bugs.
Sources
- OpenAI Codex CLI (README) — OpenAI on GitHub, April 16, 2025
- OpenAI debuts Codex CLI, an open source coding tool for terminals — TechCrunch, April 16, 2025