- Agent
- Claude Code
- Filed
- Case no.
- gh-anthropics-sclaude-hcode-s102901
Claude Code ran find -delete with an empty path and wiped a git checkout
Received Oct 17, 2026, 2:31 AM UTC
Deny rules on rm don't catch find -delete. Guard every deletion target with a literal path or "${T:?}", and keep an off-machine mirror.
Agents repeating the same mistakes? Scout gives every agent one current, shared record.
What happened
Exhibit AGitHub issue
**Bug Description**
Data loss: Claude ran `find $T -type f -delete` with $T empty and deleted an entire git checkout
Environment: Claude Code 2.1.300, model claude-opus-5-5, Arch Linux, Bash sandbox on, bypass-permissions mode.
Session b11f8688-4b04-4527-ad68-47291902121f, tool call at 2026-10-17 02:08:18 UTC. The user agrees to share that session's transcript.
What happened
1. The previous tool call ran `... && cd /home/vtf/projects/homelab-ops && git add ... && git commit ...` (the repository root). The Bash tool keeps the cwd between calls.
2. In the next turn the model wrote commands with paths relative to a subdirectory (palworld-win/mods/PalMinimapLite), as if it were still there, and ended one call with:
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
3. Scripts/world.lua did not exist at the root, so luac failed. `&&` skipped only the assignment; the `;` chain went on with T unset.
4. Unquoted and empty, `find $T -type f -delete` became `find -type f -delete`, which defaults to `.`. It deleted every file in the repository (about 5,200 working files and the .git objects/refs). Only paths the sandbox mounts read-only (.git/hooks, .git/config, .claude/settings.local.json) survived.
5. Nothing in the user's request involved deleting anything. The data was recovered only because a NAS mirror (Syncthing) had not yet received the deletion and the last commit had been pushed.
Why this is more dangerous than one repository
- The user has NOPASSWD sudo. The same line under sudo, or with the cwd at /, would delete the system. Claude also runs commands as root on other hosts through `ssh host '...'`, where the local sandbox does not apply at all.
- Permission deny rules such as `Bash(rm -rf*)` and `Bash(rm -r *)` did not apply: the deletion was `find -delete`, and the target only became empty at run time.
- The Bash sandbox allowed it because the cwd is writable by design.
- The user's CLAUDE.md told the model to clean temp dirs with `find <dir> -type f -delete`. The model filled <dir> with a variable whose assignment could be skipped, so a cleanup instruction became the deletion.
Requests
1. Model behavior: never use a bare variable or command substitution as a deletion target. Use a literal absolute path or "${T:?}" (bash aborts when T is unset or empty). Create temp dirs on their own line with `|| exit 1`, never as `cmd && T=$(mktemp -d)` followed by `;` code that uses T. Track that an earlier `cd` moves the persistent cwd.
2. Claude Code: a built-in check, independent of permission mode, that blocks a Bash call that deletes (rm, find -delete / -exec rm, xargs rm, rsync --delete) when a target is an unguarded expansion, an implicit or relative cwd, /, a top-level or home directory, or a git checkout root. This also applies under sudo and inside ssh / bash -c strings.
3. Claude Code: show the model the current shell cwd when it differs from the project root or from the cwd of the previous turn, because the model lost track of it here.
Local mitigation: a PreToolUse hook now denies these patterns, including under sudo, inside ssh / bash -c strings and in heredocs fed to a shell.
**Environment Info**
- Platform: linux
- Terminal: Orca
- Version: 2.1.300
- Feedback ID: c1f0d208-cc03-444e-8ed1-99c3602db9edSource. Posted publicly by VTFLAB on GitHub (opens in a new tab). Quoted as posted; the title and lesson are Failwall's.