First: stop, and don't make it worse
- Press Esc to interrupt Claude. Don't ask it to fix the problem yet: its usual fixes are
git checkoutandgit reset, which destroy more. - Don't run
git stash,git cleanorgit resetuntil you know what's missing. - If the files are gone from disk, avoid writing a lot of new data to that disk.
1. Rewind to a checkpoint
Claude Code saves a checkpoint of each file before it edits it. Press Esc twice, or type /rewind, pick the point in the conversation you want to return to, and choose whether to restore the code, the conversation or both.
Checkpoints only track edits made with Claude's own file tools. Anything changed by a shell command isn't recorded: rm, mv, sed -i, a formatter, a code generator, a migration, git reset --hard. If a command did the damage, /rewind can't help.
2. Ask git
| What happened | Try |
|---|---|
| A tracked file was deleted or changed | git restore path/to/file, or git checkout HEAD -- path/to/file |
| Commits disappeared after a reset or rebase | git reflog, then git reset --hard <commit> or git cherry-pick <commit> |
Staged changes were wiped by git reset --hard | git fsck --lost-found, then inspect the dangling blobs with git show <hash> |
| A stash was dropped | git fsck --unreachable | grep commit, then git stash apply <hash> |
Git can't help with changes that were never staged, untracked files, or files in .gitignore such as .env. git clean -fd and rm on those are final as far as git is concerned.
3. Look for copies elsewhere on your Mac
- Your editor. VS Code and Cursor keep a local history: open the Timeline panel for the file, or run Local History: Find Entry to Restore. JetBrains IDEs have Local History in the right-click menu.
- Time Machine. If it's on, open the folder in Finder and choose Browse Time Machine Backups. macOS also keeps hourly local snapshots for about a day when the backup disk isn't connected.
- The transcript. Claude Code's session files in
~/.claude/projectscontain the content of every file Claude read or wrote. If Claude read the file earlier in the session, its text is in there. - The Trash. Files deleted with
rmdon't go there, but files removed through Finder or some tools do.
4. Recovery tools: usually not
On a modern Mac, undelete tools rarely recover files removed with rm. The internal SSD erases freed blocks quickly and the disk is encrypted. Try them if nothing else worked, but don't count on them.
Make the next one a non-event
- Commit before each session, or use a git worktree per task.
- Keep Time Machine on.
- Have a snapshot of the whole folder taken automatically when the agent starts.
The last one is what Rollcage snapshots do. When Claude Code, Codex or Cursor starts in a project, Rollcage makes an instant APFS clone of the folder, and another every 15 minutes while the agent runs. It includes uncommitted work and ignored files. Afterwards you can see which files were deleted or changed and restore them one at a time or all at once. A notification tells you when files are disappearing in bulk.
Rollcage can only restore from snapshots taken while it was installed. It can't recover files that were deleted before that.
Questions
Does /rewind undo bash commands?
No. Checkpoints cover edits made with Claude Code's file editing tools. Files deleted or changed by a shell command aren't tracked and can't be rewound.
Can I undo git reset --hard?
Committed work, yes: find the commit with git reflog. Staged changes, sometimes, with git fsck --lost-found. Unstaged changes, no. They were only on disk and git kept no copy.
How do I recover a deleted .env file?
Git won't have it, because it's ignored. Check your editor's local history, Time Machine, a snapshot if you have one, and wherever the values came from: your hosting provider's settings, a password manager or a teammate.
How long does Claude Code keep checkpoints?
Checkpoints are kept with the session and cleaned up along with old sessions, after 30 days by default. They're meant for undoing recent work, not as a backup.