Writing Hookify Rules
AnthropicOfficialPublished by Anthropic
- Skill
- Guidelines
- Automation and integrations
- Apache-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
Hookify allows you to define custom rules that monitor an agent's interactions with bash commands, file edits, stop events, and user prompts. By creating markdown files with YAML frontmatter in the .claude directory, you can trigger warnings or blocks based on specific patterns, helping to enforce best practices, prevent dangerous operations, or provide context-aware reminders during a session.
What it does
- Defines patterns to watch for in bash commands, file edits, and user prompts.
- Supports simple regex-based matching or complex multi-condition logic.
- Allows for custom warning messages to be displayed when a rule is triggered.
- Enables blocking of specific operations to prevent errors or security risks.
- Provides a mechanism for completion checklists before an agent stops.
- Uses dynamic loading so rules take effect immediately upon file creation or update.
When to use it
- When you need to prevent the execution of dangerous bash commands like rm -rf.
- When you want to warn developers about committing debug code like console.log.
- When you need to enforce project-specific workflows or checklists before stopping.
- When you want to restrict edits to sensitive files like .env or configuration files.
- When you need to provide guidance or reminders based on specific user prompts.
Advantages
- Highly flexible configuration using standard markdown and YAML.
- Rules are stored locally within the project for easy version control.
- Supports both simple regex and advanced multi-condition logic.
- Immediate feedback loop without needing to restart the agent.
- Non-destructive; rules can be toggled via the enabled flag.
Usage examples
- “Create a hookify rule to warn me whenever I try to use the rm -rf command.”
- The agent will generate a .claude/hookify.warn-rm-rf.local.md file with the appropriate bash event and regex pattern to trigger a warning.
- “How do I block edits to my .env file that include an API_KEY?”
- The agent will provide a multi-condition rule template that checks both the file_path and the new_text fields to block the edit.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/anthropics/writing-hookify-rules/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip writing-hookify-rules.zip -d .agents/skills
Documentation by Anthropic
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-logBe 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 checkFor bash:
commandFor 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 check
pattern: 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=,mkfsPrivilege 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*=,dangerouslySetInnerHTMLSensitive 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\\sYAML unquoted:
pattern: \sworks as-isRecommendation: 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
Identify unwanted behavior
Determine which tool is involved (Bash, Edit, etc.)
Choose event type (bash, file, stop, etc.)
Write regex pattern
Create
.claude/hookify.{name}.local.mdfile in project rootTest immediately - rules are read dynamically on next tool use
Refining a Rule
Edit the
.local.mdfileAdjust pattern or message
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:
commandFile:
file_path,new_text,old_text,contentPrompt:
user_prompt
Operators:
regex_match,contains,equals,not_contains,starts_with,ends_with
Files
- ATTRIBUTION.mdAdded by AutoGineer960 B
- LICENSELicence file added by AutoGineer11.1 KiB
- SKILL.md8.2 KiB
Requirements and compatibility
Written for: Claude Code, Claude apps
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Names Claude Code tools, Needs an API key, Needs Python
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- Anthropic
- Publisher
- Anthropic (Official)
- Source
- anthropics/claude-plugins-official · plugins/hookify/skills/writing-rules · commit 0412be7
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from plugins/hookify/LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Anthropic or Anthropic.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download writing-hookify-rules.zip