# Codex CLI

The Codex CLI is OpenAI's agent that runs in your terminal and works on the files in a folder. What it does, how to start it and how to undo its edits.

**Definition:** The Codex CLI is OpenAI's AI agent for the terminal, which you start in a folder and ask in plain language to read files, edit them and run commands there.

## You ask in plain words, and Codex edits your files

Start Codex in a folder of drafts, and it reads the files, makes the edits you ask for and can run tools on your computer.

```prompt
Turn the notes in lesson-03.md into a short lesson.
```

Sign in with your ChatGPT account to use your subscription, or with an API key to pay as you go.

## AGENTS.md holds the instructions it reads every time

Your style, your reader and anything else you'd repeat in every prompt go in an [AGENTS.md](/glossary/agents-md) file, a plain Markdown file in the folder. Codex reads it before it starts work.

## Codex has no undo of its own

The CLI has no undo or rewind command. OpenAI's docs suggest saving a version of the folder with Git before and after each task, so you can go back. To see what changed, ask Codex for the [diff](/glossary/git-diff): every changed line, new files included.

## In Flywrite, Codex works under the draft you're reading

Press ⌃3 and Codex starts in Flywrite's terminal, on the project you have open. The page updates as it edits.

It doesn't see your open file or selection on its own, so @-mention the file, or select text and press ⌘⇧L to [send that selection to the terminal](/guides/send-selection-to-cli-agent).

Flywrite saves a [checkpoint](/glossary/checkpoint) of the whole project when Claude Code starts in its terminal, and when Cursor Agent starts after its one-time setup. Codex and other CLI agents don't trigger it, so press ⌘⇧C before you start them.

You use your own ChatGPT plan or API key, with no Flywrite AI fee. More in [Writing with Codex](/docs/writing-with-codex) and the guide to [course lessons with the Codex CLI](/guides/codex-cli-course-lessons).

## Questions

### Is the Codex CLI the same as Codex in ChatGPT?

It's one of several Codex surfaces. The CLI runs in your terminal on the files in a folder; the Codex desktop app, the IDE extension and Codex cloud are the others.

### How do I undo what Codex changed?

The Codex CLI has no undo command of its own, and its docs advise saving a Git checkpoint before and after each task. Restore from that checkpoint to take the changes back.

## Sources

1. [OpenAI Codex docs: Codex CLI](https://learn.chatgpt.com/docs/codex/cli), checked 2026-11-10
2. [OpenAI Codex docs: Authentication](https://learn.chatgpt.com/docs/auth), checked 2026-11-04
3. [OpenAI Codex docs: Developer commands (CLI)](https://learn.chatgpt.com/docs/developer-commands?surface=cli), checked 2026-11-17
4. [OpenAI Codex docs: Custom instructions with AGENTS.md](https://learn.chatgpt.com/docs/agent-configuration/agents-md), checked 2026-11-10
5. [Flywrite docs: Writing with Codex](/docs/writing-with-codex), checked 2026-11-17

---

This is the Markdown copy of https://flywrite.app/glossary/codex-cli.
