Codex CLI

Free (open source), requires API key1 min read

Step 1: Install with npm

Run npm install -g @openai/codex in your terminal. Requires Node.js 22 or newer.

Step 2: Set your API key

Export your OpenAI API key as an environment variable: OPENAI_API_KEY

Step 3: Choose autonomy mode

Select suggest (safest), auto-edit (balanced), or full-auto (most autonomous) based on your comfort level

Step 4: Start coding

Run codex in your project directory for interactive use, or pass a prompt directly for one-shot tasks

FeatureCodex in ChatGPTCodex CLI
Runs whereRuns whereCloud sandboxYour local machine
Setup requiredSetup requiredNone (browser based)npm install + API key
Accesses local filesAccesses local filesNo (cloud only)
Accesses local toolsAccesses local tools
Internet during executionInternet during executionNo (sandboxed)
AI providersAI providersOpenAI onlyMultiple (OpenAI, local models, etc.)
Delivers results asDelivers results asGitHub pull requestDirect file changes
CostCostChatGPT subscriptionAPI usage (pay per token)
Open sourceOpen source

When to use CLI vs. ChatGPT

Use Codex CLI when you need local file access, want to work with multiple AI providers, or prefer a terminal workflow. Use Codex in ChatGPT when you want zero setup, cloud isolation, and automatic PR creation. Many developers use both: ChatGPT Codex for larger tasks that benefit from sandboxing, and the CLI for quick local tasks where speed matters.