What it is
Writing Hookify Rules is a skill from the hookify plugin. It activates when a user asks to "create a hookify rule", "write a hook rule", "configure hookify" or "add a hookify rule", or needs guidance on hookify rule syntax and patterns. Hookify rules are markdown files with YAML frontmatter. Each one defines a pattern to watch for and a message to show when that pattern matches. Rules are stored as .claude/hookify.{rule-name}.local.md files.
Each rule needs three frontmatter fields:
- name: a unique kebab-case identifier that starts with a verb such as warn, prevent, block, require or check.
- enabled: true or false, so a rule can be toggled without deleting it.
- event: one of bash, file (Edit, Write, MultiEdit), stop, prompt or all.
The optional action field is either warn, which shows the message but allows the operation and is the default, or block. Block prevents the operation for PreToolUse events or stops the session for Stop events. Simple rules use a single Python-syntax regex pattern, which matches against the command for bash events or new_text for file events.
For more complex cases, the advanced format uses a conditions list, and all conditions must match for the rule to trigger. Each condition has three parts:
- field: command for bash; file_path, new_text, old_text or content for file; user_prompt for prompt.
- operator: regex_match, contains, equals, not_contains, starts_with or ends_with.
- pattern: the pattern or string to match.
The markdown body after the frontmatter is what Claude sees when the rule triggers. Good messages explain what was detected and why it is problematic, and suggest alternatives.
The skill also covers regex basics, escaping, common pitfalls (patterns that are too broad or too specific, and YAML escaping issues) and file organization. It describes a workflow for creating, refining and disabling rules. Rules are read dynamically on the next tool use, so changes take effect without any extra step. Example rule files ship in ${CLAUDE_PLUGIN_ROOT}/examples/.
Who it's for
- Claude Code users of the hookify plugin who want to create or configure hookify rules
- Developers who want warnings or blocks on dangerous Bash commands such as rm -rf, sudo or chmod 777
- Teams that want to catch debug code, security risks or edits to sensitive files like .env
- Users who want completion checklists or process reminders when the agent stops or when certain prompts are submitted
Requirements
Requirements
- Claude Code with the hookify plugin
- A
.claude/directory in the project root to hold rule files - Patterns written in Python regex syntax
هاد الـskill بيساعدك تكتب قواعد Hookify. هي ملفات markdown فيها YAML frontmatter بتراقب أنماط معيّنة بأوامر Bash أو تعديل الملفات أو لما يوقف الـagent أو برسائل المستخدم. وبتعرض لـClaude رسالة تحذير أو بتمنع العملية كلها.
Examples
Minimum viable rule
markdown---
name: my-rule
enabled: true
event: bash
pattern: dangerous_command
---
Warning message hereWhat it does: The simplest rule: watches Bash commands for a regex pattern and shows a warning message when it matches.
Advanced multi-condition rule for .env edits
markdown---
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!What it does: Triggers only when both conditions match: the edited file path ends in .env and the new text contains API_KEY.
Stop event completion checklist
markdown---
event: stop
pattern: .*
---
Before stopping, verify:
- [ ] Tests were run
- [ ] Build succeeded
- [ ] Documentation updatedWhat it does: Shows a checklist reminder whenever the agent wants to stop. Useful for enforcing process steps.
Testing a regex pattern
bashpython3 -c "import re; print(re.search(r'your_pattern', 'test text'))"What it does: Quickly checks whether a regex pattern matches sample text before you put it in a rule.