An AI agent deleted my files. What do I do?
Go down this list in order. Each step says what it can bring back, with a link to the tool's own documentation.
1. Stop, and stop writing
Interrupt the agent or close the terminal it runs in. Do not ask it to fix things yet: a quick git reset --hard or git clean can remove what is still there.
Then keep that disk quiet. Do not download, install, build or copy anything onto it. A deleted file's bytes stay on the disk only until something else is written over them. If you can, read this page on your phone: a browser writes its cache to the disk it runs from.
Look in the Trash or Recycle Bin once. A shell rm does not use it, but a delete made through a file manager does.
If you used Claude Code, copy the ~/.claude folder to a USB stick or another disk now. It holds the session transcripts and Claude Code's own copies of files it edited (step 2), and it records exactly what was deleted.
If any file you need was never committed, never saved in your editor, never backed up and never synced, go to step 6 now, before anything else. Steps 2 to 4 write to the disk.
2. Claude Code: rewind
In the same session, run /rewind, or press Esc twice with the prompt empty. Pick the message from before the damage and choose Restore code
, which reverts file changes and keeps the conversation. If you closed it, claude --resume reopens it: the docs say checkpoints are saved with the conversation, so /rewind still works after you resume.
Know what it covers. Checkpoints track the edits Claude made with its own file tools. The docs say: A file that only Bash commands changed isn't tracked and stays as it is. To revert it, use version control, such as Git.
So a file the agent only ever touched with rm will not come back this way. Edits made by subagents are usually not captured either. Restoring code can also overwrite changes made after that checkpoint, so copy anything you want to keep first. Source: Claude Code docs, checkpointing.
If rewind does not have it, the transcripts may. Claude Code keeps each session's transcript as plain text under ~/.claude/projects/, for 30 days by default (Claude Code docs, data usage). A file the agent read or wrote is often in there. In issue 112961, after a script deleted a project, Claude rebuilt most of its text files from its own session transcripts. Images and other binary files are not in transcripts.
3. Git
In the project folder, git status lists tracked files that are gone as deleted:. Put them back by name:
git status
git restore -- src/ README.md
git restore takes the files from the index, which is your last commit plus anything you had staged. Name the paths: git restore . would also throw away every uncommitted edit to files that still exist. If git status lists them under Changes to be committed
, the agent ran git rm; use git restore --staged --worktree -- src/, which takes them from the last commit. Source: git restore.
If the agent reset or rebased, git reflog lists where your branch pointed before. Make a new branch at the old point, using the hash at the start of its line; this changes nothing in your folder, and you can look at the branch before you switch to it. Entries for commits a reset or rebase left behind are kept 30 days by default. Source: git reflog. If the agent deleted a branch, that branch's own reflog went with it: look in the agent's transcript for Deleted branch name (was 1a2b3c4) and use that hash.
git reflog
git branch rescue 1a2b3c4
Check git stash list too; agents often stash. Files you had added with git add but never committed are still stored as objects, and so are dropped stashes and commits nothing points to. git fsck --lost-found writes them out: files into .git/lost-found/other/, with their contents but without their names, and commits into .git/lost-found/commit/. Sources: git fsck, Pro Git, Git objects.
If the whole folder is gone, .git included, clone your remote again: everything you pushed is there. Files git never saw need the next steps.
4. Your editor's local history
VS Code adds an entry to a file's local history every time you save it in VS Code. To get back a deleted file, open the Command Palette and run Local History: Find Entry to Restore
, then pick the file. For a file that still exists, its entries are in the Timeline view in the Explorer. Changes made outside VS Code, such as an agent's shell, are not saves, so what you get back is the version you last saved there. Editors built on VS Code, such as Cursor, have the same local history. Source: VS Code 1.66 notes, local history.
JetBrains IDEs (IntelliJ, PyCharm, WebStorm and the rest) record changes made in the IDE and outside it. Right-click the folder that held the file, choose Local History, then Show History, pick a revision from before the delete, right-click the file and choose Revert Selection. By default it keeps the last 5 working days. Source: JetBrains docs, local history.
5. Backups, snapshots and cloud sync
Mac, Time Machine: open a Finder window on the folder that held the files, open Time Machine, use the arrows to go back to before the delete, select the items and click Restore. Source: Apple, restore items backed up with Time Machine.
Windows, File History or restore points: in File Explorer, right-click the folder that held the files and choose Restore previous versions. Pick a version from before the delete. Microsoft warns that Restore replaces the current folder and the replacement can't be undone
, so use Restore to... and pick another place. Source: Microsoft, File History.
Linux, ZFS: snapshots can be read under the hidden .zfs/snapshot folder at the root of the file system; copy the files out (OpenZFS docs). On btrfs, if Snapper or Timeshift takes snapshots, restore from one dated before the delete.
Cloud sync: if the folder synced, the delete synced too, but the website keeps it for a while. OneDrive: the Recycle bin on the OneDrive website (Microsoft). Dropbox: Deleted files on dropbox.com (Dropbox). On personal plans, both keep deleted files for 30 days.
6. Recovery tools, last
Undelete tools read the raw disk for leftover file data. Two rules matter. First, work on a copy: image the whole disk onto a different disk, and run the recovery on the image. GNU ddrescue does this, copying the readable parts first (ddrescue manual). Second, never save recovered files to the disk you are recovering from. If the files were on the disk the computer runs from, shut it down and do the imaging from a USB stick with a live Linux on it.
lsblk
sudo ddrescue /dev/sdX /media/usb/disk.img /media/usb/disk.map
The disk you lost files on comes first, the image second. Check which disk is which with lsblk before you run it: swapping the two writes over the disk you are trying to save.
PhotoRec is free for Linux, Mac and Windows. It ignores the file system and finds files by their known headers, so it works on a damaged disk, but the files come back without their names. Its page says: you must not choose to write the recovered files to the same partition they were stored on.
Source: PhotoRec.
On an SSD this often finds little: the drive may erase deleted blocks soon after the delete. The author of issue 112961 reports exactly that: The disk is an NVMe SSD with TRIM, so undelete tools could not help.
On Linux, many systems trim once a week; sudo systemctl stop fstrim.timer holds that off while you work.
Why it happens
An agent runs many commands quickly, and a delete is only as safe as the path it is given. The public reports follow a few patterns.
- A path that resolves to the project root. In issue 112961 (Nov 2026), a helper script built its work folder from part of a path, the part was
.., and itsrmtreedeleted about 3,500 files, almost the whole project. - A recursive delete that reaches the home folder. In issue 10077 (Oct 2025), an
rm -rfdeleted every user-owned file in a home directory on WSL2. The exact command was never captured; a~expanded after the permission check is a community guess, not a finding (MakerChecker's write-up). - A cleanup that goes one level too far. In issue 29082 (Feb 2026), an
rm -rfduring Flutter work deleted the project folder. - Links followed into live files. One account, which the MIT AI Incident Tracker notes has not been independently verified, says a sub-agent followed Windows directory junctions into a live project and deleted about 48,000 files and the Git object store in 103 seconds.
For next time
We make ScriptKitty, a small background service that keeps an old copy of each file before it is deleted or changed. It keeps copies from the moment it is installed, so it is for next time. With it underneath, most of the above becomes sk back 10m, which puts things back as they were ten minutes ago, or sk back to a bookmark, which is exact. See the morning after for every way back.
We asked Claude Code twice, on the same test machine, to clean up a project hard, and then: Wait, I needed those. Can you put it back?
The first time, the agent was not told about ScriptKitty. It searched for backups, reset git and said: I got some of it back, but most of what I deleted is gone for good.
The second time, ScriptKitty's hook had told it the bookmark saved before it started. It ran sk back m448112 --only /home/dev/shop, which answered Put back 242 files (22.0 MB) and 5 folders in 4.1 s.
, and the agent said: Nothing was lost.
Both runs, with prompts and transcripts.
On 14 Nov, in another test run, Claude Code cleaned up a git project holding a database, a dump, uploads and logs, and deleted or changed 242 entries. After one sk back to the minute before it started, all 296 files were hashed and compared with how they were before: none differed. The run's files.
In a third run, an agent spent under two minutes trying to get a folder under 5 MB while we ran sk back about every 10 seconds behind its back. The file kept coming back. Its report: Something on the box keeps restoring that file. I couldn't find what
. The haunted run. Or be the agent yourself in rm -rf Simulator, a 60-second browser game.
It is free and open source, for Linux and Windows. On Linux, from the source folder, the first line installs and starts the service, and the second adds the hook that tells Claude Code the bookmark:
sudo ./install.sh
python3 integrations/agent/sk_agent.py install claude