How to undo Codex changes
The Codex CLI has no undo command: its slash-command list, checked on October 17, 2026, has no
/undo and no /rewind. To undo a run, choose Revert all,
or revert one file or one hunk, in the Codex app's review pane, or put the files back with Git:
git restore for edits nobody committed and git revert for commits.
Where /undo went
If you remember typing /undo in Codex, you are not imagining it. In January 2026 a
user reported it missing after an update (openai/codex issue #8804, since closed). A request for a
/rewind that puts back both the chat and the code Codex edited is still open (issue
#11626).
What Escape twice does, and does not do
Press Esc twice with an empty composer and Codex lets you edit your previous
message, then forks the chat from that point. That rewinds the conversation. Codex's documentation
does not say it restores any files, and the author of issue #11626 writes that it does not revert
code changes made after that point.
So treat it as a way to ask again, not a way to undo. The files Codex already edited stay edited, and the re-asked turn starts from that changed code. Put the files back first, then edit the message.
Undo in the Codex app
The app's review pane shows the run's diff with Git actions on it. Codex's code review documentation, read on October 17, 2026, lists three levels you can revert or stage at:
- The entire diff, with Revert all or Stage all in the review header.
- One file.
- One hunk.
The docs sum it up as staging what you want to accept and reverting what you want to discard. That makes a partial undo easy: keep the hunks that were right, revert the one that was not.
When one part is wrong, a fix can be cheaper than an undo. Hover over the line in the review pane, select +, write what is wrong, and send a follow-up message that says what to do with it. The docs suggest something like "Address the inline comments and keep the scope minimal."
Undo in the CLI, with Git
Start by looking. Inside Codex, /diff shows staged changes, unstaged changes and
files Git is not tracking yet. In the project folder, the same picture:
git status
git diff --stat
You can run every command below without leaving Codex: prefix the line with ! and
it runs as a local shell command under your current approval and sandbox settings.
Edits nobody committed
git restore path/to/file
git restore .
The first puts one file back as it was at the last commit, or as you staged it. The second does it for every tracked
file under the current folder, including any edits of yours, so check
git status first. If something is staged, git restore --staged on it
comes first.
Files Codex created are untracked, and git restore does not touch them. List them
with git clean -n, which deletes nothing, then remove the ones that are Codex's by
hand or with git clean -f once the list holds nothing you want.
To set the attempt aside instead of deleting it, git stash --include-untracked
keeps it, new files and all, and git stash pop brings it back later.
Commits Codex made
Codex sometimes commits during a run, and a commit is not in git diff anymore.
Find the run's commits and undo them with new commits:
git log --oneline -5
git revert <commit>
git revert --no-commit <oldest-commit>^..HEAD
The second line undoes one commit. The third undoes a range in one go and leaves the result for you to check and commit. Both keep history intact, which matters once the branch is pushed.
Make the next undo easy
- Start from a clean tree. Commit or stash your own work before a run, so the diff, and anything you revert, is only Codex's.
- Use a worktree for risky attempts.
/worktreestarts or moves a chat into a managed Git worktree, a separate checkout of the repository. If the attempt is bad, your main checkout was never touched./newand/forkcan also offer a new worktree when they start. - Branch the chat, not just the code.
/forkcopies the chat into a new one and leaves the original as it was, so you can try a second approach and still go back to the first conversation. It does not copy files, so stash or commit the first attempt's code before you try again.
Which of these is your situation
- You use the Codex app and want the whole run gone: Revert all in the review pane.
- Most of the run is right: revert the bad file or hunk, or leave an inline comment and ask for a fix.
- You use the CLI and nothing is committed:
git restore, thengit clean -nfor new files. - Codex committed:
git reverteach commit or the range. - You want to re-ask the last prompt: undo the files first, then
Esctwice.
Know what you are throwing away
Before you revert a run, read it. Read sign-in, deletion, payments, new dependencies and configuration first. The full read is in how to review what Codex changed, and the same job in Claude Code, which does have a rewind, is in how to undo Claude Code changes.
BuildGist explains each meaningful Claude Code, Cursor and Codex run in plain English and flags concerns, so you can see what a run did before you keep it or throw it away. BuildGist does not undo anything. The review pane and Git do that. The explanation is written by AI, so check important behavior against the code and tests.
Sources
- Codex developer commands, checked October 17, 2026.
- Codex code review, checked October 17, 2026.
- openai/codex issues #8804 (closed) and #11626 (open), checked October 17, 2026.
What you need
- A Mac with Apple silicon and macOS 12 or later.
- Claude Code, Cursor or Codex.
- A Git project. No commit, push, remote or GitHub repository is needed.
- A GitHub account, to sign in. BuildGist does not access your GitHub repositories.
Codex needs you to approve BuildGist once, in Codex. BuildGist shows the steps. Setup is in Getting started.
To explain a run, your computer sends BuildGist what that run needs, and BuildGist passes it to Anthropic. BuildGist does not keep this material. It does not send your whole repository, files the run did not change, or files named like secrets, such as .env files and keys. It keeps the explanation and short cited excerpts of changed code, at most 12 lines each. Secret masking is best-effort. Privacy has the full list.
Every account gets 7 days of BuildGist Pro free, with no card. The 7 days start at your first explanation or Continue handoff. Nobody is charged when the trial ends. After that, BuildGist Pro is $12 per month, plus any applicable tax shown at checkout. See pricing.
Apple silicon, macOS 12 or later. United States, 18 or older.
Related
- What did Claude Code change?
- Switch from Claude Code to Codex
- Understand code an agent wrote
- Hand off Claude Code to Cursor
- Review what Codex changed
- You’ve hit your session limit in Claude Code
- You’ve hit your usage limit in Codex
- Keep context across agents
- Review AI code before merging
- BuildGist or the git diff
- Claude Code session history
- Undo Claude Code changes
- BuildGist vs CLAUDE.md, AGENTS.md and HANDOFF.md
- Keep context from Claude Code to Cursor
- Resume an agent session in another tool
- BuildGist vs Conductor
- Codex context window full
Questions: kayvanandre@gmail.com.