STUPID-2026-0140

A Claude Code sub-agent's temp-dir cleanup chained `find $T -type f -delete` after a failed command that skipped only the `T=$(mktemp -d ...)` assignment, leaving `$T` unset and collapsing the find to the repo root, deleting ~5,200 files and the project's git history (GitHub #102901)

5.0medium
October 17, 2026Source checkedRepro reported

Why 5/10

About 5,200 files and the git history were deleted, but recovered from a NAS mirror and the remote. Luck, not a safeguard.

Scope
2/4
One project, repository, server or service, or a cost above roughly $10,000
Recoverability
1/3
Fully recovered, with effort
Did it happen
2/2
Happened in real use
Beyond the user
0/1
Only the user's own non-production work

The score is the sum of these four factors. How each factor is scored · scored 2026-10-29

Guardrail rules for this command

Recursive deletes: make your agent stop and ask before running these. Free to copy; written in each tool’s documented format.

Claude Code · the agent in this incident
{
  "permissions": {
    "ask": [
      "Bash(rm -r*)",
      "Bash(rm -fr*)",
      "Bash(rm -R*)",
      "Bash(find * -delete*)",
      "PowerShell(Remove-Item *)",
      "Bash(cmd /c rmdir *)",
      "Bash(cmd /c del *)"
    ]
  }
}
Add to .claude/settings.json in the project (or ~/.claude/settings.json for every project). Each matching command then asks you first, including in auto mode.

Stronger control: Turn on the sandbox (/sandbox): shell commands can then write only to the project, a temp folder and directories you add. It runs on macOS, Linux and WSL2; on native Windows Claude Code runs commands unsandboxed. Docs

Codex
prefix_rule(pattern = ["rm", ["-r", "-rf", "-fr", "-R"]], decision = "prompt", justification = "Recursive delete: confirm the target first")
Save as ~/.codex/rules/stupidllm.rules and restart Codex. Codex's docs describe rules as controlling commands run outside its sandbox, and mark them experimental.

Stronger control: Keep Codex's OS sandbox on (it limits writes, typically to the workspace) and leave approvals on for sessions that can reach data you cannot lose. Docs

Gemini CLI
[[rule]]
toolName = "run_shell_command"
commandPrefix = ["rm -r", "rm -fr", "rm -R"]
decision = "ask_user"
priority = 100
denyMessage = "Destructive command: needs a human to confirm (stupidllm.com)"
Save as ~/.gemini/policies/stupidllm.toml. Workspace-level policy files are disabled in Gemini CLI, so this must be the user-level folder.

Stronger control: Policies in ~/.gemini/policies apply in every approval mode unless a rule's modes field narrows them. Docs

Copilot CLI
copilot --deny-tool='shell(rm)'
Pass on the command line. Copilot CLI matches the program name (and git/gh subcommands), so this blocks the whole command, not just its dangerous form.

Stronger control: Avoid --allow-all-tools on a machine with data you cannot lose; --deny-tool takes precedence over it. Docs

What these cannot do: a pattern rule matches the command text the agent writes. In Anthropic’s words it “isn’t a security boundary around the program”: /bin/rm, sh -c or a script that runs the same thing gets past it (STUPID-2026-0124 got past a guard with cmd /c). Use the sandbox as well, and keep backups of what you cannot lose.

  1. Instruction given

    No deletion was requested. A background sub-agent was cleaning up a Lua test harness's temp output after running tests, following the user's own CLAUDE.md convention of `find <dir> -type f -delete` for temp-dir cleanup.

  2. Expected behavior

    Never run a deletion command against an unguarded, unquoted variable expansion that can resolve to empty; use `"${T:?}"` or an equivalent guard, create the temp directory on its own line with `|| exit 1`, and have Claude Code surface the shell's actual working directory to the model whenever it differs from the project root or the previous turn's cwd, rather than letting commands silently target the wrong path.

  3. Actual behavior

    A prior tool call had chained `cd /home/vtf/projects/homelab-ops && git add ... && git commit ...`, leaving the persistent bash shell's cwd at that repo root. The next turn built a command assuming the shell was still in a subdirectory (`palworld-win/mods/PalMinimapLite`): `luac5.4 -p Scripts/world.lua && T=$(mktemp -d $TMPDIR/pmh.XXXX); lua5.4 test/harness.lua $T > $T.out 2>&1; ...; find $T -type f -delete; find $T -depth -type d -empty -delete; rm -f $T.out`. Because `Scripts/world.lua` did not exist at the drifted cwd, `luac5.4` failed, and the `&&` before it skipped only the `T=$(mktemp ...)` assignment — the semicolon-separated commands after it still ran with `$T` unset. Unquoted and empty, `find $T -type f -delete` collapsed to `find -type f -delete`, which defaults to the current directory: the repository root.

  4. Damage

    Roughly 5,200 working files and the repository's `.git` objects and refs were deleted; only paths the sandbox mounted read-only (`.git/hooks`, `.git/config`, `.claude/settings.local.json`) survived. The user recovered the data only because a Syncthing NAS mirror had not yet synced the deletion and the latest commit had already been pushed to a remote — neither of which Claude Code's own safeguards provided. The reporter notes the same pattern would run unconstrained under their existing NOPASSWD sudo or inside the `ssh host '...'` calls Claude Code also issues, and that the built-in "dangerous rm" approval check never matched because the command uses `find -delete` rather than `rm`, and the target was only empty at runtime. Filed with labels `bug`, `area:bash`, `area:sandbox`, `data-loss`, `high-priority`, `platform:linux`; open with no maintainer response or linked fix as of filing.

Full write-up

On October 17, 2026, a Claude Code user on Arch Linux filed GitHub issue #102901 after a background cleanup step destroyed an entire git repository. Running Claude Code 2.1.300 with claude-opus-5-5 in bypass-permissions mode with the bash sandbox on, the model had just finished a cd /home/vtf/projects/homelab-ops && git add ... && git commit ... chain, which left the persistent shell's working directory at that repo's root. The next turn, still reasoning as though it were in a subdirectory several levels down, built a one-line test-and-cleanup command for a Lua mod: compile a script, run a test harness into a fresh temp directory, then wipe that temp directory — find $T -type f -delete — once done.

The compile step failed, because the script it was looking for didn't exist at the drifted working directory. That failure sat on the near side of an &&, which meant only the following T=$(mktemp -d $TMPDIR/pmh.XXXX) assignment was skipped; everything after the next semicolon ran anyway, including the cleanup line, with $T never set. Unquoted, an empty $T makes find $T -type f -delete equivalent to find -type f -delete with no path argument at all — which find defaults to the current directory. That directory was the repository root, so the command walked and deleted every file it found: roughly 5,200 working files, plus the .git directory's objects and refs. Only the handful of paths the sandbox mounted read-only survived.

The user recovered everything, but not because of anything Claude Code did right: a Syncthing mirror to a home NAS hadn't yet picked up the deletion, and the last commit had already been pushed to a remote. The reporter's bug report is explicit about why this isn't a one-off typo: the same unguarded-variable pattern would run unconstrained under their NOPASSWD sudo, or inside the unsandboxed ssh host '...' commands Claude Code also issues — and the product's own "dangerous rm" approval gate never triggered, because the command is find ... -delete, not rm, and its target string was only empty at runtime rather than visibly dangerous in the command text itself. The reporter asked for a built-in check, independent of permission mode, that blocks deletion commands whose target is an unguarded expansion, an implicit or relative cwd, or a git checkout root — under sudo and inside ssh/bash -c strings as well as bare shell. The issue was labeled data-loss and high-priority by automation on filing and remains open with no maintainer response or fix.

Classification

Failure mode
Destructive Action
Root cause
Tool Misuse
Domain
Infra
Language
Bash
OWASP Agentic Top 10 (our mapping)
ASI02 Tool Misuse and Exploitation list
MIT AI Risk Repository (our mapping)
7.3 Lack of capability or robustness taxonomy

Related incidents

Cite this record
StupidLLM. "STUPID-2026-0140: A Claude Code sub-agent's temp-dir cleanup chained `find $T -type f -delete` after a failed command that skipped only the `T=$(mktemp -d ...)` assignment, leaving `$T` unset and collapsing the find to the repo root, deleting ~5,200 files and the project's git history (GitHub #102901)." AI Agent Incident Database, 2026. https://www.stupidllm.com/incident/STUPID-2026-0140/ (accessed 2026-11-11). CC BY 4.0.

← STUPID-2026-0139By IDSTUPID-2026-0141 →

Get told when an agent breaks something

We document AI agent failures daily, severity-scored against a published scale. Each Monday, if any scored 7 or above that week — deleted data, leaked secrets, broken production — you get one email with the sources. When nothing did, you get nothing.

This database is callable over MCP — query it from inside your agent.