Codex CLI Beginner's Guide: From Installation to Your First AI Coding Task
What This Tutorial Teaches
Codex CLI is OpenAI's coding agent that runs in your terminal. It can inspect your project, edit files, run commands, and automate repeatable work — all from a command line. By the end of this tutorial, you will be able to install Codex CLI, sign in, and complete your first AI-assisted coding task.
Time needed: 15–20 minutes
Difficulty: Beginner
Before You Start
| Requirement | Details |
|---|---|
| Operating system | Windows 10 or later, macOS, or Linux |
| Account | A ChatGPT account (subscription) or an OpenAI API key (pay-as-you-go) |
| Node.js | Only needed for the npm install method (version 18 or later) |
| Terminal | PowerShell (Windows), Terminal (macOS), or your Linux terminal |
| Cost | ChatGPT subscription, or pay per API usage |
What is a terminal? A terminal (also called command line) is a window where you type commands instead of clicking buttons. On Windows it is called PowerShell; on macOS it is called Terminal. This tutorial uses codex commands, which you type into this window and press Enter.
What is Node.js? Node.js is a free program that lets you install tools with the npm command. You only need it if you choose the npm install method below. If you do not have it, install it from nodejs.org (choose the LTS version).
What is an API key? An API key is a secret code that identifies your account when paying per use. You generate it once at platform.openai.com → API keys. Treat it like a password — never share it.
How to Open Your Terminal (Step by Step)
If you are not sure how to open a terminal, follow the steps for your system below. You will use it for every command in this tutorial.
Windows — open PowerShell
- 1Click the Start button (the Windows logo) at the bottom-left corner of your screen.
- 2Type
PowerShell— you do not need to click anything first, just start typing. - 3Click the Windows PowerShell or Terminal app that appears in the list.
- Windows 11 shows Terminal; Windows 10 shows Windows PowerShell. Either one works.
- 1If a blue User Account Control window pops up, click Yes.
How to paste a command: right-click anywhere inside the PowerShell window to paste (or press Ctrl + V).
Download and Install
Choose Your Version
| Version | Best for | Notes |
|---|---|---|
| Stable (official installer) | Most users | Fully tested, recommended |
| npm package | Users who already have Node.js | Easy to update |
| Homebrew (macOS) | macOS users who use Homebrew | Manage alongside other apps |
What is Homebrew? Homebrew is a free package manager for macOS. You type brew install to install programs, just like an app store for the command line. Only choose this option if you already use Homebrew.
Install for Your System
Select your system below. Each tab contains the complete steps for that operating system.
Windows installation
- 1Open PowerShell: click the Start button (Windows logo), type
PowerShell, then click Windows PowerShell or Terminal. - 2Copy the command below, paste it into the PowerShell window, and press Enter:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"- 1Wait for the installation to finish. When you can type again, verify the installation by copying and running this command:
codex --versionIf you see a version number (for example v1.x.x), the installation succeeded.
Update Codex (copy and run this command whenever you want the latest version):
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"Sign In
- 1Open a terminal and go to a project folder (replace
path/to/your/projectwith your own folder path):
cd path/to/your/project- 1Start Codex:
codex- 1The first time, choose a sign-in method:
- Sign in with ChatGPT — use your ChatGPT account (subscription). A browser window opens; after you sign in, the browser returns your credentials to Codex automatically.
- Use an API key — paste the key you generated at platform.openai.com when asked.
- 1After signing in, you will see the Codex prompt, ready for your first task.
Installation Troubleshooting
| Error | Cause | Fix |
|---|---|---|
codex: command not found | The install folder is not in your PATH | See the step-by-step fix below for your system |
npm: command not found | Node.js is not installed | Install Node.js from nodejs.org (LTS version), close and reopen the terminal, then retry the npm install |
| Sign-in page does not open | Network restrictions or proxy | Check your internet connection, make sure chatgpt.com is accessible, and try again. If you use a VPN or proxy, try turning it off or switching servers |
codex: Permission denied (macOS/Linux) | The script cannot write to the install folder | Open Terminal, run this once, then re-run the install command: chmod +x ~/.local/bin/codex |
Fix for "codex: command not found" — Windows:
- 1Press the Windows key, type
environment variables, and click Edit the system environment variables. - 2Click the Environment Variables... button.
- 3In the lower list (System variables), find Path, select it, and click Edit....
- 4Click New, add the folder where Codex was installed (default:
C:\Users\<your username>\.local\bin), and click OK on every window. - 5Close PowerShell completely and open it again, then run
codex --version.
Fix for "codex: command not found" — macOS/Linux:
- 1Open Terminal and copy-run this command:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc- 1Reload the settings:
source ~/.zshrc- 1If you use Bash instead of Zsh, use
~/.bashrcin both commands above. - 2Run
codex --versionto confirm.
Your First Task
Step 1: Open a project
Go to the project folder you want Codex to work on (replace the path with yours):
cd path/to/your/projectStep 2: Start Codex
codexStep 3: Ask your first question
Type this request and press Enter:
Tell me about this projectCodex reads the project files and explains what it finds. Try a few more:
Explain the main function in this file— explains the main function of this fileFind the bug in this code— looks for bugs in this codeAdd a comment header to every file— adds a comment header to every file
Step 4: Approve what Codex wants to do
When Codex wants to edit files or run commands, it asks for your permission first. This is normal. Type y and press Enter to approve, or n to reject. Review each change — you stay in control of what happens on your machine.
Step 5: Exit Codex
When you are done, type /exit and press Enter, or press Ctrl + C twice.
Useful Commands
| Command | What it does |
|---|---|
codex | Start an interactive session |
codex exec "task description" | Run a task without interactive mode (good for scripts and CI) |
codex resume | Reopen a recent chat session |
codex --image <file> | Include a screenshot or diagram with your prompt |
codex --search | Enable live web search for the current task |
codex mcp | Connect external tools through MCP servers |
codex completion | Generate shell completions for your terminal |
/permissions | Change what Codex may do without asking (inside a session) |
/exit | Exit Codex |
Frequently Asked Questions
Do I need a paid plan?
You need either a ChatGPT subscription or an OpenAI API key. The free ChatGPT plan does not include Codex CLI access. Check the official pricing page for current options.
Does Codex work outside a git repository?
Codex works best inside a git project. If you are starting from scratch, create a repository first:
git initCan Codex run my code?
Yes, with your permission. Codex can run shell commands and tests on your machine, and it always shows you what it runs before asking. Use the permission settings to control what it can do without asking.
Is my code sent to OpenAI?
When you use Codex with OpenAI models, your prompts and file contents are processed by OpenAI according to the data controls of your account type (subscription or API organization settings). Review the official data controls documentation for details.
What's Next
- Add project guidance: Create an
AGENTS.mdfile in your repository to give Codex durable instructions about your project. - Automate with scripts: Use
codex execin CI pipelines and repeatable workflows. - Connect tools with MCP: Use
codex mcpto give Codex access to external data and services. - Try Codex cloud: Hand long-running work to the cloud and return to the terminal later.