Codex CLI: install and first task, step by step
The short answer. Getting Codex CLI running takes three actions: install it (one shell line, or npm install -g @openai/codex, or Homebrew), run codex inside a project folder and choose "Sign in with ChatGPT" (or an API key). The rest is discipline: start from a clean Git repository with a fresh commit, write a small task with a verifiable definition of done, read the diff and run the tests yourself. The result is an agent that proposes real changes that you can always undo. The cost of this approach is time: it is slower than "do it all yourself", and it only pays when the task is small enough to verify in a few minutes. This is part 2 of the OpenAI Codex series.
Method note. The commands come from the CLI documentation and the repository README, consulted on 30 October 2026. I did not run them in this session: take them as the path indicated by the vendor, not as an account of my machine. I am not affiliated with OpenAI.
Before installing: two decisions
How you authenticate. With a ChatGPT account (Plus, Pro, Business, Edu, Enterprise plans) or with an API key. Part 1 has the comparison; here it is enough to remember that ChatGPT sign-in gives you quotas in five-hour windows plus the cloud features, while an API key bills per use and does not include the cloud.
On which system. macOS uses the built-in sandbox (Seatbelt) with nothing else to do. On Linux and WSL2 the sandbox documentation requires bubblewrap (bwrap): Codex uses the first bwrap on the PATH or, failing that, a bundled helper that needs unprivileged user namespace support. On Windows, from PowerShell it uses a native sandbox; from WSL2, the Linux one. If the sandbox does not start, the most likely symptom is an error when commands launch, not a block in your editor: part 3 explains how to read it.
Installation
The four routes documented in the README, all for the same CLI (Apache-2.0 licence):
# macOS / Linux
curl -fsSL https://chatgpt.com/codex/install.sh | sh
# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
# npm
npm install -g @openai/codex
# Homebrew
brew install --cask codex
The standalone installers download from releases.openai.com and, if it does not answer, from GitHub Releases; setting CODEX_INSTALLER_USE_RELEASES_OPENAI_COM=false forces GitHub. To update, the CLI page says to re-run the same install command.
The trade-off between routes is simple but matters in a team. The curl | sh script is the quickest but runs downloaded code: in a regulated environment, download the script first and read it, or use a package from a manager your security group already vets. npm needs Node but fits your version tooling; Homebrew is the cleanest choice on macOS. Whichever you pick, note the version: the repository published 0.166.0 on 29 October 2026, with almost daily releases, and two colleagues on different versions may see different commands.
First launch
The documentation describes the first run like this: open a project folder, run codex, choose "Sign in with ChatGPT" or another available method. If you use an API key, configuration takes one more step than a login; for non-interactive and CI use the detail is in part 6.
cd ~/projects/my-service
git status # must be clean
git log -1 --oneline
codex
The git status check is not a formality: the documentation itself suggests creating Git checkpoints before and after a task so you can go back. With an already dirty working tree you can no longer tell what the agent changed from what you changed.
The five commands to know at once
The CLI page lists these as the first commands to try inside the interactive session:
/init: creates anAGENTS.mdfile with instructions for Codex. It is the first genuinely useful step; part 4 explains how to write it well./status: shows the current session configuration (model, permissions, folder)./permissions: sets what Codex may do without asking./model: chooses the model and reasoning level./review: reviews the changes and looks for problems.
Train your hand to type /status before every task that matters: it tells you which permissions you are working with. Many incidents with this kind of tool start from a broad permission set for one activity and forgotten for the next.
The first task: small, verifiable, reversible
The classic first-day mistake is to ask "improve this project". An agent can execute, but it cannot guess your success criterion. A prompt that works has four parts: the goal, the context (which files), the constraints (what not to touch) and the definition of done (which command must pass). A realistic example, to adapt to your stack:
Add a unit test for the function calcDiscount in src/prices.ts.
Cover: zero amount, negative amount (must throw an error), 100% discount.
Do not modify src/prices.ts. Follow the style of the tests in src/prices.spec.ts.
You are done when "npm test -- prices" passes.
Then a sequence follows that is worth governing:
- Read the plan or the first actions. If Codex proposes touching unrelated files, interrupt and narrow the prompt.
- Approve commands carefully. With default settings the agent asks permission when it leaves the sandbox boundary; reading what it asks is your last check.
- Read the diff with
git diff. Do not trust the summary the agent writes: the summary describes intentions, the diff describes facts. - Run the tests yourself. "It said they pass" is not verification. Run the definition-of-done command with your own hands.
- Use
/reviewas a second pair of eyes. The CLI page says it can check changes against a base branch (PR style), uncommitted changes, a specific commit or custom review instructions, and that it reports prioritised findings without modifying the working tree. - Commit only what you understood. A separate commit for the agent's changes makes rollback one line:
git revert.
The command-line features that change how you work
Beyond the interactive session, the same page documents:
codex resume: reopens a recent chat from the current repository, or searches older local ones. Useful to resume an interrupted task without re-explaining everything.codex --image: attaches an image (a screenshot, a diagram) to the first prompt; alternatively you can paste it into the composer.codex --search: enables live web search for tasks that need current information; the search activity shows in the transcript.codex cloud: browses and submits work to Codex Cloud, then applies the results to your local repository (part 7).codex mcp: adds local or remote MCP servers and inspects their tools.codex exec: non-interactive execution for scripts and CI (part 6).
A cost-benefit example: --search is useful when the task depends on a library released after the model's training period, but every page the agent reads is external content entering its context. If you do not need it, leave it off: less surface, less noise.
When something goes wrong
- The login does not complete. Check that your ChatGPT plan includes Codex on the surface you chose; in the Pricing table the Free and Go plans mention only the desktop app.
- The sandbox does not start on Linux. Check that
bwrapis installed and that unprivileged user namespaces are enabled in your kernel or container. - Commands keep asking for approval. That is the cautious behaviour. Do not fix it by raising permissions at random: part 3 shows how to widen only what you need.
- Behaviour does not match a guide. Check the version with your package manager and compare with the releases: with an almost daily release cadence, a three-month-old guide may describe changed commands. The
codex doctorcommand appears in recent release notes (ascodex doctor --network-only) and is worth trying for network problems.
What not to do on day one
Do not launch it at the root of a production repository with full permissions. Do not paste secrets or database dumps into the prompt "to give context". Do not ask for cross-cutting refactors: those are the tasks where the agent produces a lot of diff and you understand little of it. Start from tests, small functions, the fix of a reproducible bug. When you trust the flow, widen.
Sources (consulted 30 October 2026)
- Codex CLI, documentation (slash commands,
resume,--image,--search,/review). - openai/codex README (installation, licence, authentication).
- Sandboxing (requirements per operating system).
- Releases (0.166.0 of 29 October 2026).
Commenti
Caricamento commenti...
Sign in to comment