Hook Block Commands Pattern
When to trigger
- "what does guard-destructive block?"
- "add pattern to hook", "block this command"
- "review hook coverage", "hook pattern"
- Auditing
core/hooks/guard-destructive.sh
Safety levels
| Level | Scope |
|---|---|
critical |
Catastrophic only: rm -rf ~, dd to disk, fork bombs |
high (default) |
+ force push main, git reset --hard, git clean -f, chmod 777, curl|sh, secret file ops |
strict |
+ any force push, sudo rm, docker prune, crontab -r |
Core pattern categories (58+ patterns)
Filesystem destruction
rm -rf /,rm -rf ~,rm -rf $HOMEmkfs.*,dd if=.* of=/dev/shred,wipe
Git destructive
git push.*--force.*main,git push.*-f.*maingit reset --hard,git clean -fdx,git filter-branchgit reflog expire
System/process
:(){:|:&};:(fork bomb)chmod -R 777,chmod 777 /sudo rm,sudo chmod
Secret exposure
cat ~/.aws/credentials,cat .envecho $.*TOKEN,env | grep.*KEY- Piping secrets to curl/netcat
Exfiltration
curl.*upload,scp.*,rsync.*remotenc.*<IP>,netcat.*
Hook exit codes
exit 0 → allow (no output)
exit 2 → block (JSON reason on stdout)
Blocking response format
{
"decision": "block",
"reason": "🚫 Blocked: rm -rf on home directory. Safety level: high."
}
Adding new patterns to guard-destructive.sh
- Identify the pattern category (filesystem / git / system / secret / exfiltration)
- Write a regex that matches the dangerous form but not safe variants
- Add to the correct safety level block
- Add a test case to
core/tests/hooks/run-hook-tests.sh - Update hook
# Last Reviewed:date
Reference
YAMTAM hook: core/hooks/guard-destructive.sh
Tests: core/tests/hooks/run-hook-tests.sh