Claude Code deleted my files: how to get them back and stop it happening again
If Claude Code deleted files, stop the agent and stop writing to the disk, because every new write risks overwriting what was deleted. Then look in this order: Git, the rewind menu, the Trash and Time Machine. Rewind restores edits that Claude made with its file tools. A file that only Bash commands changed is not tracked, so Git is the way back for it.
A missing folder and a clean terminal feel final, but the next few minutes are usually enough to find out whether the files can come back. The steps below go in the order that costs you the least.
01What to do in the first ten minutes
- Stop the agent and stop using the Mac. Interrupt Claude and close the session so it cannot run another command. In one reported case the user saw the command running and interrupted it, but the files were already gone. Then do not install tools, clone repositories or build projects: every moment of use risks overwriting the deleted data for good.
- Check Git. If the project is a Git repository, the files may still be there as a saved copy. See the next section.
- Try the rewind menu if Claude edited the files with its own tools. Details are two sections down.
- Look in the Trash, then open Time Machine. If Time Machine is on, it keeps hourly, daily and weekly backups.
- Write down what happened. Note the time, the project folder and what Claude was asked to do. You will need it for the prevention steps at the end.
02Check Git first
Git keeps a copy of every file you ever committed (saved into the project history). If the deleted file was committed, one command brings it back:
git restore <file>Use the real path in place of <file>. Warning: this replaces the file in your folder with the saved copy, so any edits to that file that you never committed are lost. Name the files you want one by one. Git also removes a tracked path that does not exist in the saved copy, to match it, so do not run it on a whole folder as a guess. Older commits are covered on restore a deleted file in Git.
Files that were never committed are the hard case. If untracked files are removed, Git often cannot bring their content back. Some may still be in the Trash or a backup, so read restore untracked files and then go to the Mac steps below. If Claude ran git reset --hard rather than a delete, see undo a Git reset.
03What the rewind menu can and cannot bring back
Claude Code tracks the edits that Claude makes with its file editing tools. To undo them, run /rewind or its alias /undo to open the rewind menu. You can also press Esc twice when the prompt input is empty. The menu offers three choices: restore code and conversation, restore the conversation only, or restore code only. After a deletion you want the code-only option.
Warning: restoring code reverts file changes back to the point you pick. Later changes to those files go with it, including your own, so copy out what you still need first.
The limits matter here, because many deletions come from a shell command:
| What happened | Does rewind cover it? |
|---|---|
| Claude edited a file with its file tools | Yes, it tracks those edits |
| A file was changed only by Bash commands | No, it is not tracked; use Git |
| You edited files yourself, or another session did | Normally not captured |
| A subagent (a helper Claude started) edited files | Usually not captured |
| The session is old | Snapshots cover the 100 most recent checkpoints; file snapshots are deleted about 30 days after the session last saved one |
Checkpoints are saved with the conversation, so you can still use rewind after you resume a session. There is a longer guide on Claude Code checkpoints and a short one on undoing Claude Code changes.
04Trash, Time Machine and iCloud
Check the Trash even if you think the files were removed with a command. If an item is there, select it and choose File > Put Back. Put Back returns a file to its original location. If the Trash was already emptied, Apple warns that the items are permanently deleted. Terminal cannot recover an emptied Trash or files that bypassed the Trash.
Time Machine is the next stop. Open the folder that held the files, open Time Machine, select the items and click Restore. Restored items return to their original location. Spotlight can open Time Machine for you; it is in the Other folder. Even with no backup disk attached, local snapshots may let you recover earlier versions. They are created hourly, stored on the same disk and kept for up to 24 hours, or until the disk needs the space. So the first day matters. The full steps are on restore from Time Machine, and the wider list is on recover deleted files on a Mac. For an emptied Trash, see recover an emptied Trash.
If the folder lived in iCloud Drive, also check icloud.com/iclouddrive: choose Recently Deleted, select the files and choose Recover. Files stay there for 30 days, and files you removed permanently cannot be restored this way.
05If Claude deleted my home directory
Some reports describe much more than one project. In one GitHub issue, Claude Code ran a recursive delete that removed all user files in the reporter's home directory, on a Windows machine running Linux (WSL2), in October 2025. If you are in the same place, the order is the same: stop writing to the disk, then Time Machine, then iCloud and Git for individual projects.
A full restore is possible when you have a Time Machine backup. After macOS is reinstalled, Migration Assistant asks whether to transfer information from a Time Machine backup, and it can restore all your personal files, including apps and everything in your user account. Do not reinstall in a hurry, though. If you only lost some folders, restore those from Time Machine first.
One more fact explains why backups beat recovery tools. On an SSD, which every modern Mac has, a drive feature called TRIM makes recovery much harder. TRIM tells the drive to wipe freed space, so deleted data does not wait around to be found.
06Why Claude Code runs rm -rf
rm -rf is a shell command that deletes a folder and everything inside it without asking. OWASP calls the underlying problem excessive agency: damaging actions taken in response to unexpected, ambiguous or manipulated output from a model, whatever causes the malfunction. In plain terms, the agent was allowed to do more than the task needed. A recursive delete is one such action. For other ways an agent goes wrong, see when an AI agent goes rogue.
07How to stop Claude Code deleting files
Prevention is a set of layers, and none is a wall by itself.
- Know your mode. Since Claude Code v2.1.283, interactive terminal and VS Code sessions start in auto mode. In auto mode a separate model reviews each action before it runs, and by default it does not review
rmorrmdiron critical paths such asrm -rf ~. Manual mode, whose config value isdefault, asks before Bash commands except a built-in set of read-only ones. In the CLI, Shift+Tab switches modes. The permissions page lists all modes. - Skip the flag outside an isolated environment.
--dangerously-skip-permissionsis equivalent to--permission-mode bypassPermissions. Anthropic's docs say to use it only in isolated environments such as containers, VMs or dev containers without internet access. See dangerously-skip-permissions. - Commit before long sessions. A commit is a copy you can bring back with one command.
- Add a hook that blocks rm -rf. A hook is a script that Claude Code runs before a command. Anthropic's hooks guide has an example script that exits 2 to deny when the command contains
rm -rf. The setup is on Claude Code hooks. A deny rule does not match the same program when it is started by its full path or insidesh -c, so a hook or rule catches honest mistakes and is not a wall. - Know what the sandbox covers. The sandbox restricts what commands can touch. It is off by default, and it covers shell commands only; file tools, MCP servers and hooks run outside it.
Other tools have their own recovery features: Cursor deleted files, Codex or Gemini CLI, a lost database and the Replit case.
08Claude Code deleted files: what to remember
When Claude Code deleted files, the order is fixed: stop the session, stop writing to the disk, check Git, try rewind for tool edits, then the Trash and Time Machine. A commit before a long session is the cheapest insurance.
Rewind and backups bring files back afterwards; neither shows what ran on the Mac. To see which command did the deleting next time, Artificial Immunity's free, open-source core watches Claude Code sessions and program starts on your Mac and reports what it finds, without stopping anything.
FAQ
Can Claude recover deleted files?
Not by asking it. Its own recovery tool is the rewind menu (/rewind), which undoes edits made with Claude's file tools. For a file that only Bash commands changed, Git is the way back.
How to prevent Claude Code from deleting files?
Use manual mode, which asks before Bash commands except a built-in set of read-only ones. Commit before long sessions. Do not use --dangerously-skip-permissions outside an isolated environment.
Why did Claude delete my projects?
OWASP calls this excessive agency: damaging actions taken in response to unexpected, ambiguous or manipulated model output, whatever causes the malfunction. In one GitHub report, the reporter says Claude ran a recursive delete in the home directory.
Where does Claude Code save files?
Your project files stay in your project folder. Session transcripts are stored locally in plain text under ~/.claude/projects/ for 30 days by default. Checkpoints are saved with the conversation, and their file snapshots are deleted about 30 days after the session last saved one.
Did Claude delete everything?
Check before you assume. A user report on GitHub says all files in the home directory were deleted. In your case only the disk can tell you, so look in Git, the Trash and Time Machine first.
Where is my Claude folder located?
The local session transcripts are in ~/.claude/projects/. Your project files are not in that folder.
Where did my deleted folder go?
Check the Trash first: Put Back returns an item to its original location. If the Trash was emptied, the items are permanently deleted, and Time Machine is the next place to look.
Related guides
Sources
- Claude Code docs, checkpointing
- Claude Code docs, permission modes
- Claude Code docs, sandboxing
- Claude Code docs, hooks guide
- Claude Code docs, data usage
- GitHub issue 10077, anthropics/claude-code
- Git documentation, git-restore
- Pro Git, stashing and cleaning
- Apple Support, empty the Trash
- Apple Support, back up with Time Machine
- Apple Support, restore files
- Apple Support, iCloud Drive recovery
- CleverFiles, recover files with Terminal
- OWASP LLM06 2025, Excessive Agency
- Artificial Immunity