This site’s operator asked Claude Code to clean up a PC, and a script it created deleted the entire Windows user folder. This actually happened in November 2026 on a secondary PC belonging to this site's operator.

What happenedThe user folder was deleted

Sign-in stopped working, so the PC was reset and set up again.

Limits of the safeguardsChecks look at command text

The built-in deletion checks don't inspect deletion commands inside script files.

How to prevent itHave it show a list before deleting

Back up important PCs, and require confirmation before delegating deletion tasks.

Claude Code's safeguards were verified against the original official documentation on November 24, 2026. We have omitted information that could identify the PC or account involved.

This article walks through what happened, how Claude Code's deletion safeguards work and where they fall short, how to prevent this, and how the PC was made usable again after the files were deleted. The script that caused the problem was not preserved, so the explanation of the safeguards' limitations is based on what we could verify in the official documentation.

1. What happened

Circumstances of the incident

PC
A secondary laptop used only for watching videos (Windows 10; a model that cannot be upgraded to Windows 11)
Request
"Clean it up, including taking care of security"
Permission mode
Auto (auto). A model evaluates actions and proceeds with few or no confirmation prompts
What was deleted
The user folder inside C:\Users
Script responsible
It was deleted along with other files on the PC, so its contents are gone. The operator does not remember what was in it
  1. The cleanup script runs The script Claude Code created had a bug and deleted the entire user folder
  2. The PC starts behaving strangely The operator also deleted other remaining folders, such as Downloads
  3. Can't sign in with a new user either After creating a new user and restarting, sign-in failed with the error below, and the original user also disappeared from the sign-in screen
  4. Reset the PC From the recovery environment, selected "Reset this PC" and chose to remove everything, then reinstalled Windows (Chapter 5)
The User Profile Service service failed the sign-in.
User profile cannot be loaded.

This is the error shown on the English-language screen.

We believe the new user could not sign in because C:\Users\Default, which is used as the basis for creating new users, had also been deleted (the operator's inference). The original user's account was still listed among the accounts in the recovery environment.

Inside C:\UsersContentsWhat happens if it's deleted
Each user's folderDesktop, Documents, Downloads, and app settings (AppData)Files and settings saved in that folder are lost, and sign-in may be affected
DefaultTemplate used when creating a new userEven if you create a new user, you can't sign in as that user (what happened here)
PublicFiles shared among all usersShared Desktop and Documents folders are lost

User folders also contain browser sign-in state and app settings. The entire working environment on that PC is lost, not just the files.

This PC was not synced with a cloud drive (OneDrive, Google Drive, or Dropbox). If it had been, the deletion could have synced to the cloud and potentially deleted files on other PCs too (Chapter 4).

2. Deletion safeguards and their limitations

Claude Code has several safeguards to stop dangerous deletions. Built-in checks and deny rules inspect the text of commands Claude runs, while Auto mode relies on the judgment of an evaluation model. Script files are inspected only if you add a hook that you write yourself.

SafeguardWhen deletion is entered directlyDeletion inside a script file
Critical-path checks for rm (Bash)✓ Blocks rm and rmdir from deleting locations such as the home directory or drive root (in Auto mode, asks for confirmation in the terminal and denies it elsewhere)✕ Checks apply to rm and rmdir, and the official documentation notes that "other approved commands can still delete critical paths"
Remove-Item checks (PowerShell tool)✓ In every mode, denies deletion of your home directory, the drive root, or folders immediately under the root (such as C:\Users itself). Other folders inside C:\Users, including Default, are not on the official list✕ Checks apply to commands such as Remove-Item that Claude runs
deny rules✓ Stops a command if its text matches✕ The command being run (for example, the line that runs a script) does not contain the deletion command
hook (PreToolUse)△ Runs checks you write yourself against the text of the command it receives△ Receives the line that runs the command (you can add code to open and inspect the script file yourself)
Auto mode evaluation△ Blocks by default things like recursive deletion using a variable that might be empty△ Evaluates actions in the conversation, but the model may miss something
Sandbox✕ Not available in Claude Code running directly on Windows (only macOS, Linux, and WSL2)
/rewind✕ Cannot restore files deleted by commands or scripts (it records only Claude's file edits)

Sources: Choose a permission mode (Critical paths, Remove-Item in PowerShell, How auto mode evaluates actions), Configure permissions, Sandboxing, and Checkpointing.

The official documentation also warns that Auto mode "reduces confirmations but does not guarantee safety."

How an empty variable can broaden the deletion range (example)

The script from this incident was not preserved, so we cannot verify the cause. One way a cleanup script can end up deleting a parent folder is if the variable that should contain a folder name is empty.

How the deletion target is constructedWhen a name is presentWhen the name is empty
C:\Users\ + nameC:\Users\old-user (that user only)C:\Users\ (all user folders)
Working folder + name + \*Only the contents of that folderEverything in the working folder

This is an example; we have not verified that this is what caused the incident. Claude Code's official documentation also cites deleting a parent folder because of an empty variable as an example of a dangerous deletion.

3. How to prevent it

MeasureWhat to doHow it would have helped here
Have it show a list before deletingAsk it to "show me a list of the items to be deleted and the count first, then delete them after I confirm" (with commands such as PowerShell's Remove-Item, -WhatIf displays the targets without actually deleting them)There would have been an opportunity to check whether the targets included the entire user folder before running the command
Require confirmation for deletion tasksDon't delegate deletion tasks such as cleanup or organization in Auto or Bypass permissions modes. Use Manual (default) mode, and read the details of each command before Claude runs it. If there are only a few items to delete, you can also move them to the Recycle Bin yourself in File ExplorerThere would have been an opportunity to review the script before running it
Back up important PCsChoose a backup period based on how much data you could afford to lose. Back up to a separate drive that the cleanup task cannot write to, and test restoring from it once (cloud sync is not a substitute for a backup — Chapter 4)There was nothing on the secondary PC that would have been a problem to lose
Limit the working areaStart Claude Code in a working folder, and don't ask it to work across your home directory or all of C:\ (the instructions and launch location do not prohibit writes outside that area)"Clean up the entire PC" was too broad
Restrict write access through the OSTo use a sandbox on Windows, run Claude Code inside WSL2, enable the sandbox, and check the writable locations in the settings (official guidance)—

-WhatIf is a parameter you can add to commands such as Remove-Item (Remove-Item, Microsoft Learn). For differences between permission modes, see "Claude Code permission modes"; for how to write deny rules and hooks, see "Configuring permission rules" and "Claude Code hooks."

deny rules and hooks are not a "last line of defense." The official documentation says that Bash deny rules are "not a security boundary around a program." When asking Claude to create and run a script, the measures you can actually rely on are checking the list before deletion (and allowing deletion only from paths on the approved list) and keeping a backup that can restore the files afterward.

Example: How to ask for a cleanup

If you simply say "clean this up," Claude decides how much to delete. Specify the scope and steps in your request first.

I want to clean up .zip and .exe files in the Downloads folder whose last modified date is at least 90 days ago.
1. First, show me only a list of the files that might be deleted (path, size, last modified date) and the count. Don't delete anything.
2. After I review the list and say "OK," delete only the files on that list.
3. Don't touch any files or folders outside Downloads.
4. Don't permanently delete anything; move it to the Recycle Bin. If you can't move it to the Recycle Bin, stop without deleting anything.

The key is to specify the target folder, criteria, list review, and restriction against touching anything outside the scope in a single request. Broad requests such as "clean up the entire PC" or "clean it up, including taking care of security" leave Claude to decide what to delete.

What to check before running a script

Before running a script Claude created, look for the following lines, even if you can't read the whole script. If you don't understand something, ask Claude, "Explain exactly what this line deletes, using specific paths."

Look forDangerous patternWhat to check
Remove-Item, rm, del, rdIncludes -Recurse, -Force, or /sAre the targets limited to the folder you specified?
Variables that begin with $A variable is part of the path to the deletion targetWhere does the path point if the variable is empty?
*The path ends in \*Does this mean that everything in that folder will be deleted?
C:\, Users, USERPROFILEPoints to the drive root or home directoryIs it really necessary to operate on that location?

Before deleting, have it show only a list of candidates

For the first run, have it use a command that only lists the targets and contains no deletion operation. For example, for the request above, it would only display potential candidates as follows.

Get-ChildItem "$env:USERPROFILE\Downloads" -File -Recurse -Include *.zip, *.exe |
  Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-90) } |
  Select-Object FullName, Length, LastWriteTime

Ask it to perform the deletion separately after reviewing the list and approving it. At that point, instruct it to "use only the paths on the approved list; don't search for candidates again," and don't run the deletion if it uses any path that isn't on the list.

Guidelines for tasks that can be delegated in Auto mode

TaskDelegate in Auto modeReason
Reading, researching, and summarizing✓ A good fitRead-only actions don't need to be undone (a read-only request does not prohibit writes, so check if it proposes making changes)
Editing code in the working folder△ Only if there's a way to undo itYou can restore the previous state if it was recorded in Git or elsewhere before the work began (/rewind restores only changes made with Claude's editing tools)
Deleting, overwriting, or organizing✕ AvoidFiles deleted by commands or scripts cannot be restored with /rewind
Changing PC settings or security✕ AvoidThe effects can reach across the PC, making it hard to trace what changed afterward
Writing outside the working folder✕ AvoidExplicit instructions alone do not prevent writes outside the scope (don't delegate this if you can't restrict writable locations through the OS)

4. Cloud sync also syncs deletions

If it had been syncedThe impact could spread to other PCs

The deletion would sync to the cloud and remove the files from other PCs syncing the same folder.

In this caseThe impact was limited to this PC

It was not synced with a cloud drive.

Sync keeps the same state across devices, so it also propagates the state after files are deleted. Keep backups somewhere separate from the synced location and use a different method to create them.

5. How the PC was reset so it could be used again

On the PC where the user folder had been deleted, we could not sign in even after creating a new user. Since there was no data we needed to recover, the operator reset the PC.

What to check before resetting

Data you need to recover
If there is any, don't reset the PC. Resetting also deletes any data that remains
Recycle Bin
Items deleted by moving them to the Recycle Bin can be restored from there
Cloud
If the files were synced, check whether the service has a feature for restoring deleted files
Backups
Check how recent the backups on another drive or in your backup system are

The steps below are the ones the operator chose in this case.

  1. Open the recovery environment On the sign-in screen, hold Shift and select "Restart"
  2. Reset the PC Select "Troubleshoot" → "Reset this PC" → "Remove everything"
  3. Choose how to reinstall Select "Just remove my files" → "Cloud download" to reinstall Windows
  4. Limit how the PC is used Sign in only with a dedicated account for watching videos

We did not select "Keep my personal files." There was nothing to keep, and there was a risk of carrying over the broken user state. The on-screen labels are from the operator's Windows 10 installation. For the full set of recovery options, see Microsoft's "Windows recovery options."

If you have a backup

If you have a backup on another drive or in a backup system, you can restore your personal files from it after resetting the PC. The advice in Chapter 3 to back up important PCs is the most effective safeguard after files have been deleted.

6. Cautions about old PCs and tools that connect PCs

The PC involved was a Windows 10 model that could not be upgraded to Windows 11. Separately from the incident, the operator also reviewed how to secure this PC.

What was reviewedDetails
Windows 10 updatesSupport ended on October 14, 2025, but important security updates are available through October 12, 2027, if you enroll in the consumer Extended Security Updates (ESU) program (enroll by syncing settings, using Microsoft Rewards points, or paying $30)
Tools that connect PCsStopped connecting the PC to the main PC with PowerToys Mouse Without Borders, because clipboard sharing and file transfer were enabled
Home networkMove the PC to guest Wi-Fi so a vulnerable PC cannot be used as a foothold to access other devices
Sign-in accountsUse only a dedicated account for watching videos, and don't sign in with any other accounts

Source: Windows 10 Extended Security Updates (ESU) for consumers (Microsoft; the English version is Windows 10 Extended Security Updates).

Mouse Without Borders (Microsoft Learn) lets you turn clipboard sharing and file transfer on or off in its settings.

The ESU end date was verified against Microsoft's guidance on November 24, 2026.

Summary

Key points

What happened
A cleanup script created by Claude Code in Auto mode deleted the entire Windows user folder
Limits of the safeguards
By default, deletion checks, deny rules, and hooks inspect command text. Deletion inside script files is outside the scope of built-in checks
How to prevent it
Have it show a list and count before deleting, require confirmation for deletion tasks, and keep a backup of important PCs on a separate drive
Sync
Cloud sync can propagate deletions. Don't use it as a substitute for a backup
After files are deleted
Before resetting, check the Recycle Bin, cloud recovery options, and backups. In this case, there was nothing to recover, so the PC was reset

FAQ

Q. Doesn't Claude Code prevent user folders from being deleted?

Even for commands entered directly, the safeguards cover only the cases listed in the official documentation (see the table in Chapter 2 for differences by tool). They do not protect against every deletion, and built-in checks do not cover deletions inside script files.

Q. Should I stop using Auto mode?

You don't need to stop using it altogether. However, don't delegate deletion tasks such as cleanup or organization in Auto or Bypass permissions mode. Review the list of deletion targets before proceeding.

Q. Can I restore deleted files with Claude Code's /rewind?

No. /rewind records files changed using Claude's file-editing tools; files touched only by commands or scripts are not covered (see the official Checkpointing documentation). Check the Recycle Bin, cloud recovery features, and backups.

Q. Can the same thing happen on Mac or Linux?

Yes. On Mac and Linux, rm is also checked when it deletes locations such as the home directory that are listed in the official documentation, but deletions inside script files are likewise outside the checks. The difference is that you can enable the sandbox on Mac and Linux and use the OS to restrict where commands can write.

Q. Can a company prevent people from using Auto or Bypass permissions mode on work PCs?

Yes. Set permissions.disableAutoMode and permissions.disableBypassPermissionsMode to "disable" to make those modes unavailable. If an administrator adds these settings to managed settings that they distribute, users cannot override them (see the official Configure permissions documentation).

Sources

Update history

  • November 24, 2026Published.