CoursesAI-powered Sanity developmentOpenAI Codex
AI-powered Sanity development

OpenAI Codex

Install Codex CLI, start a session in your project, and learn the prompt-and-confirm loop that makes it useful for Sanity work.
Log in to mark your progress for each Lesson and Task

Codex CLI is OpenAI's terminal-based AI coding agent. Like Claude Code, it runs in your shell, reads your project files, makes edits, and works through tasks autonomously. No IDE required.

It's a good fit if you're already in a ChatGPT-heavy workflow, or if you want to run multiple agents in parallel across different parts of a project (Codex supports subagents for this).

npm install -g @openai/codex

You'll need a ChatGPT Plus, Pro, Business, Edu, or Enterprise account. Codex is included in these plans.

Install Codex CLI by running npm install -g @openai/codex in your terminal

Once installation is complete, you can verify it worked by running codex --version in your terminal. You should see the installed version number printed to the screen.

Unlike Cursor, which embeds a terminal pane inside a graphical IDE, Codex CLI runs entirely in the terminal. There is no graphical user interface. The terminal is the interface.

Navigate to your project directory and run codex to start a session

On first run, Codex prompts you to authenticate with your ChatGPT account. Once in, you'll see the interactive TUI: a prompt where you describe what you want done, and Codex works through it.

A concrete example. From a Sanity Studio project, a prompt like "Add a category field to my post schema, with references to a new category document type, and regenerate the TypeGen types" triggers a predictable pattern:

  1. Codex reads schemas/post.ts and nearby schema files.
  2. It drafts schemas/category.ts, adds a reference field to post, and shows you both diffs.
  3. After you approve, it runs npx sanity schema typegen and shows the updated sanity.types.ts.
  4. If the TypeGen run fails, it reads the error, proposes a fix, and asks again.

The pattern holds for most tasks: read → propose → confirm → apply → verify.

Type / in a session to see available commands. /mcp shows your connected MCP servers once you've set those up in the next lessons.

Both are terminal-based agents that operate on your local files. The main differences are the underlying model (GPT vs. Claude) and some workflow tooling. Codex has built-in subagents for parallelising tasks, while Claude Code has tighter integration with the Sanity Agent Toolkit via its plugin system. Either works well for this course.

In the following lessons you'll prepare your environment for the best possible Sanity implementation. You could skip these steps, but your results wouldn't be nearly as good.

Let's set things up properly from the start.

You have 2 uncompleted tasks in this lesson
0 of 2