Codex CLI from zero: install, sign in, /init and your first task

Build Guides

Codex CLI from zero: install, sign in, /init and your first task

Close-up of rows of round black typewriter keys in low blue light
Photo by Alexandre Boucher on Pexels

A beginner's walkthrough of OpenAI's Codex CLI: install on Mac, Linux or Windows, sign in with your ChatGPT plan, generate an AGENTS.md with /init, and run your first task safely.

In this article
  1. 1. Install it
  2. 2. Sign in
  3. 3. Open a project and run /init
  4. 4. Check the model and permissions
  5. 5. Your first task
  6. 6. Commands worth learning next
  7. Common beginner mistakes
  8. Codex CLI vs the alternatives

Codex and Claude Code are the two coding agents people compare most on X. Our sample had about 16,600 posts mentioning both. If you've only used Codex in the browser, the CLI is worth ten minutes. It runs on your own machine, inside your real project.

This guide gets you from nothing to a first safe task.

1. Install it

From the official README:

Mac or Linux

curl -fsSL https://chatgpt.com/codex/install.sh | sh

Windows (PowerShell)

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

Package managers

npm install -g @openai/codex
# or
brew install --cask codex

Piping a script into your shell runs code from the internet. That's standard for CLI installers, but only do it from the official URL. If you'd rather read before running, use npm or Homebrew, or download a binary from GitHub Releases.

2. Sign in

Run:

codex

Choose Sign in with ChatGPT. OpenAI recommends this so Codex usage comes out of your Plus, Pro, Business, Edu or Enterprise plan.

You can use an API key instead, but the README says it "requires additional setup". With a key you also pay per token, so set a spend limit at the provider first. The OpenCode Console breach is a good reminder of why.

3. Open a project and run /init

cd into a project. Ideally it's a git repo with a clean working tree, so every change is easy to see and undo. New to git? Start with Git and GitHub basics.

Inside Codex, type:

/init

Codex reads your project and writes an AGENTS.md file: instructions it loads at the start of every session. Open the file and fix it. Add your real test command, your package manager, and anything it must never touch. Our AGENTS.md guide and starter template show what good looks like.

4. Check the model and permissions

Before your first real task, run:

Command What it shows or does
/status The current session: model, approvals, workspace
/permissions What Codex may do without asking you
/model Switch models

Keep approvals strict at first. Let Codex read freely, but have it ask before editing files or running commands. Loosen up once you trust it. Our guide to running coding agents safely explains the trade-offs.

5. Your first task

Start small and checkable:

Add a unit test for the formatPrice function in src/utils.ts.
Run the existing test command and show me the result.

Good first tasks have a clear finish line, like a passing test or a lint error fixed. Avoid "refactor the whole app" on day one.

When it's done, review the diff yourself:

git diff

6. Commands worth learning next

Command Use it for
/review Have Codex review your changes
codex exec "…" Run a task non-interactively, e.g. from a script
codex resume Pick up a previous session
codex --image screenshot.png Attach an image, like a UI bug
codex --search Allow web search for the session
codex mcp Manage MCP servers (tools Codex can call)
codex app Open the Codex desktop app

For MCP setup, see how to add an MCP server to Codex, Cursor and Claude Code.

Common beginner mistakes

  • Running it outside git. If you can't diff it, you can't review it.
  • Approving everything. Read the command before you say yes, especially anything that deletes, installs or pushes.
  • Never editing AGENTS.md. The /init draft is a starting point, not a finished file.
  • Skipping review. Agent code still needs a human pass. Our checklist for reviewing AI-written code takes five minutes.

Codex CLI vs the alternatives

Codex CLI is open source (Apache-2.0), runs locally, and uses your ChatGPT plan. If you're choosing between agents, our Cursor vs Claude Code vs Codex comparison breaks down the differences. If you want to drive several agents from one window, look at T3 Code.

FAQ

Is Codex CLI free?

The CLI itself is open source under Apache-2.0. Model usage comes from your ChatGPT plan when you sign in with ChatGPT (Plus, Pro, Business, Edu or Enterprise), or from your API billing if you use an API key.

Does Codex CLI work on Windows?

Yes. The README gives a PowerShell installer: powershell -ExecutionPolicy ByPass -c \"irm https://chatgpt.com/codex/install.ps1 | iex\".

What does /init do in Codex?

It has Codex look at your project and write an AGENTS.md file: the instructions Codex reads at the start of every session. Edit it by hand afterwards so it matches how you actually work.

What's the difference between Codex CLI, the Codex app and Codex Web?

The CLI runs in your terminal on your machine. `codex app` opens the desktop app. Codex Web, at chatgpt.com/codex, is OpenAI's cloud-based agent.

Sources

  1. openai/codex README (GitHub)https://github.com/openai/codex
  2. OpenAI, Codex CLI documentationhttps://learn.chatgpt.com/docs/codex/cli
Matching resources

Matching resources

Newsletter

The Codema publication. Consent is required. You are not subscribed until you confirm from the email, and nothing is stored if email delivery is not connected.