What is Codex?
Codex is OpenAI's AI coding agent. Like Claude Code (Guide 3), the Codex CLI runs in your terminal: you describe a change in plain English, it reads the Butter Bot's source code, writes the C++, and can build and flash the firmware for you. It's open source, written in Rust, and included with ChatGPT paid plans.
(Codex also exists as a VS Code IDE extension and as a cloud agent inside ChatGPT — this guide uses the CLI, which is the simplest way to work on firmware that lives on your computer.)
The Codex CLI docs
What you need
Item | Notes |
Everything from Guide 2 | Working ESP-IDF setup + the cloned |
A ChatGPT account | ChatGPT Plus, Pro, Business, Edu, and Enterprise plans include Codex (Plus is ~$20/month). Alternatively, pay-as-you-go with an OpenAI API key. |
15 minutes | Same as Guide 3. |
Step 1 — Install the Codex CLI
The official setup lives at https://developers.openai.com/codex/cli — here's the short version:
Codex CLI setup from the official docs
macOS/Linux
Easiest, in Terminal (official installer):
curl -fsSL https://chatgpt.com/codex/install.sh | sh
Or, if you are on macOS and use Homebrew: brew install --cask codex
Windows
Codex runs natively on Windows (Windows 11 recommended). Open PowerShell (Start menu → type powershell → Enter) and paste the official installer:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
(Alternatives: npm install -g @openai/codex if you have Node.js; or run Codex inside WSL2 with the macOS/Linux command above — see OpenAI's Windows setup guide.)
Check it worked
Open a new terminal and run:
codex --version
You should see something like codex-cli 0.142.5.
To update Codex later: codex update (or re-run the installer / npm update -g @openai/codex).
Step 2 — Sign in
Go to your Butter Bot project folder: - macOS/Linux:
cd ~/Projects/ButterBot-Firmware- Windows:cd C:\Projects\ButterBot-FirmwareRun:
codexOn first run, Codex asks you to sign in — choose Sign in with ChatGPT. Your browser opens; log in and approve. (You can also use an OpenAI API key instead.)
You're now chatting with Codex inside your project. To leave later, press
Ctrl+C(or type/exit).
If anything seems off, codex doctor checks your installation, login and configuration.
Approvals: Codex starts in Auto mode — it works freely inside the project folder, but asks for your approval before touching anything outside it or using the network (flashing the robot over USB may trigger such a prompt — that's expected, approve it). Type /permissions to see or change what Codex may do without asking; /status shows the current setup. Same philosophy as Claude Code: you review, you approve, git can undo.
Step 3 — Open the right terminal (so Codex can build)
Codex can only compile the firmware if idf.py works in the terminal you launched it from:
Open the
ButterBot-Firmwarefolder in VS Code (as in Guide 2).Press
F1→ "ESP-IDF: Open ESP-IDF Terminal".Run
codexin that terminal.
(Terminal purists: any shell with the ESP-IDF environment loaded works too — source the export.sh from your ESP-IDF install; the path is version-specific, e.g. ~/esp/esp-idf-v5.5.3/export.sh.)
Step 4 — The fun part: teach the robot to be funnier
The Butter Bot picks its jokes from a list in the firmware and speaks them with on-device text-to-speech. Paste this prompt into Codex (put your own joke in!):
Add a new joke to the Butter Bot's joke list: "I asked the toaster for a joke. It was too dark". Look at how the existing jokes are defined in components/ButterBot-Common/src/Phrases.cpp and follow the same pattern exactly, including the trailing comma. Write it the way a text-to-speech engine can pronounce it.
What you'll see (example session, shortened):
Example Codex session
Codex will: 1. Search and read Phrases.cpp to find JokePhrases. 2. Edit the file: your joke added, formatted exactly like its neighbors and written so the text-to-speech engine pronounces it right — the little details that trip up humans. 3. Show you the diff of what it changed.
Not sure about the change? Ask: "show me exactly what you changed and why".
Step 5 — Build and flash, hands-free
Still in the same session:
Build the firmware with idf.py and fix any compile errors you caused. Then flash it to the robot on port <YOUR-PORT> and tell me when it's done.
(Replace the port with yours from Guide 2, Step 7 — e.g. COM5 on Windows or /dev/ttyUSB0 on Linux.)
Codex runs idf.py build (~20 seconds for a one-file change), asks for approval to flash, then runs idf.py -p <port> flash.
Step 6 — Test it on the robot
Short-press the power button — the robot starts listening.
Say: "Tell me a joke."
Repeat until your joke comes up (they're picked at random). Take a bow. 🎭
More prompt ideas
Identical playground as Guide 3 — these all work with Codex too:
"Add three new responses for when someone tells the robot to pass the butter, matching the existing deadpan tone."
"List every voice command this robot understands, in a table."
"Make the robot grumpier when it gets picked up."
"Walk me through what happens in the code when I say 'tell me a joke', step by step, for a beginner."
And the same note: adding new spoken commands (not responses) involves phoneme strings in ListenState.cpp — Guide 5 — Program Your Butter Bot explains that whole system step by step, and its sections work as specs you can paste straight into Codex.
Troubleshooting
Symptom | Fix |
| Open a new terminal so PATH refreshes; if it still fails, re-run the Step 1 installer. (Only if you installed via |
Codex can't run | Launch |
Login loops or errors | Run |
Build fails after the change | Paste the error into the chat: "the build failed with this error, fix it" |
Flash fails | Guide 2, Step 8 checklist: close the serial monitor, verify the port, power-cycle, direct USB |
Want a clean slate | Ask Codex: "show me everything that changed". Full reset to stock: |
Claude Code or Codex — which one?
Both do this job well, and both follow the same loop: describe → review the diff → approve → build → flash → play. Use whichever assistant you already pay for: Claude Pro/Max gets you Claude Code (Guide 3), ChatGPT Plus/Pro gets you Codex. Firmware tinkering is a fantastic, low-risk way to learn either — your robot can always be restored to stock (Guide 2, FAQ).
Ready to go deeper than jokes? Guide 5 — Program Your Butter Bot walks through new voice commands, object detection, and controller mods in full detail.