CDX-101 · Module 1
Getting Started
4 min read
OpenAI Codex CLI is an open-source, terminal-native coding agent that connects to OpenAI models (GPT-4.1, o3, o4-mini, and the specialized Codex-series models). Unlike cloud-only tools, Codex runs locally on your machine and operates directly on your filesystem — reading, writing, and executing code in a sandboxed environment.
Installation is straightforward via npm. You need Node.js 22 or later. Once installed, you authenticate either through ChatGPT OAuth (browser-based) or by setting an API key.
# Install globally via npm
npm install -g @openai/codex
# Or install via Homebrew on macOS
brew install openai-codex
# Authenticate with ChatGPT (opens browser)
codex --login
# Or set your API key directly
export OPENAI_API_KEY="sk-..."
Codex lives across multiple surfaces — not just the terminal. You can use the CLI directly, the VS Code / Cursor extension, the Codex web app (codex.openai.com), or even the iOS mobile app. All surfaces share the same AGENTS.md configuration and model access, but differ in their interaction model. The CLI gives you the most control. The web app and mobile app let you delegate tasks to cloud sandboxes and review results asynchronously.
Do This
- Use the CLI for interactive local development where you want full control
- Use Codex Cloud (web/mobile) for tasks you want to delegate and review later
- Use the IDE extension when you prefer staying inside VS Code or Cursor
Avoid This
- Run the CLI on a remote server without understanding sandbox limitations
- Mix surfaces mid-task — pick one surface per task for cleaner context
- Forget to authenticate — Codex will silently fail on API calls
After installation, navigate to your project root and run codex to start an interactive session. Codex will look for AGENTS.md files, load your project context, and present a terminal UI where you can type natural-language prompts. Your first session should be creating an AGENTS.md file — but we will cover that in depth in Lesson 6.
# Start an interactive session in your project
cd ~/my-project
codex
# Or pass a prompt directly for one-shot execution
codex "add input validation to the signup form"