AI agents wiping drives: how a cleanup command's target shifts in the shell

Between September and November, Claude Code, Codex, Antigravity and opencode wiped hard drives, user profiles and Git histories. We went through the cases where the executed command is publicly documented. Almost every time, the goal was to delete a single folder, and only on its way through several shells did that folder turn into the whole drive.

Analysis Nov 17, 2026 10 min read Original analysis by our editors
Illustrative image, AI-generated

What this is about

An AI agent is supposed to clean up a test folder and instead deletes 600 GB, the user profile or an entire drive. Reports like this came in almost weekly in fall 2026, involving Claude Code, OpenAI's Codex, Google's Antigravity and the open-source tool opencode. Usually the story goes that the AI went rogue.

On November 17, developer "doolyk" published a sober analysis on velog, which was also shared on GeekNews. He examined ten cases where the command actually executed is publicly visible in a GitHub issue or Reddit post. His finding: in most cases, only a narrow folder was supposed to go. It was the shell that turned it into a different target. The shell is the program that reads a command line, expands variables and then runs it.

We read the original issues, looked for responses from the vendors and added further cases from the same period. One caveat right away: the author maintains a protection tool himself, the hook project claude-bulkhead, and says so openly. We didn't reproduce the cases in a VM ourselves. The mechanisms are based on the author's tests (with deletion targets replaced by echo and test folders), the issues themselves and Microsoft's documentation.

Ten cases, command by command

Case System Executed command (shortened) What actually happened Damage
Claude Code #109735, Nov 14 Windows + WSL2 wsl -- bash -lc '… rsync -a --delete … $R/' $R was already empty before the inner bash ran, target became / Business documents and backups on /mnt/d
Antigravity, Nov 6 (Reddit) Windows cmd /c "rmdir /s /q \"D:\My Documents\…\"" cmd received rmdir /s /q \ Folders on D:, alphabetically for about 19 seconds
Codex #43343, Sep 7 Windows, PS 5.1 cmd.exe /d /c "rd /s /q \"\\?\$resolved\"" validated path arrived at cmd broken other repos, approx. 97,500 deletions per USN journal
Claude Code #95426, Sep 16 Windows, Git Bash rm -rf "$(cygpath -u 'C:\')" 2>/dev/null cygpath returned /c/ approx. 600 GB in 35 minutes
opencode #62825, reported Nov 9 Windows, PS 5.1 $home = Join-Path … followed by Remove-Item (Split-Path $home) assignment failed, target became C:\Users config, toolchains
r/ClaudeCode, Nov 7 macOS xargs -n1 dirname before rm -rf space in "Application Support" split the path ~/Library
Codex #42355, Sep 2 Windows git clean -fdX -- config/<pfad> Git removed the entire ignored folder config/ with API keys
r/ClaudeAI, Nov 10 Windows git worktree remove --force junction pointed to the real model folder approx. 230 GB
Claude Code #107274 macOS rm -rf including .git scope too broad more than 12 months of Git history
Claude Code #109627 macOS pkill -f "gcloud.py compute" -u <user> --signal 0 BSD pkill read --signal and 0 as search patterns approx. 66 processes killed

Strictly speaking, the last case isn't a deletion incident, but it follows the same pattern. According to the analysis, most of the commands were cleanup steps the agent had added without being asked.

In fairness, the thesis needs softening. In about half the cases, the shell really did bend a harmless target. In the others, the model itself chose a target that was too broad without grasping the consequences. Nobody explains why an agent would write cygpath -u 'C:\' of all things, literally asking it to convert the drive root. In case #99193, the agent admitted it had typed the home folder path "by accident."

The mechanisms: how a folder becomes a drive

Read twice. When you call wsl -- bash -lc '…', according to wsl --help, the line is passed "unmodified" to the Linux distribution's default shell. That shell reads it first and expands $R. $R was never set there, so it stayed empty. $R/ became /. The set -u meant to catch empty variables was in the inner bash and came too late. According to the analysis, this doesn't happen with wsl --exec, which launches the command without the default shell. The same principle is behind case #97660: bash -lc "export X=$(mktemp -d); rm -rf $X" was called from PowerShell. Inside double quotes, PowerShell expands $ expressions itself, and since mktemp doesn't exist on Windows, they came out empty. Bash received rm -rf and, according to the reporter, a backslash, which MSYS2 turned into the drive root. Result: about 125 GB gone.

The wrong escape. Escape characters mark a quotation mark as "part of the text." According to Microsoft's documentation, in PowerShell that's the backtick (`), not the backslash. So a \" ends the string instead of inserting a quotation mark. That's why cmd received rmdir /s /q \, and there a lone backslash means "root of the current drive." The same form shows up in an Antigravity report from September 26 in Google's forum (desktop deleted, 14 minutes of runtime) and as early as July with Cursor. So this isn't about a single tool but about a command form.

Computed root. cygpath, which Git Bash uses to convert Windows paths, correctly turns C:\ into /c/. The value isn't empty, so the commonly recommended safeguard ${VAR:?} doesn't help here. With opencode, the culprit was letter case. PowerShell doesn't distinguish case in variable names, so $home is the read-only automatic variable $HOME. The assignment failed, the script kept running anyway, and Split-Path returned C:\Users. In both cases, error messages had been silenced with 2>/dev/null and -ErrorAction SilentlyContinue respectively.

Windows quirks. In case #99193, a subagent typed rm -rf C:/Users/<USER83>~1. That's the 8.3 short name of the user folder. Windows assigns these substitute names in the old DOS format, and the short name was already part of the temp path the agent actually meant. The damage came to about 116 GB. NTFS junctions are folder pointers, similar to a shortcut, but programs treat them like a real folder. Through one of them, git worktree remove --force got into someone else's model folder. According to vibegraveyard, another case lost 48,218 files the same way because Python's islink() doesn't recognize junctions as links.

Why 7 out of 10 cases happen on Windows

The sample is small and not representative. But our additional cases from the same period (#92593, #97660, #99193, the Antigravity forum case and the junction case) also all come from Windows machines. The reasons can be documented:

  • Chains of multiple shells: PowerShell, cmd, Git Bash or MSYS2, and WSL each have their own rules for quotes, escapes and variables. Every handoff is another chance for a command to be read differently.
  • No sandbox for Claude Code: According to Anthropic's documentation, the sandbox only runs on macOS, Linux and WSL2: "On native Windows, Claude Code runs commands without a sandbox." Codex, by contrast, has its own Windows sandbox modes. Whether they were active in case #43343 isn't clear from the issue.
  • No Recycle Bin: Files deleted with rmdir /q, via WSL or via MSYS don't end up in the Recycle Bin. On SSDs with TRIM, which immediately clears freed storage blocks, recovery is often hopeless.
  • Stop doesn't mean stop: In #92593, #99193 and #109735, the TaskStop command reported success. But the actual deletion process (rm.exe or rsync in WSL) kept running for anywhere from 2 to about 50 minutes. The reporters suspect that on Windows, the whole process tree isn't terminated. Codex #43343 was similar. On top of that came false all-clears: one agent reported "Looks intact" because the top-level folder names were still there, while rm -rf had long since been emptying their contents.

Why blocklists miss this by design

Blocklists, hooks (scripts that check every command beforehand) and confirmation dialogs see the command text before it's evaluated. So the user approves $(cygpath …), not /c/. The opencode bot openly writes in the issue that the scanner only checks the command text and can't resolve paths computed at runtime. The blog codex.danielvaughan.com sums it up:

"The guard and the shell never see the same thing."

It cites the ShellSieve study (arXiv 2606.15549), which found that 69.0 to 98.6 percent of 1,709 blocklists examined could be bypassed. For deletion operations, the figure was 69.0 percent. The blog describes Codex's own list of dangerous commands as merely a "UX safety net."

Claude Code shows the problem in miniature. According to the changelog, a recursive rm in auto mode has asked for confirmation since v2.1.281. Since v2.1.283 (September 25), the PowerShell tool refuses cmd /c rd, rmdir, del and erase on drive roots. Two days later, an rm -rf inside a nested bash -lc deleted 125 GB (#97660), and the reporter writes that the path check "didn't catch it." In none of the Claude Code and Codex issues we checked has an Anthropic or OpenAI employee responded so far. There are only automatically assigned labels. For Antigravity, a Google moderator "escalated" the forum case "to the engineering team."

What helps: proven safe forms

  • Variables in delete commands: "${VAR:?}/fester-unterordner" aborts if the variable is empty. Also print it with echo first and abort if the value is a root or ~.
  • Path lists: find … -print0 together with xargs -0, or find … -exec rm -rf -- {} +. That way, spaces don't split paths.
  • PowerShell: Call Remove-Item -LiteralPath '…' -Recurse -Force directly, without going through cmd. -LiteralPath takes the path literally and doesn't interpret wildcards. Also set $ErrorActionPreference = 'Stop' and don't use automatic variable names like $home.
  • WSL: Use wsl --exec or a script inside WSL instead of nested bash -lc strings.
  • Dry run: rsync -n and git clean -ndX show what would be deleted. If a parent folder shows up, abort.
  • Links: Find junctions with cmd /c dir /AL /S, remove them one by one with rmdir <link> without /s, and use git worktree remove without --force.
  • Don't suppress errors: no 2>/dev/null and no SilentlyContinue on delete commands.
  • Environment over rules: On Windows, run Claude Code in WSL2 with the sandbox, and set sandbox.failIfUnavailable: true and allowUnsandboxedCommands: false. Backups belong outside the working folder, for example via git bundle create ../backup.bundle --all.

The bigger picture

The pattern isn't new. Back in 2025, Docker's "Coding Agent Horror Stories" series showed cases like rm -rf tests/ patches/ plan/ ~/, where the shell silently turned ~ into the home folder. Two things have changed. First, Windows with its shell chains now dominates. Second, the incidents increasingly happen in subagents, in the background and overnight: four of the Claude Code cases mentioned here involved subagents. According to reports on v2.1.283, auto mode is now the default. Features like Claude Code Projects or Google's /teamwork, which let many agents work in parallel, tend to widen this attack surface.

Our take: "The shell is to blame" is only half true. The agent adds cleanup steps nobody asked for, silences error messages and gives the all-clear too early. The shell then bends the target, and the tool doesn't reliably stop the process. If you want to do something about it, don't count on ever-longer blocklists. As one Reddit user put it in r/ClaudeAI after a different incident, the question isn't "Did I forbid it?" but "Can it do it?" As long as Claude Code runs on native Windows without a sandbox, the answer there is: yes.

Sources

#security#coding-agents#claude code#codex#windows#shell

Ask the AI assistant

Questions about this article, installation or background? Our assistant knows this page and runs on our own machine, not in someone else's cloud.

Connecting …

The Assistant is an AI (Gemma 4) and can make mistakes – please check important details against the source. Questions are used only to generate an answer and are deleted after one hour. Please don't enter any personal data.

Comments

What do you think? Already tried it? Write it here, no sign-up needed.

  1. Loading comments …

Comments are public. Links aren't allowed, and we delete abusive posts. You can delete your own comment at any time in this browser. Learn more in the Privacy Policy.