The worst AI coding session isn’t the one where the assistant makes a wrong change. It’s the one where it makes 47 wrong changes across 12 files, you hit “Restore Checkpoint,” and discover the checkpoint didn’t capture the three files the agent deleted with a rm in a bash step. As of June 2026, Cursor, Claude Code, and GitHub Copilot all ship built-in checkpoints. They’re great for a quick undo, and they all share the same blind spots. This guide covers what the built-in checkpoints actually do, where they quietly fail, and the four-step git discipline that keeps every AI edit reversible no matter which tool you use.
TL;DR
- Built-in checkpoints are a local undo, not a backup. They live on your machine, are separate from git, and (in all three major tools) do not track files changed by bash commands like
rm,mv, orcp. - Git is the real safety net. The four-step discipline: commit a clean baseline before AI runs, review the
git diffbefore committing AI output, commit between agent steps on long tasks, andgit stash“maybe later” changes. - Push before high-risk runs. Local commits and local checkpoints both vanish if your machine or repo dies. Push your baseline before any autonomous agent run.
- The overhead is 2-3 minutes per session. The payoff is that “undo” is always cheap and never a guess.
Built-in checkpoints: what each tool actually does
Every major AI coding tool added checkpoint-style undo over the past year. They work the same way at a high level — a snapshot of file state before each AI turn — and they all explicitly tell you to keep using git for real version history.
| Tool (as of June 2026) | How to rewind | What it captures | Retention |
|---|---|---|---|
| Claude Code | /rewind, or Esc Esc on an empty prompt | A checkpoint per user prompt; can restore code, conversation, or both | Persists across sessions; auto-cleaned after 30 days (configurable) |
| Cursor | Click a checkpoint in the chat timeline, or “Restore Checkpoint” on a prior request | Snapshot before each significant Agent edit | Current session + recent history, auto-cleaned |
| GitHub Copilot (VS Code) | “Restore Checkpoint” in chat; toggle via chat.checkpoints.enabled | Workspace + chat history snapshot per request | Session-scoped |
Claude Code is the most granular: its rewind menu lets you Restore code and conversation, Restore conversation (keep current code), or Restore code (keep the conversation) — useful when you want to undo the edit but keep the chat context. Cursor and Copilot bundle code and chat together.
The three gaps every built-in checkpoint shares
These limitations are documented by the vendors themselves, and they’re why git discipline still matters:
- Bash-command edits aren’t tracked. Claude Code’s docs state plainly that files changed by
rm,mv, orcp“cannot be undone through rewind.” If your agent runs a shell command that touches files, the checkpoint won’t restore them. Cursor and Copilot behave the same way for non-edit-tool changes. - They’re local and separate from git. Cursor stores checkpoints “locally and separate from Git.” If your laptop dies, a
git clonesomewhere else has zero checkpoints. They are not a backup. - Manual hand-edits and concurrent sessions slip through. Checkpoints generally track only edits made by the AI in the current session. Your own hand edits, or edits from a second agent session on the same repo, are often not captured.
Use the built-in checkpoint as a fast “oops, undo that last turn.” Use git for everything you’d actually be upset to lose.
The four-step git discipline
Same git you already know, applied with stricter cadence because AI changes more files faster than you do.
- Commit before AI runs. Even a “WIP” commit is fine — the goal is a clean diff after AI changes appear.
git commit -am "wip: baseline before AI refactor of userService". - After AI runs, always
git diffbefore committing. Read it line by line for changes you didn’t ask for: deleted error handling, removed null checks, renamed exports, “improved” loops that subtly change semantics. This is the step everyone skips and later regrets. - If the diff is clean, commit with a descriptive message.
git commit -am "ai: refactor callbacks to async/await in userService". If most is good but some is bad, stage only the good parts withgit add -p, commit, then discard the rest withgit restore <files>. - For multi-step agents, force a commit between steps. Tell the agent: “Stop after each ticket. I will commit before you proceed.” Long autonomous runs without intermediate commits are how 4-hour disasters happen.
For “maybe later” changes the AI produced that you don’t want to drop entirely, use git stash push -m "ai: extracted helper, may reuse". When an agent run goes off the rails, abort and git reset --hard HEAD back to the last known-good commit — far cheaper than untangling 40 unwanted changes by hand.
Commit cadence by task type
| Scenario | Minimum commit cadence |
|---|---|
| Single AI suggestion (one function, one file) | 1 commit per accepted suggestion |
| Multi-file refactor | 1 commit per logical unit (per module / per concern) |
| Autonomous agent run | 1 commit every 3-5 steps, plus a push before the run |
| Overnight / long batch run | Push baseline first; commit + push at every checkpoint |
Before you start: the pre-AI checklist
- Clean working tree.
git statusshows nothing uncommitted. Stash or commit anything in progress first, so AI changes arrive on a clean diff. - Tests green on the current state. You need a known-good baseline. If tests are already red, you can’t tell whether the AI broke something.
- Commit cadence decided. See the table above. Default to “more commits than feels necessary.”
- Baseline pushed. If you haven’t pushed in a week and the agent wrecks your repo, you can lose work that no checkpoint will save. Push first.
A handy one-liner to paste before any session: “Clean tree, baseline committed, baseline pushed, tests green.”
First-run exercise
- Pick a small task you’d normally do casually — rename a function across a module, or extract a helper.
- Run the full discipline: clean tree, baseline commit, baseline push, AI runs,
git diffreview, selective stage, commit. - Time it against your normal “just let it edit” approach. The overhead is small (2-3 minutes); the safety is large.
- The second time, deliberately accept a bad suggestion, then practice the rollback.
git resetandgit restoreare muscle memory you want before you need them under pressure — not the first time a production agent goes sideways.
Common mistakes
- Trusting the built-in checkpoint as a backup. It’s local-only and misses bash edits. Commit and push the things you can’t afford to lose.
- Letting AI work on a dirty tree. You can’t separate your in-progress edits from the AI’s changes. Stash first.
- Long agent runs with no intermediate commits. When something goes wrong (and it will), you lose hours or untangle a mess.
- “Looks fine, commit all” without reading the diff. Silent AI changes — deleted error handling, removed guards — ship to production this way.
- One giant final commit. It makes
git bisectuseless when a regression appears. Commit per logical step. - No remote push before high-risk runs. Local commits aren’t backed up; an agent that corrupts your repo can lose everything.
FAQ
- Do I still need git if my tool has checkpoints?: Yes. Vendor docs for Cursor and Claude Code both say checkpoints “complement but don’t replace” version control. Checkpoints are local undo; git is permanent, pushable history.
- The agent deleted a file and rewind didn’t bring it back. Why?: It almost certainly used a bash command (
rm) rather than its file-edit tool. Built-in checkpoints don’t track bash-modified files.git checkout HEAD -- <file>restores it if it was committed. - Can I use
git stashinstead of committing?: For short-term hiding, yes. For checkpoints during long runs, commits are stronger — stashes are easy to lose and don’t push to remote. - How do I review a huge AI diff efficiently?:
git diff --statfirst for the file map, thengit diff <file>per touched file. Scan for surprise files first — they hint at scope drift the agent introduced. - What about IDE undo (Ctrl+Z)?: Fine for a single edit, useless for multi-file agent runs and gone after you close the editor. Git is the source of truth.
- Can I script this?: Yes. A common team pattern is a
pre-ai.shthat runsgit status; git diff --statand refuses to proceed on a dirty tree. See the git basics for AI coding docs for the exact restore semantics.
Related
Tags: #AI coding #Tutorial