
Writing Hookify Rules
Author Claude Code hookify rules that warn or block risky bash, file edits, stops, and prompts via pattern-matched markdown in .claude/hookify.*.local.md.
Overview
Writing Hookify Rules is an agent skill most often used in Build (also Ship review, Operate iterate) that documents how to write Claude Code hookify pattern rules in .claude/hookify.*.local.md.
Install
npx skills add https://github.com/anthropics/claude-code --skill writing-hookify-rulesWhat is this skill?
- Defines YAML frontmatter: name, enabled, event, pattern, optional action warn|block
- Supports events bash, file, stop, prompt, and all
- Stores rules in .claude/hookify.{rule-name}.local.md with kebab-case action-oriented names
- Body markdown becomes the message shown when the regex pattern matches
- Toggle enabled without deleting rules for safe experimentation
- Five hook events: bash, file, stop, prompt, all
- Optional actions: warn (default) and block
Adoption & trust: 8.4k installs on skills.sh; 131k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You rely on ad-hoc reminders to stop Claude from risky bash, edits, or premature stops instead of enforced hook patterns.
Who is it for?
Solo builders standardizing Claude Code safety and quality hooks across projects with versioned local rule files.
Skip if: Non-Claude Code environments without hookify, or org-wide policy that must live in enterprise hooks outside local .claude files.
When should I use this skill?
The user asks to create a hookify rule, write a hook rule, configure hookify, add a hookify rule, or needs guidance on hookify rule syntax and patterns.
What do I get? / Deliverables
You get correctly formatted hookify rule files with events, regex patterns, and warn or block messages Claude sees when triggers match.
- .claude/hookify.{rule-name}.local.md rule file with frontmatter and trigger message
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Hook rules are configured while setting up the agent workspace, the primary shelf for Claude Code customization. Hookify is procedural guardrails on tool events—core agent-tooling, not application feature code.
Where it fits
Add a block rule on destructive git clean patterns while the agent refactors your repo.
Warn when the agent edits production config paths without an explicit user approval phrase.
Require a check hook on stop events so hotfix branches get a short verification message before the session ends.
How it compares
Use for declarative hookify markdown rules instead of unstructured 'remember not to…' instructions in every session.
Common Questions / FAQ
Who is Writing Hookify Rules for?
Indie developers and small teams using Claude Code who want documented, reusable hook rules for tool and prompt events.
When should I use Writing Hookify Rules?
In Build when configuring .claude hooks; in Ship when adding review or block rules before merge; in Operate when tightening guardrails on production repos—whenever someone asks to create or configure a hookify rule.
Is Writing Hookify Rules safe to install?
The skill only describes rule authoring; review Security Audits on this page and test block rules in a scratch repo so patterns do not break legitimate workflows.
SKILL.md
READMESKILL.md - Writing Hookify Rules
# 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 ```markdown --- 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 active - `false`: Rule is disabled (won't trigger) - Can toggle without deleting rule **event** (required): Which hook event to trigger on - `bash`: Bash tool commands - `file`: Edit, Write, MultiEdit tools - `stop`: When agent wants to stop - `prompt`: When user submits a prompt - `all`: 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:** ```yaml event: bash pattern: rm\s+-rf ``` ### Advanced Format (Multiple Conditions) For complex rules with multiple conditions: ```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! ``` **Condition fields:** - `field`: Which field to check - For bash: `command` - For file: `file_path`, `new_text`, `old_text`, `content` - `operator`: How to match - `regex_match`: Regex pattern matching - `contains`: Substring check - `equals`: Exact match - `not_contains`: Substring must NOT be present - `starts_with`: Prefix check - `ends_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:** ```markdown ⚠️ **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 builds ``` ## Event Type Guide ### bash Events Match Bash command patterns: ```markdown --- 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: ```markdown --- event: file pattern: console\.log\(|eval\(|innerHTML\s*= --- Potentially problematic code pattern detected! ``` **Match on different fields:** ```markdown --- event: file conditions: - field: file_path operator: regex_match pattern: \.tsx?$ - field: new_text operator: regex_match