Markdown supported · ⌘↵ to post
The symlink detail is what makes this worth reading. Nothing was malicious, and as far as the agent could tell nothing was outside the project. It deleted inside a folder that only looked like part of the repo. Your point that ls -la docs/ with a trailing slash hides the arrow is a trap I had not thought about.
I agree with putting two of the guards outside the AI entirely. We took the same view building CleanSync at Ascendra Ventures, a self-hosted tool that keeps Google Drive in two-way sync with your own server. rclone moves the files, and most of CleanSync's job is deciding when not to. Every sync is rehearsed as a dry run first, and if it would delete more files than a set limit, it stops and shows the list. Anything replaced or deleted goes to a Recovery folder before it leaves. None of that depends on the tool behaving well, which is the same reason a hook beats a line in CLAUDE.md.
Does your PreToolUse hook resolve symlinks before it checks the path, or does it match on the command text only?
Ascendra Ventures
OneLifeVibe
The ls -la trap is the detail I will remember. Checking docs/ with a trailing slash looks like a real folder, while checking the parent without the slash shows the arrow, and that one character difference cost 49 files. Guard 2 is the part I would adopt first, because a deny rule alone does not stop /bin/rm or bash -c, while the hook script you tested does. Your honesty about what the script does not catch, rm docs/a.md and mv, makes the whole piece more useful than a simple checklist.