BuildBotsBetter
CX

Install ChatGPT Codex CLI

End-to-End Terminal Setup, OpenAI Auth & Sandbox Automation

Progress
0%

Select Your Operating System

Commands and environment variables update instantly to match your target shell.

Step 1 of 6 Est: 2 minutes

Verify Node.js Runtime & Package Manager

ChatGPT Codex CLI runs on Node.js and requires version 18.0.0 or later (v20 LTS recommended).

Check Installed Node Version

Open your terminal and verify whether Node.js and npm are present and meet the minimum runtime requirements:

PowerShell
PS > node -v; npm -v
zsh
$ node -v && npm -v
bash
$ node -v && npm -v
💡
Missing or outdated Node.js? Install or switch version via nvm install 20 (macOS/Linux) or download the Windows LTS installer from nodejs.org.
Checkpoint 1
Required

Paste the exact output of your node -v command below to verify runtime version compliance:

Step 2 of 6 Est: 3 minutes

Install OpenAI ChatGPT Codex CLI Globally

Install the official Codex command-line interface package and ensure its binary is discoverable in your system path.

Install Global CLI Package

Install the package globally via npm. If you encounter permission errors on Unix, configure your user npm prefix or use nvm.

PowerShell
PS > npm install -g @openai/codex PS > codex --version
zsh
$ npm install -g @openai/codex $ codex --version
bash
$ npm install -g @openai/codex $ codex --version
⚠️
Command not found? If terminal reports codex: command not found, verify that the npm global binary folder is added to your PATH environment variable, then restart your terminal.
Checkpoint 2
Required

Paste the output of codex --version to verify binary installation:

Step 3 of 6 Est: 3 minutes

Configure OpenAI API Authentication

Codex CLI requires an active OpenAI API secret key stored in your shell environment variables.

Set Persistent OPENAI_API_KEY

Generate an API key at platform.openai.com/api-keys and configure it as an environment variable in your profile:

PowerShell
# Set persistent user variable and current session variable PS > [System.Environment]::SetEnvironmentVariable('OPENAI_API_KEY', 'sk-your-key-here', 'User') PS > $env:OPENAI_API_KEY = 'sk-your-key-here' PS > python -c "import os; print('Key set:', bool(os.environ.get('OPENAI_API_KEY')))"
zsh
# Append to ~/.zshrc and export for current session $ echo 'export OPENAI_API_KEY="sk-your-key-here"' >> ~/.zshrc $ export OPENAI_API_KEY="sk-your-key-here" $ test -n "$OPENAI_API_KEY" && echo "Key configured successfully"
bash
# Append to ~/.bashrc and export for current session $ echo 'export OPENAI_API_KEY="sk-your-key-here"' >> ~/.bashrc $ export OPENAI_API_KEY="sk-your-key-here" $ test -n "$OPENAI_API_KEY" && echo "Key configured successfully"
💡
Security Rule: Never commit API keys to version control repositories. Store keys strictly in environment variables or a local untracked .env file.
Checkpoint 3
Required

Paste your API key prefix (e.g. sk-proj-...) or the confirmation text showing key is active:

Step 4 of 6 Est: 3 minutes

Interactive REPL & Sandbox Execution Modes

Launch an interactive pair-programming session and configure workspace sandbox permissions.

Start Codex with Sandbox Protection

Launch Codex in workspace-write mode to restrict file system modifications strictly inside your working project directory:

PowerShell
# Start interactive session with workspace-write sandbox PS > codex --sandbox workspace-write
zsh
# Start interactive session with workspace-write sandbox $ codex --sandbox workspace-write
bash
# Start interactive session with workspace-write sandbox $ codex --sandbox workspace-write
💡
REPL Slash Commands: Inside the interactive session, type /help for available commands, /model gpt-4o to switch active model, and /exit to return to your normal terminal shell.
Checkpoint 4
Required

Paste the interactive banner or sandbox mode confirmation text from your terminal:

Step 5 of 6 Est: 3 minutes

Non-Interactive Execution & STDIN Piping

Execute single-shot queries and pipe files or terminal outputs into Codex for automated code reviews and CI scripting.

Execute Single Prompt & Pipe File Content

Run single-shot commands using codex exec, or pipe file contents directly into the LLM context:

PowerShell
# Single-shot command execution PS > codex exec "Explain the key differences between gpt-4o and gpt-4o-mini in 2 sentences" # STDIN piping in PowerShell PS > Get-Content package.json | codex exec "Summarize top 3 dependencies and their purpose"
zsh
# Single-shot command execution $ codex exec "Explain the key differences between gpt-4o and gpt-4o-mini in 2 sentences" # STDIN piping in zsh $ cat package.json | codex exec "Summarize top 3 dependencies and their purpose"
bash
# Single-shot command execution $ codex exec "Explain the key differences between gpt-4o and gpt-4o-mini in 2 sentences" # STDIN piping in bash $ cat package.json | codex exec "Summarize top 3 dependencies and their purpose"
Checkpoint 5
Required

Paste the response generated by your codex exec command:

Step 6 of 6 Est: 2 minutes

Default Preferences & Run It Later Card

Lock in persistent model defaults and save the quick reference card for daily terminal development.

Set Default Model Configuration

Configure your preferred default model and view persistent settings:

PowerShell
PS > codex config set model gpt-4o PS > codex config list
zsh
$ codex config set model gpt-4o $ codex config list
bash
$ codex config set model gpt-4o $ codex config list
Checkpoint 6
Required

Paste the output of codex config list showing your saved preferences:

⚡ Run It Later — Quick Reference

Interactive Session codex Launches full interactive pair programming terminal agent
Safe Sandbox Mode codex --sandbox workspace-write Restricts file modifications strictly inside workspace directory
One-Shot Command codex exec "Review git diff" Executes non-interactive prompt and prints output to stdout
Pipe File Analysis cat file.py | codex exec "Add types" Pipes standard input stream directly into Codex context
Lesson 7 of 7 Fleet Safety Standard

Build Bot Better & Wipe Resistance

Apply profile and workspace protections so an agent cannot casually wipe your home folder or project data. Fleet rule: Hub conversation #31.

⚠️ The 2026-09-23 Profile Wipe Lesson

An autonomous agent running without boundary constraints executed a recursive delete targeting the user profile. Prompt rules and command-text deny lists (like rm or Remove-Item) fail when paths are passed inside variables or child scripts. BuildBotsBetter requires the complete defense trio: PreToolUse path inspection, off-volume backups, and a practised restore.

1. Per-Agent Onboarding Checklist (Run Once Per Agent)

Onboarding does not end when software installs. Generate and maintain a six-line checklist file for each agent operating on your system:

PowerShell
$check = Join-Path $env:TEMP "bbb-onboarding-checklist.txt"; @("agent:","rules file:","memory location:","permissions:","delete guard:","backup path:","final check:") | Set-Content -Encoding ascii $check; Get-Content $check; Write-Host "Fill every line for this agent. Rerun this checklist for the next agent."
zsh (macOS)
check="${TMPDIR:-/tmp}/bbb-onboarding-checklist.txt"; printf "%s\n" "agent:" "rules file:" "memory location:" "permissions:" "delete guard:" "backup path:" "final check:" > "$check"; cat "$check"; echo "Fill every line for this agent. Rerun this checklist for the next agent."
bash (Linux)
check="${TMPDIR:-/tmp}/bbb-onboarding-checklist.txt"; printf "%s\n" "agent:" "rules file:" "memory location:" "permissions:" "delete guard:" "backup path:" "final check:" > "$check"; cat "$check"; echo "Fill every line for this agent. Rerun this checklist for the next agent."

2. Variable-Limit Delete Guard Demo

Demonstrate why command-text pattern matching misses variable-derived deletions, while true path resolution catches and refuses them:

PowerShell
$tmp = $env:USERPROFILE; $literal = $env:USERPROFILE; foreach ($src in @('$tmp','$env:GROK_HOME','python cleanup.py')) { if ($src -like "*$literal*") { "HIT $src" } else { "MISS $src" } }; if ([IO.Path]::GetFullPath($tmp) -eq [IO.Path]::GetFullPath($env:USERPROFILE)) { "REFUSE resolved tmp: it is the user profile. Text guards miss dollar-variables and python cleanup.py. 2026-09-23 Remove-Item of user profile is the example." }
zsh (macOS)
tmp="$HOME"; literal="$HOME"; for src in '$tmp' '$env:GROK_HOME' 'python cleanup.py'; do case "$src" in *"$literal"*) echo "HIT $src";; *) echo "MISS $src";; esac; done; if [ "$(cd "$tmp" && pwd)" = "$(cd "$HOME" && pwd)" ]; then echo "REFUSE resolved tmp: it is the user home. Text guards miss dollar-variables and python cleanup.py."; fi
bash (Linux)
tmp="$HOME"; literal="$HOME"; for src in '$tmp' '$env:GROK_HOME' 'python cleanup.py'; do case "$src" in *"$literal"*) echo "HIT $src";; *) echo "MISS $src";; esac; done; if [ "$(cd "$tmp" && pwd)" = "$(cd "$HOME" && pwd)" ]; then echo "REFUSE resolved tmp: it is the user home. Text guards miss dollar-variables and python cleanup.py."; fi

3. Off-Volume Profile & Data Backup

Back up ChatGPT Codex configuration and profile directory off the OS volume:

PowerShell
$dest = "D:\Backups\llm-profiles\$(Get-Date -Format yyyyMMdd-HHmm)" New-Item -ItemType Directory -Force -Path $dest | Out-Null if (Test-Path "$env:USERPROFILE\.codex") { robocopy "$env:USERPROFILE\.codex" "$dest\.codex" /E /NFL /NDL /NJH /NJS Write-Host "Backed up $dest\.codex" } Get-ChildItem $dest
zsh (macOS)
DEST="${BACKUP_ROOT:-$HOME/Backups}/llm-profiles/$(date +%Y%m%d-%H%M)" mkdir -p "$DEST" if [ -d "$HOME/.codex" ]; then rsync -a "$HOME/.codex/" "$DEST/.codex/"; echo "Backed up $DEST/.codex"; fi ls -la "$DEST"
bash (Linux)
DEST="${BACKUP_ROOT:-$HOME/Backups}/llm-profiles/$(date +%Y%m%d-%H%M)" mkdir -p "$DEST" if [ -d "$HOME/.codex" ]; then rsync -a "$HOME/.codex/" "$DEST/.codex/"; echo "Backed up $DEST/.codex"; fi ls -la "$DEST"

4. Practised Restore Drill

Never trust an unverified backup. Run this safe, self-contained restore drill inside your temp folder:

PowerShell
$drill = Join-Path $env:TEMP "bbb-restore-drill"; $src = Join-Path $drill "source"; $bak = Join-Path $drill "backup"; $back = Join-Path $drill "restored"; New-Item -ItemType Directory -Force -Path $src,$bak,$back | Out-Null; Set-Content -Encoding ascii -Path (Join-Path $src "proof.txt") -Value "bbb-restore-proof"; Copy-Item (Join-Path $src "proof.txt") (Join-Path $bak "proof.txt"); Remove-Item (Join-Path $src "proof.txt"); Copy-Item (Join-Path $bak "proof.txt") (Join-Path $back "proof.txt"); Get-Content (Join-Path $back "proof.txt"); Write-Host "Practised restore wrote proof into $back. Do not delete your user profile to test this."
zsh (macOS)
drill="${TMPDIR:-/tmp}/bbb-restore-drill"; src="$drill/source"; bak="$drill/backup"; back="$drill/restored"; mkdir -p "$src" "$bak" "$back"; printf "%s\n" "bbb-restore-proof" > "$src/proof.txt"; cp "$src/proof.txt" "$bak/proof.txt"; rm "$src/proof.txt"; cp "$bak/proof.txt" "$back/proof.txt"; cat "$back/proof.txt"; echo "Practised restore wrote proof into $back. Do not delete your home folder to test this."
bash (Linux)
drill="${TMPDIR:-/tmp}/bbb-restore-drill"; src="$drill/source"; bak="$drill/backup"; back="$drill/restored"; mkdir -p "$src" "$bak" "$back"; printf "%s\n" "bbb-restore-proof" > "$src/proof.txt"; cp "$src/proof.txt" "$bak/proof.txt"; rm "$src/proof.txt"; cp "$bak/proof.txt" "$back/proof.txt"; cat "$back/proof.txt"; echo "Practised restore wrote proof into $back. Do not delete your home folder to test this."

5. Fail-Closed Workspace Policy

Codex runs with danger-full-access on this fleet to allow sqlcmd, hub.py, and DEV_LOG operations. Full access requires the protect_user_folders.py PreToolUse hook in ~/.codex/hooks.json and off-volume backups.

Checkpoint: Confirm Build Bot Better Protection Required

Paste terminal output from the restore drill or variable demo confirming protection: