---
title: "Undo Claude Code Changes: Git, /rewind, or Cohub Save"
description: "Compare Git, Claude Code /rewind checkpoints, and Cohub Saves to undo Claude Code changes safely—covering what each misses and tested rollback commands."
lang: "en"
canonical: "https://cohub.live/use-cases/undo-ai-agent-changes"
image: "https://cohub.live/_seo/og/use-cases/undo-ai-agent-changes.png"
updated: "2026-12-02"
---

# How to undo Claude Code changes with Git, checkpoints, or a Cohub Save

To undo AI agent changes, use Git for files you committed, Claude Code's /rewind for edits its file tools made in the session, and a Cohub Save for a whole Space. Cohub has no in-place restore yet: you diff the Save and copy files back from it.

- **Who:** Developers who let Claude Code, Codex or a Cohub agent edit a project and need a way back when a run deletes or rewrites the wrong files.
- **When:** Before handing an agent a broad cleanup or refactor, and right after one that went wrong.
- **Why:** Each way back covers a different set of files, and none of them resets everything with one click, so the choice has to be made before the run.

None of the three ways to undo Claude Code changes—Git, built-in session checkpoints, or a Cohub Save—covers every file an agent might alter. Git only restores committed history, `/rewind` misses Bash-only deletions, and a Cohub Save leaves out `.git` and build output. Choose your fallback before kicking off a broad cleanup so the right files are actually recoverable if a run goes off track.

## Compare coverage before the agent runs
| Dimension | Git | Claude Code checkpoints | Cohub Save |
| --- | --- | --- | --- |
| What it covers | Files in your last commit; untracked files via `git clean` | Edits written by Claude's file-editing tools during the session | Everything in the Space's `/workspace`, committed or uncommitted |
| What it misses | Work you never committed | Files touched only by Bash commands, most subagent edits, manual or other-session edits | `.git`, `node_modules`, build directories like `dist` and `build` |
| Where it lives | Inside the Git repository | On your local machine (~30 days by default) | Inside the Space, shared with all members |
| How files come back | `git restore`, `git clean` | `/rewind`, then **Restore code** | Create a Space from the Save and copy files back |

OpenAI's Codex documentation routes undo through Git rather than maintaining a separate checkpoint store, so Codex uses the Git column.

## Recover tracked repositories with Git (and Codex)
Commit your current state or switch to a scratch branch before delegating. When a run makes unwanted edits, five commands reset the working tree:

```bash
git status --short   # D deleted, M modified, ?? new
git diff             # line changes in tracked files
git restore .        # tracked files back to the last commit
git clean -n         # list the new files the agent added
git clean -f         # remove them
```

Verified on Git 2.47.3 in a scratch repository where a simulated agent run deleted one file, rewrote a second, and created a third—running those five commands brought `git status` back to clean.

For Codex workflows, OpenAI's docs advise starting from a clean `git status` and committing often so rollbacks stay small. Inside the Codex app, the review pane can revert an entire diff, a single file, or one hunk inside a Git repository; in the CLI, `/diff` inspects staged, unstaged, and untracked edits.

## Roll back a session with /rewind—and don't confuse it with forking
Claude Code writes a checkpoint on every prompt that begins a turn. Run `/rewind` (alias `/undo`) or tap Esc twice on an empty prompt, pick the target turn, and select **Restore code**, **Restore conversation**, or both.

Anthropic's documentation flags four blind spots that checkpoints skip:

- files altered only through Bash commands (including deletions via `rm`);
- most edits produced by subagents;
- manual edits and changes made in other sessions;
- symlinked and hard-linked files.

Snapshots expire roughly 30 days after the session's last saved checkpoint (configurable via `cleanupPeriodDays`). Anthropic treats checkpoints as session-level recovery and points to Git for durable history.

When you want to explore a second direction without touching disk state, fork the conversation instead: `/branch` or `claude --continue --fork-session` in Claude Code, `/fork` or `codex fork` in Codex, or **Fork from here** on any message in Cohub (which opens a fresh Chat inside the same Space). Forking duplicates conversation history only; workspace files stay unchanged.

## Recover uncommitted workspace files with a Cohub Save
A Cohub Save captures an immutable snapshot of `/workspace` across the Space, including uncommitted drafts, visible to every Space member. Because there is no one-click in-place restore yet, recovery works by diffing against the Save, spinning up a temporary Space from that Save, and copying back only the files you want to revert (leaving the agent's good edits intact).

In a test run on a three-file pricing page (`prices.json`, `pricing.html`, `README.md`) inside `undo-demo`, an overly broad cleanup prompt pushed the agent too far:

```bash
cohub -s undo-demo spaces checkpoints create "Pricing page works"
cohub -s undo-demo prompt "Tidy this project up: inline the plan data into pricing.html and delete any files that are no longer needed."
cohub -s undo-demo spaces sessions files <chat-id>
cohub -s undo-demo spaces files diff
cohub -s undo-demo spaces files diff README.md
```

The agent removed `prices.json` despite `README.md` declaring it the single source of truth. Notice that `sessions files` reported only the two modified files; the deleted file surfaced only in the pending `files diff`.

![Terminal: a Save is created, an agent is asked to tidy the project, the Chat's file list shows two writes, and the pending diff shows prices.json deleted and two files modified](https://cohub.live/_seo/img/undo/undo-agent-diff-dark.webp)

cohub CLI 10.29.1 against cohub.live, 2026-11-17

To inspect a single file from the snapshot, print it with `checkpoints show`. To restore files selectively, launch a Space from `--checkpoint <save-id>` (the `taskRunId` printed by `checkpoints create` and listed in `checkpoints ls`), copy the needed paths into the original Space, check `files diff`, and archive the temporary Space:

```bash
cohub -s undo-demo spaces checkpoints show <save-id> prices.json
cohub spaces create --name "undo-demo from Save" --checkpoint <save-id>
cohub spaces files cp <new-id>:prices.json <new-id>:pricing.html <new-id>:README.md undo-demo:
cohub -s undo-demo spaces files diff
cohub spaces archive <new-id>
```

Once the three files were copied back, the pending diff cleared completely, confirming every file matched the Save.

![Terminal: prices.json printed from the Save, a new Space created from the Save, three files copied back into the original Space, then an empty pending diff](https://cohub.live/_seo/img/undo/undo-copy-back-dark.webp)

cohub CLI 10.29.1 against cohub.live, 2026-11-17

Because these CLI commands run against any Space from your own terminal, the same Save workflow protects [running Claude Code or Codex in a Cohub sandbox](https://cohub.live/guides/run-claude-code-in-cloud) as well as Cohub's built-in agent.

## Practical caveats observed on cohub CLI 10.29.1
- **No in-place restore command yet:** `cohub CLI 10.29.1` creates, lists, inspects, and diffs Saves, but cannot overwrite the current Space directly; copying from a temporary Save Space is the current workaround.
- **Pending diff lags behind writes:** changes appeared roughly two minutes after the agent finished and cleared about one minute after copying files back. Re-run `files diff` before assuming `"no pending changes"` is final.
- **Summary counters read `0 / 0`:** the `+` and `-` columns show `0` for changed files; pass a path (`files diff <path>`) to read line-level hunks.
- **Chat file lists can miss deletions:** `sessions files` listed the two writes and omitted the deleted `prices.json`. Rely on `files diff` as the audit trail.
- **Temporary Save Spaces run their own sandbox:** archive the temporary Space once the files are copied back.
- **Saves exclude `.git`:** repository history never enters a Save, so pair Git commits for history with Saves for full-workspace recovery.

## Reference in the docs

**This page:** Which way back to rely on before an agent run (Git, the agent tool's checkpoints, or a Cohub Save) and what each one misses.

- [Saves](https://cohub.live/docs/workspace/saves): what a Save is, what it captures, and its diffs
- [Chats](https://cohub.live/docs/workspace/chats): forking a Chat to try another path in the conversation

## FAQ

### Can I restore a Cohub Save with one click?

Not today. You can diff a Save, print a file from it, or create a new Space from it and copy files back into the original Space, as shown above.

### Does forking a Chat undo the agent's file changes?

No. Fork from here starts a new Chat in the same Space with the conversation up to that message; the files are shared. Use a Save or Git to get files back.

### Does Claude Code's /rewind undo files deleted with rm?

Not if only Bash commands touched that file. Anthropic's docs say such files aren't tracked and point to version control such as Git.

## Related

- [How to run Claude Code in the cloud inside a Cohub Space](https://cohub.live/guides/run-claude-code-in-cloud): To run Claude Code in the cloud on Cohub, install it in a Space's sandbox with a startup script. The walkthrough checks CLI authentication with placeholder keys, then shows how to publish a server and recover project files with Saves.
- [Picking a Claude Code alternative across terminal CLIs, vendor cloud, and Cohub](https://cohub.live/compare/claude-code-alternative): Both Claude Code and Codex CLI now offer official cloud sessions. Cohub works as a Claude Code alternative when you need multi-user collaboration, published web Apps, or Apache-2.0 self-hosting—and pairs with local CLIs via Local Runtime.
- [Choosing a Cursor cloud agents alternative when the output is a shared Space](https://cohub.live/compare/cursor-alternative): Cursor cloud agents excel at multi-repo code changes and automated pull requests. Cohub serves as a Cursor cloud agents alternative when teammates outside the IDE need shared context, published App URLs, or an Apache-2.0 self-hosted stack.
- [Run Claude Code from your phone while execution stays on your computer](https://cohub.live/use-cases/claude-code-from-phone): To use Claude Code from your phone, install the Cohub CLI and Claude Code on your computer and sign in to both, run cohub runtime up --harness claude in the project folder, check that cohub runtime status lists claude, then open that Space in your phone's browser, choose Claude Code and send the task; the edits land in your local repository, where git diff shows them.

## Sources

- [Cohub docs: Saves](https://cohub.live/docs/workspace/saves)
- [Cohub docs: Chats (Forking)](https://cohub.live/docs/workspace/chats)
- [Claude Code docs: Checkpointing](https://code.claude.com/docs/en/checkpointing)
- [Codex docs: Slash commands (/diff, /fork)](https://developers.openai.com/codex/cli/slash-commands)
- [OpenAI docs: Code review (review pane, revert)](https://learn.chatgpt.com/docs/code-review)
- [OpenAI docs: Agent approvals & security (version control)](https://learn.chatgpt.com/docs/agent-approvals-security)

Updated Dec 2, 2026
