
Writing Hookify Rules
- 10.6k installs
- 139k repo stars
- Updated July 25, 2026
- anthropics/claude-code
Step-by-step process to author markdown-based pattern-matching rules that trigger warnings or block Claude agent actions.
About
Writing Hookify Rules teaches developers how to create markdown-based rules that monitor Claude agent tool use and enforce guardrails. Rules are stored as .claude/hookify.{name}.local.md files with YAML frontmatter defining event type (bash, file, stop, prompt, all), regex patterns, and optional actions (warn or block). Developers use this skill when setting up safety checks for dangerous commands (rm -rf, sudo), code patterns (console.log, eval), sensitive files (.env, .pem), or completion workflows. Rules match against command text, file paths, new content, or user prompts using regex or substring operators, then display markdown messages to the agent. Dynamic reloading allows instant iteration without restarting.
- Five event types: bash (shell commands), file (edits/writes), stop (completion), prompt (user input), all (any event)
- Pattern matching via regex or conditions with operators: regex_match, contains, equals, not_contains, starts_with, ends_
- Actions: warn (allow + message) or block (prevent operation or halt session)
- YAML frontmatter with required fields: name, enabled, event; optional: action, pattern, conditions
- Rules stored as .claude/hookify.{name}.local.md; dynamically reloaded on next tool use
Writing Hookify Rules by the numbers
- 10,580 all-time installs (skills.sh)
- +328 installs in the week ending Jul 28, 2026 (Skillselion tracking)
- Ranked #77 of 16,659 AI & Agent Building skills by installs in the Skillselion catalog
- Security screen: LOW risk (skills.sh audit)
- Data as of Jul 28, 2026 (Skillselion catalog sync)
writing hookify rules capabilities & compatibility
- Capabilities
- define regex based pattern rules for bash comman · match file edits by path, content, or changes · trigger on user prompts and agent stop events · block operations or warn with markdown messages · support multi condition rules with logical and
- Use cases
- security audit · debugging · testing · code review
- Platforms
- macOS · Windows · Linux
- Runs
- Runs locally
- Pricing
- Free
What writing hookify rules says it does
Hookify rules are markdown files with YAML frontmatter that define patterns to watch for and messages to show when those patterns match.
npx skills add https://github.com/anthropics/claude-code --skill writing-hookify-rulesAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 10.6k |
|---|---|
| repo stars | ★ 139k |
| Security audit | 3 / 3 scanners passed |
| Last updated | July 25, 2026 |
| Repository | anthropics/claude-code ↗ |
What it does
Define pattern-matching rules that trigger messages or block Claude agent actions during bash commands, file edits, or session events.
Who is it for?
Enforcing project-specific safety guardrails, blocking dangerous commands, warning about debug code leaks, and validating completion steps before agent stops.
Skip if: Real-time log analysis, post-deployment security scanning, or policies requiring manual approval workflows.
When should I use this skill?
Setting up a new Claude-powered project, onboarding agents to a codebase with safety requirements, or preventing specific failure modes observed during development.
What you get
Rules automatically intercept and warn/block problematic tool use, with instant reload on file save and zero performance overhead.
- One or more .claude/hookify.{name}.local.md rule files
- Regex patterns matching project hazards
- Markdown messages displayed to agent
By the numbers
- Five event types supported: bash, file, stop, prompt, all
- Six condition operators available: regex_match, contains, equals, not_contains, starts_with, ends_with
- Two action modes: warn (default) or block
Files
Writing Hookify Rules
Overview
Hookify rules are markdown files with YAML frontmatter that define patterns to watch for and messages to show when those patterns match. Rules are stored in .claude/hookify.{rule-name}.local.md files.
Rule File Format
Basic Structure
---
name: rule-identifier
enabled: true
event: bash|file|stop|prompt|all
pattern: regex-pattern-here
---
Message to show Claude when this rule triggers.
Can include markdown formatting, warnings, suggestions, etc.Frontmatter Fields
name (required): Unique identifier for the rule
- Use kebab-case:
warn-dangerous-rm,block-console-log - Be descriptive and action-oriented
- Start with verb: warn, prevent, block, require, check
enabled (required): Boolean to activate/deactivate
true: Rule is activefalse: Rule is disabled (won't trigger)- Can toggle without deleting rule
event (required): Which hook event to trigger on
bash: Bash tool commandsfile: Edit, Write, MultiEdit toolsstop: When agent wants to stopprompt: When user submits a promptall: All events
action (optional): What to do when rule matches
warn: Show message but allow operation (default)block: Prevent operation (PreToolUse) or stop session (Stop events)- If omitted, defaults to
warn
pattern (simple format): Regex pattern to match
- Used for simple single-condition rules
- Matches against command (bash) or new_text (file)
- Python regex syntax
Example:
event: bash
pattern: rm\s+-rfAdvanced Format (Multiple Conditions)
For complex rules with multiple conditions:
---
name: warn-env-file-edits
enabled: true
event: file
conditions:
- field: file_path
operator: regex_match
pattern: \.env$
- field: new_text
operator: contains
pattern: API_KEY
---
You're adding an API key to a .env file. Ensure this file is in .gitignore!Condition fields:
field: Which field to check- For bash:
command - For file:
file_path,new_text,old_text,content operator: How to matchregex_match: Regex pattern matchingcontains: Substring checkequals: Exact matchnot_contains: Substring must NOT be presentstarts_with: Prefix checkends_with: Suffix checkpattern: Pattern or string to match
All conditions must match for rule to trigger.
Message Body
The markdown content after frontmatter is shown to Claude when the rule triggers.
Good messages:
- Explain what was detected
- Explain why it's problematic
- Suggest alternatives or best practices
- Use formatting for clarity (bold, lists, etc.)
Example:
⚠️ **Console.log detected!**
You're adding console.log to production code.
**Why this matters:**
- Debug logs shouldn't ship to production
- Console.log can expose sensitive data
- Impacts browser performance
**Alternatives:**
- Use a proper logging library
- Remove before committing
- Use conditional debug buildsEvent Type Guide
bash Events
Match Bash command patterns:
---
event: bash
pattern: sudo\s+|rm\s+-rf|chmod\s+777
---
Dangerous command detected!Common patterns:
- Dangerous commands:
rm\s+-rf,dd\s+if=,mkfs - Privilege escalation:
sudo\s+,su\s+ - Permission issues:
chmod\s+777,chown\s+root
file Events
Match Edit/Write/MultiEdit operations:
---
event: file
pattern: console\.log\(|eval\(|innerHTML\s*=
---
Potentially problematic code pattern detected!Match on different fields:
---
event: file
conditions:
- field: file_path
operator: regex_match
pattern: \.tsx?$
- field: new_text
operator: regex_match
pattern: console\.log\(
---
Console.log in TypeScript file!Common patterns:
- Debug code:
console\.log\(,debugger,print\( - Security risks:
eval\(,innerHTML\s*=,dangerouslySetInnerHTML - Sensitive files:
\.env$,credentials,\.pem$ - Generated files:
node_modules/,dist/,build/
stop Events
Match when agent wants to stop (completion checks):
---
event: stop
pattern: .*
---
Before stopping, verify:
- [ ] Tests were run
- [ ] Build succeeded
- [ ] Documentation updatedUse for:
- Reminders about required steps
- Completion checklists
- Process enforcement
prompt Events
Match user prompt content (advanced):
---
event: prompt
conditions:
- field: user_prompt
operator: contains
pattern: deploy to production
---
Production deployment checklist:
- [ ] Tests passing?
- [ ] Reviewed by team?
- [ ] Monitoring ready?Pattern Writing Tips
Regex Basics
Literal characters: Most characters match themselves
rmmatches "rm"console.logmatches "console.log"
Special characters need escaping:
.(any char) →\.(literal dot)()→\(\)(literal parens)[]→\[\](literal brackets)
Common metacharacters:
\s- whitespace (space, tab, newline)\d- digit (0-9)\w- word character (a-z, A-Z, 0-9, _).- any character+- one or more*- zero or more?- zero or one|- OR
Examples:
rm\s+-rf Matches: rm -rf, rm -rf
console\.log\( Matches: console.log(
(eval|exec)\( Matches: eval( or exec(
chmod\s+777 Matches: chmod 777, chmod 777
API_KEY\s*= Matches: API_KEY=, API_KEY =Testing Patterns
Test regex patterns before using:
python3 -c "import re; print(re.search(r'your_pattern', 'test text'))"Or use online regex testers (regex101.com with Python flavor).
Common Pitfalls
Too broad:
pattern: log # Matches "log", "login", "dialog", "catalog"Better: console\.log\(|logger\.
Too specific:
pattern: rm -rf /tmp # Only matches exact pathBetter: rm\s+-rf
Escaping issues:
- YAML quoted strings:
"pattern"requires double backslashes\\s - YAML unquoted:
pattern: \sworks as-is - Recommendation: Use unquoted patterns in YAML
File Organization
Location: All rules in .claude/ directory Naming: .claude/hookify.{descriptive-name}.local.md Gitignore: Add .claude/*.local.md to .gitignore
Good names:
hookify.dangerous-rm.local.mdhookify.console-log.local.mdhookify.require-tests.local.mdhookify.sensitive-files.local.md
Bad names:
hookify.rule1.local.md(not descriptive)hookify.md(missing .local)danger.local.md(missing hookify prefix)
Workflow
Creating a Rule
1. Identify unwanted behavior 2. Determine which tool is involved (Bash, Edit, etc.) 3. Choose event type (bash, file, stop, etc.) 4. Write regex pattern 5. Create .claude/hookify.{name}.local.md file in project root 6. Test immediately - rules are read dynamically on next tool use
Refining a Rule
1. Edit the .local.md file 2. Adjust pattern or message 3. Test immediately - changes take effect on next tool use
Disabling a Rule
Temporary: Set enabled: false in frontmatter Permanent: Delete the .local.md file
Examples
See ${CLAUDE_PLUGIN_ROOT}/examples/ for complete examples:
dangerous-rm.local.md- Block dangerous rm commandsconsole-log-warning.local.md- Warn about console.logsensitive-files-warning.local.md- Warn about editing .env files
Quick Reference
Minimum viable rule:
---
name: my-rule
enabled: true
event: bash
pattern: dangerous_command
---
Warning message hereRule with conditions:
---
name: my-rule
enabled: true
event: file
conditions:
- field: file_path
operator: regex_match
pattern: \.ts$
- field: new_text
operator: contains
pattern: any
---
Warning messageEvent types:
bash- Bash commandsfile- File editsstop- Completion checksprompt- User inputall- All events
Field options:
- Bash:
command - File:
file_path,new_text,old_text,content - Prompt:
user_prompt
Operators:
regex_match,contains,equals,not_contains,starts_with,ends_with
Related skills
How it compares
Use writing-hookify-rules for declarative regex guardrails in Claude Code sessions rather than full programmatic hook scripts.
FAQ
Where do I store hookify rules?
In the project root at .claude/hookify.{descriptive-name}.local.md. Add .claude/*.local.md to .gitignore.
When do rule changes take effect?
Immediately on the next agent tool use (bash, file edit, prompt, or stop). No restart needed.
Can I prevent an operation or just warn?
Both: action: warn (default) shows a message; action: block prevents the operation (for bash/file) or halts the session (for stop).
Is Writing Hookify Rules safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.