Codex Setup
What is Codex?
Section titled “What is Codex?”Codex is an AI coding assistant from OpenAI. It runs in your terminal and uses natural language prompts to read, write, and modify files on your machine. It is powered by OpenAI’s models and integrates with your local development environment.
Before You Start
Section titled “Before You Start”All the steps below happen inside a terminal. If you have never used a terminal before, follow the Using the Terminal guide first, then come back here.
Step 1: Install Node.js
Section titled “Step 1: Install Node.js”Codex requires Node.js 22 or later. You may already have it installed. Open your terminal and run:
node --versionIf you see a version number like v22.x.x or higher, skip ahead to Step 2. If you see “command not found” or a version below 22, follow the instructions below.
Install Node.js
Visit nodejs.org and download the LTS installer for macOS. Run the .pkg file and follow the prompts.
Alternatively, if you have Homebrew installed:
brew install nodeVisit nodejs.org and download the LTS installer for Windows. Run the .msi file and follow the prompts. Make sure “Add to PATH” is ticked during installation.
After installing, verify by running:
node --versionYou should see a version number like v22.x.x or higher.
Step 2: Get an OpenAI API Key
Section titled “Step 2: Get an OpenAI API Key”- Visit platform.openai.com and sign in or create an account.
- Navigate to API Keys in the dashboard.
- Click Create new secret key and copy the key.
Set the API key in your terminal:
Set API Key
export OPENAI_API_KEY="your-api-key-here"To make this permanent, add the line above to your ~/.zshrc or ~/.bashrc file.
set OPENAI_API_KEY=your-api-key-hereTo make this permanent, add it as a system environment variable via System Properties > Environment Variables.
Step 3: Install Codex
Section titled “Step 3: Install Codex”Open your terminal and run:
npm install -g @openai/codexVerify the installation:
codex --versionStep 4: Basic Usage
Section titled “Step 4: Basic Usage”Navigate to your project folder and start Codex:
cd ~/my-projectcodexYou are now in an interactive session. Try your first prompt:
Here's what I found in this directory: 1. meeting-notes.docx: A Word document containing meeting notes 2. budget.xlsx: A spreadsheet with budget figures 3. photos/: A folder containing image files The directory has 2 files and 1 folder.
LLM outputs are non-deterministic and may vary from this example.
Codex will read your files and respond directly in the terminal.
Useful Commands
Section titled “Useful Commands”| Command | Description |
|---|---|
codex | Start an interactive session in the current directory |
codex "your prompt" | Run a single prompt without entering interactive mode |
codex --help | Show all available options |
Ctrl+C | Cancel the current response |
Ctrl+D | Exit the interactive session |
Next Steps
Section titled “Next Steps”Return to the Prerequisites page and continue with the guides. When you see an LLM Prompt Box, copy the prompt and paste it into your Codex session.