How to install the Codex CLI and run your first task
OpenAI describes it this way: "Codex CLI is a coding agent from OpenAI that runs locally on your computer." (checked Oct 2026) This guide covers installing it, signing in, choosing how much it's allowed to do, and giving it a first small task. Everything here is quoted from OpenAI's Codex GitHub README, the CLI quickstart, and the sign-in, security and Windows pages, checked Oct 2026.
Not affiliated with or endorsed by OpenAI. Check OpenAI's current docs before relying on these details.
Our tool page: OpenAI Codex
What you need first
The repo's install notes list "macOS 12+, Ubuntu 20.04+/Debian 10+, or Windows 11 via WSL2" (checked Oct 2026), "4-GB minimum (8-GB recommended)" (checked Oct 2026) of RAM, and Git "2.23+ for built-in PR helpers" (checked Oct 2026) (optional but recommended).
A note on Windows: those same install notes say WSL2, but the README and OpenAI's Windows page now also offer a native Windows installer: "Use Codex on Windows with the native ChatGPT desktop app, the CLI, or the IDE extension." (checked Oct 2026) If you're on Windows, read that page first to choose.
You also need a way to sign in, either a ChatGPT plan or an API key (see Step 3). For prices, see Codex pricing (checked Oct 2026).
Step 1: Install
macOS 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"
These commands download a script and run it right away, and the Windows one also bypasses PowerShell's script policy for that one run. Our advice, not a vendor quote: if you want to see what it does first, open the script's address in your browser and read it before you run the command.
Or use a package manager. The README says "Codex CLI can also be installed via the following package managers" (checked Oct 2026):
npm install -g @openai/codex
brew install --cask codex
You can also download a ready-made binary from the latest GitHub release. The README notes "you likely want to rename it to codex after extracting it." (checked Oct 2026)
Step 2: Updating and removing it
If you used the curl installer, OpenAI's quickstart says to update by running the same command again:
curl -fsSL https://chatgpt.com/codex/install.sh | sh
OpenAI's docs don't give update or uninstall steps for npm or Homebrew. Our advice, not a vendor quote: check those tools' own docs. If you remove it, know that your sign-in and settings live in the ~/.codex folder.
Step 3: Sign in
Go to your project folder and start Codex:
cd /path/to/your/project
codex
The README says: "Run codex and select Sign in with ChatGPT. We recommend signing into your ChatGPT account to use Codex as part of your Plus, Pro, Business, Edu, or Enterprise plan." (checked Oct 2026) You can also run codex login and, per OpenAI's auth docs, "complete the browser flow." (checked Oct 2026)
To use an API key instead, which is "usage-based access" (checked Oct 2026), the sign-in page gives:
printenv OPENAI_API_KEY | codex login --with-api-key
Keep your sign-in file private. OpenAI warns: "treat ~/.codex/auth.json like a password: it contains access tokens. Don't commit it, paste it into tickets, or share it in chat." (checked Oct 2026) For more on this, see our keeping secrets safe with AI coding tools guide.
Step 4: Choose how much it can do
OpenAI's security page says "By default, the agent runs with network access turned off" (checked Oct 2026), and Codex uses "an OS-enforced sandbox that limits what it can touch (typically to the current workspace), plus an approval policy that controls when it must stop and ask you before acting." (checked Oct 2026)
For a first look where it can't change anything, the docs give:
codex --sandbox read-only --ask-for-approval on-request
In the "Auto preset" (--sandbox workspace-write --ask-for-approval on-request), "Codex can read files, make edits, and run commands in the working directory automatically" (checked Oct 2026), and it asks before editing outside the workspace or using the network.
There's also a full-access mode. The docs say "Use caution before doing so." (checked Oct 2026) Our advice, not a vendor quote: don't use it while you're learning.
Step 5: Your first task
Our advice, not a vendor quote: tell Codex in plain words what you want done, one small task at a time. OpenAI's CLI docs suggest you "ask Codex to explain the project, make a focused change, or help debug an issue." (checked Oct 2026) Here is OpenAI's example prompt (we haven't tried it ourselves):
Tell me about this project
Our advice, not a vendor quote: try one small, focused change and read what it did before you keep it. OpenAI's own tip: "Create Git checkpoints before and after a task so you can revert changes." (checked Oct 2026)
Next steps
- Give it project instructions: AGENTS.md and CLAUDE.md guide
- Connect outside tools: MCP setup guide
- Keep secrets out of its reach: keeping secrets safe with AI coding tools
- Run checks automatically in Claude Code: Claude Code hooks guide
- Trying Claude Code too? How to install Claude Code
Not affiliated with or endorsed by OpenAI. Check OpenAI's current docs before relying on these details.