Short answer: in Claude Code, type /rewind (or /undo, or press Esc twice) and pick Restore code: it puts back the files Claude edited with its own edit tools since that message. The Codex CLI has no undo command; OpenAI's advice is to make Git checkpoints, and the ChatGPT desktop app's review pane can revert the diff per file or per hunk. OpenCode has /undo and /redo. None of them reliably takes back what an agent's shell commands did, so commit before a big task.
Everything about Claude Code, Codex and OpenCode below is from their own documentation, read on December 1, 2026. (I build Morphy, an app that runs these agents side by side and has its own Undo; it comes up in the second half.)
What each one undoes
| How | Files the agent edited | Changes made by commands | Conversation | |
|---|---|---|---|---|
| Claude Code | /rewind, /undo, Esc Esc | Yes | Only in files Claude had already edited | Yes, if you choose |
| Codex CLI | No undo command; Git checkpoints | Through Git | Through Git | No |
| Codex in the ChatGPT desktop app | Review pane: Revert all, per file, per hunk | Through Git | Through Git | No |
| OpenCode | /undo, /redo, Ctrl+X U | Yes, with snapshots on | Not stated in its docs | Yes |
| Git | A commit before, git stash -u after | Everything it tracks | Everything it tracks | No |
How to undo changes in Claude Code
Claude Code saves a checkpoint every time you send a prompt that starts a turn, and keeps file snapshots for the 100 most recent checkpoints of a session. To go back:
- Type
/rewind(its aliases are/undoand/checkpoint), or pressEsctwice with an empty prompt. - Pick the message you want to go back to.
- Choose Restore code and conversation, Restore conversation (keep the code), or Restore code (keep the conversation).
Checkpoints are saved with the conversation, so /rewind still works after you resume a session. Their snapshots are deleted about 30 days after the session last saved one.
What it misses, in Anthropic's words:
- Shell commands: "A file that only Bash commands changed isn't tracked and stays as it is." So
npm install, a build or asedin a file Claude never edited with its edit tools stays changed. - Most subagents: a subagent's edits to files your own conversation hadn't edited "stay, so use version control, such as Git, to revert them."
- Your own changes: restoring a file Claude edited "can discard changes you or another session made to that file after the selected checkpoint."
- Linked files: symlinked and hard-linked files are skipped.
Anthropic sums it up: "Checkpoints are designed for quick, session-level recovery." For the rest, it points to Git.

Does Codex have an undo?
Not as a command. The slash commands in OpenAI's Codex CLI reference have no /undo or /rewind (checked December 1, 2026). Its quickstart says instead: "Create Git checkpoints before and after a task so you can revert changes."
In the ChatGPT desktop app, Codex's review pane has Git actions: Revert all for the whole diff, or revert one file or one hunk. Because these work on the Git diff, they can't tell the agent's edits from yours in the same file (my reading, not OpenAI's words).
In the CLI, for work you may want to throw away, /worktree starts or continues the chat in a managed Git worktree, a separate checkout, so your main folder stays as it was.
For apps that run Codex, its app-server has thread/revert, which removes turns from the conversation. Its docs are clear: "It doesn't revert local file changes."
OpenCode's /undo and /redo
In OpenCode's terminal app, /undo (or Ctrl+X then U) reverts "the latest user message and the work that followed it", and puts your prompt back in the box to edit. /redo (Ctrl+X then R) brings the work back; sending a new prompt instead keeps the undo. It runs on filesystem snapshots, a setting its config docs describe as "used by undo and revert behavior", so leave snapshots on. Its own server has revert endpoints too.
Git is the safety net under all of them
Every one of these tools tells you the same thing: keep using Git. The habit that covers what checkpoints miss:
- Before a big task, commit what you have.
- After it, look at
git diffto see everything that changed, commands included. - If it went wrong,
git stash -uputs every change since the commit aside, new files included.git stash popbrings it back if you change your mind.
For bigger experiments, give the agent its own copy of the project: a Git worktree is the usual way.
Why an app around the agents copies the folder
Morphy has an Undo on every turn that changed files, on every AI it runs. In November I asked my agent a fair question: why does Morphy copy a whole folder for that, instead of using each agent's own undo?
It checked each one. For the way Morphy runs them, only Claude's undo is one another app can call: Anthropic's Agent SDK has file checkpointing, where an app turns it on and calls rewindFiles() to put files back. Codex's revert only rewinds the conversation. OpenCode, Grok, Copilot, Hermes and Junie run in Morphy over ACP, the open protocol code editors like Zed use to run agents, and the protocol's list of methods has no undo. (OpenCode's own undo lives in its own app and server, not in ACP.)
And Claude's has the same gap as /rewind. The SDK's checkpointing tracks the Write, Edit and NotebookEdit tools, and "Rewinding doesn't undo changes a Bash command made, except in files the main conversation had already edited." Directories that were created, moved or deleted aren't undone either.
So Morphy does something plainer. An app can't know in advance which files an agent will change, and once a file is changed, its old version is gone. So before a turn, Morphy keeps a "before" copy of the chat's folder in a Git store of its own (never in your repository). The first copy reads the whole folder; after that, each turn only stores the files that changed. That's why it catches the agent's edits and what its commands did, on every AI.
It has a cost. In a speed test on November 23, the copy added 0.1 to 0.25 seconds before each turn. The very first copy of Morphy's own code repository took 28 seconds; the turn itself waits 3 seconds at most and then goes ahead without Undo. On November 28 I hit the worst case: a chat working in a folder with about 1.5 GB of loose files, where the first copy never finished and Morphy tried again every hour (it turned up while I was looking into two PC freezes). I chose a plain limit: a folder whose first copy would be over 1 GB gets no Undo, and Morphy doesn't try again for a week. On a test folder shaped like mine (72,000 files, 1.27 GB), that took the hourly 65 seconds of work down to 3.4 seconds, once a week.

Where Morphy's Undo doesn't work
From Morphy's docs and my own checks:
- Outside the chat's folder. Undo copies only the chat's own project folder, so an edit the agent makes in another folder can't be undone.
- Big or special folders. Not in your vault's own folder, Morphy's own folder, a whole drive, your home folder, or your Desktop, Documents or Downloads folder itself, nor a cloud drive's own folder. A project folder inside any of them works. A folder that would take more than 1 GB to copy has no Undo.
- What Git ignores. Ignored files,
node_modulesand files over 50 MB aren't covered, nor big batches of generated output, like a render's frames. - Without Git. The project doesn't need to be a repository, but your computer needs Git 2.32 or newer.
- After a day. Turns stay undoable for a day.
A file you changed after the turn is left as it is, and the list says so. If another chat worked in the same folder at the same time, the list warns that some changes may be its. More in Undo a turn.
Questions
How do I undo changes in Claude Code? Type /rewind or /undo, or press Esc twice, pick a message and choose Restore code. It restores files Claude edited with its edit tools, not changes made only by shell commands.
Does Codex have an undo command? The CLI doesn't. Use Git checkpoints, the desktop app's review pane (Revert all, per file, per hunk), or start risky work in a worktree with /worktree.
Can I undo what an agent's terminal commands did? Not with Claude Code's checkpoints, unless the file was one Claude had already edited. Git can, if you committed before. An app that copies the folder, like Morphy, can too, inside that folder.
Does Claude Code's rewind work after I close the session? Yes, checkpoints are saved with the conversation, until their snapshots are cleaned up about 30 days later.
Related
- Claude Code worktrees
- How to run multiple Claude Code agents
- Codex vs Claude Code
- Undo a turn in Morphy
References
- Anthropic: Checkpointing, Commands, Rewind file changes with checkpointing (Agent SDK)
- OpenAI: Codex CLI, Developer commands, Code review, App server
- OpenCode: TUI, Config, Server
- Agent Client Protocol: Schema
- Morphy: Undo a turn




