Home / Errors / Claude Code / rm-rf-incident

Claude Code Deleted My Home Directory (the rm -rf Incident)

Claude Code Involved 1-3 hours if backups or snapshots exist; unrecoverable without them data risk Last verified Jul 17, 2026
The fix  Power down or stop all writes to that disk immediately: on SSDs with TRIM, deleted blocks get purged fast and the data is effectively unrecoverable. Your realistic recovery paths are APFS local snapshots (tmutil listlocalsnapshots /), Time Machine, cloud sync trash (iCloud, Dropbox, and Google Drive keep deleted files about 30 days), and re-cloning any repo you ever pushed.

Symptoms

  • You asked Claude Code to clean up a repo or organize folders and it executed an rm -rf whose arguments reached far beyond the project.
  • Documented worst case: 'rm -rf tests/ patches/ plan/ ~/', where the trailing ~/ expanded to the user's entire Mac home directory: Desktop, Documents, photos, Keychain.
  • Other reports include an rm -rf from root on Ubuntu/WSL2 and an 11GB deletion during a folder-organization benchmark.
  • Files are simply gone; on SSDs with TRIM, undelete tools find nothing.

Why it happens

Generation and execution happen in one step

The agent generates the rm command and the shell executes it in the same step. A hallucinated or pattern-matched extra path argument like '~/' becomes catastrophic because the shell expands ~ to your home directory before rm ever sees it.

A directory literally named '~'

In one variant (issue #12637), the agent created a directory named '~', then cleaned it up with an unquoted rm -rf ~, which the shell expanded to the real home directory.

The permission system did not catch it

In the October 2025 Wolak case (issue #10077), the default permission system failed to flag the destructive expansion; the user was not running --dangerously-skip-permissions. That flag makes things worse by removing even the per-command confirmation.

How to fix it

  1. Stop all writes to the disk right nowPower down or stop everything writing to the affected disk. On SSDs with TRIM, deleted blocks are purged fast, which is why undelete tools that work on spinning disks mostly come up empty here. This is a race you win in minutes, not hours.
  2. Check APFS local snapshots and Time Machine on macOSRun 'tmutil listlocalsnapshots /' to see whether APFS kept a local snapshot from before the deletion. Restore through Time Machine, including the 'Browse other backup disks' option, or from a full Time Machine backup if you have one.
  3. Restore from cloud sync trashiCloud Drive, Dropbox, and Google Drive keep deleted files for about 30 days. This is exactly how the January 2026 Claude Cowork photo-deletion victim recovered, so check every synced folder's deleted-items view before assuming the worst.
  4. Re-clone any repo that was ever pushedFor git repositories that were pushed to any remote, the code is safe on the server; re-clone from GitHub or wherever the remote lives. Honest note: anything that was only local, never snapshotted, and never synced is effectively unrecoverable on a TRIM-enabled SSD.

How to prevent it

  • Never run --dangerously-skip-permissions on your host machine. Use a container or sandbox (a devcontainer, or Docker sandboxes via 'sbx run claude') where the agent's ~/ is the workspace, not your real home directory.
  • Add deny rules in ~/.claude/settings.json permissions, for example "deny": ["Bash(rm -rf:*)"], and keep the default permission prompts on for Bash.
  • Run cleanup-type tasks ('clean up', 'organize', 'delete old files') in a fresh git worktree or throwaway sandbox and review the diff before merging.
  • Keep automatic backups (Time Machine or equivalent) running; they turn this incident from a catastrophe into an inconvenience.

Tools that actually fix this

Recommended because they address the failure mode above, not because of the payout. Some are affiliate links; see how we choose.

Frequently asked questions

Can files deleted by Claude Code's rm -rf be recovered from an SSD?

Usually not from the disk itself. On SSDs with TRIM, the drive purges deleted blocks quickly, so undelete tools rarely help. Your realistic recovery paths after a Claude Code rm -rf are APFS local snapshots, Time Machine, cloud sync trash (iCloud, Dropbox, and Google Drive keep deleted files about 30 days), and re-cloning any repo you pushed.

Is --dangerously-skip-permissions safe to use?

Not on your host machine. The --dangerously-skip-permissions flag removes even the per-command confirmation, so a single hallucinated path in an rm -rf runs unchecked. If you want that speed, run Claude Code inside a container or sandbox where its home directory is the disposable workspace, not your real one.

Can Claude Code delete files even with permission prompts turned on?

Yes, it has happened. In the October 2025 case tracked as claude-code issue #10077, the user was not running --dangerously-skip-permissions, and the default permission system failed to flag an rm -rf whose trailing ~/ expanded to the entire home directory. Prompts reduce the risk; they do not eliminate it.

How does a trailing ~/ end up in an rm -rf command?

The agent generates the command and the shell executes it in the same step, so a hallucinated or pattern-matched extra path argument like ~/ gets expanded by the shell to your home directory before rm ever sees it. In one variant (issue #12637), the agent created a directory literally named '~', then cleaned it up with an unquoted rm -rf ~.

Sources

Related errors

The Vibe Oops briefing

One email when something ships to production that should not have. New incidents, new error guides, no filler.