Skip to content
Back to skills

Hook Block Commands

FSecurity

Pattern guide for writing PreToolUse hooks that block dangerous shell commands. Use when: building or auditing a guard-destructive hook, adding new blocked patterns, reviewing what the current hook covers. Covers 3 safety levels (critical/high/strict) and 58+ regex patterns. Inspired by: karanb192/claude-code-hooks block-dangerous-commands pattern (MIT).

  • 10 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 9, 2026
ai-agentsgoshellbashdockerawsgit

Security analysis

F20/100
  • criticalPipes output to a shell interpreter
  • criticalAccesses sensitive system or user directories
  • highPerforms destructive filesystem operations
  • highCreates or modifies cron jobs for persistent execution

Pro shows the line behind each finding and how to fix it

Scanned September 9, 2026

npx -y skills add yanacuti1121/Yana-AI --skill hook-block-commands --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Hook Block Commands?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Hook Block Commands
[![Security: F β€” Skills Directory](https://www.skillsdirectory.com/api/skills/yanacuti1121-hook-block-commands/badge)](https://www.skillsdirectory.com/skills/yanacuti1121-hook-block-commands)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: "hook-block-commands"
description: "Pattern guide for writing PreToolUse hooks that block dangerous shell commands. Use when: building or auditing a guard-destructive hook, adding new blocked patterns, reviewing what the current hook covers. Covers 3 safety levels (critical/high/strict) and 58+ regex patterns. Inspired by: karanb192/claude-code-hooks block-dangerous-commands pattern (MIT)."
---

# 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 $HOME`
- `mkfs.*`, `dd if=.* of=/dev/`
- `shred`, `wipe`

### Git destructive
- `git push.*--force.*main`, `git push.*-f.*main`
- `git reset --hard`, `git clean -fdx`, `git filter-branch`
- `git reflog expire`

### System/process
- `:(){:|:&};:` (fork bomb)
- `chmod -R 777`, `chmod 777 /`
- `sudo rm`, `sudo chmod`

### Secret exposure
- `cat ~/.aws/credentials`, `cat .env`
- `echo $.*TOKEN`, `env | grep.*KEY`
- Piping secrets to curl/netcat

### Exfiltration
- `curl.*upload`, `scp.*`, `rsync.*remote`
- `nc.*<IP>`, `netcat.*`

## Hook exit codes

```bash
exit 0  β†’ allow (no output)
exit 2  β†’ block (JSON reason on stdout)
```

## Blocking response format

```json
{
  "decision": "block",
  "reason": "🚫 Blocked: rm -rf on home directory. Safety level: high."
}
```

## Adding new patterns to guard-destructive.sh

1. Identify the pattern category (filesystem / git / system / secret / exfiltration)
2. Write a regex that matches the dangerous form but not safe variants
3. Add to the correct safety level block
4. Add a test case to `core/tests/hooks/run-hook-tests.sh`
5. Update hook `# Last Reviewed:` date

## Reference

YAMTAM hook: `core/hooks/guard-destructive.sh`
Tests: `core/tests/hooks/run-hook-tests.sh`

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.