Rule Identifier
Create smart code rules that guide AI behavior and prevent mistakes
✨ The solution you've been looking for
This skill should be used when 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.
See It In Action
Interactive preview & real-world examples
AI Conversation Simulator
See how users interact with this skill
User Prompt
Create a hookify rule to warn when someone tries to run 'rm -rf' commands
Skill Processing
Analyzing request...
Agent Response
A rule file that detects dangerous deletion commands and shows a warning with safer alternatives
Quick Start (3 Steps)
Get up and running in minutes
Install
claude-code skill install rule-identifier
claude-code skill install rule-identifierConfig
First Trigger
@rule-identifier helpCommands
| Command | Description | Required Args |
|---|---|---|
| @rule-identifier prevent-dangerous-commands | Block potentially destructive bash commands before they execute | None |
| @rule-identifier code-quality-enforcement | Catch problematic code patterns like console.log in production files | None |
| @rule-identifier deployment-checklists | Ensure critical steps are completed before finishing tasks | None |
Typical Use Cases
Prevent Dangerous Commands
Block potentially destructive bash commands before they execute
Code Quality Enforcement
Catch problematic code patterns like console.log in production files
Deployment Checklists
Ensure critical steps are completed before finishing tasks
Overview
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
1---
2name: rule-identifier
3enabled: true
4event: bash|file|stop|prompt|all
5pattern: regex-pattern-here
6---
7
8Message to show Claude when this rule triggers.
9Can 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:
1event: bash
2pattern: rm\s+-rf
Advanced Format (Multiple Conditions)
For complex rules with multiple conditions:
1---
2name: warn-env-file-edits
3enabled: true
4event: file
5conditions:
6 - field: file_path
7 operator: regex_match
8 pattern: \.env$
9 - field: new_text
10 operator: contains
11 pattern: API_KEY
12---
13
14You'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
- For bash:
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:
1⚠️ **Console.log detected!**
2
3You're adding console.log to production code.
4
5**Why this matters:**
6- Debug logs shouldn't ship to production
7- Console.log can expose sensitive data
8- Impacts browser performance
9
10**Alternatives:**
11- Use a proper logging library
12- Remove before committing
13- Use conditional debug builds
Event Type Guide
bash Events
Match Bash command patterns:
1---
2event: bash
3pattern: sudo\s+|rm\s+-rf|chmod\s+777
4---
5
6Dangerous 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:
1---
2event: file
3pattern: console\.log\(|eval\(|innerHTML\s*=
4---
5
6Potentially problematic code pattern detected!
Match on different fields:
1---
2event: file
3conditions:
4 - field: file_path
5 operator: regex_match
6 pattern: \.tsx?$
7 - field: new_text
8 operator: regex_match
9 pattern: console\.log\(
10---
11
12Console.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):
1---
2event: stop
3pattern: .*
4---
5
6Before stopping, verify:
7- [ ] Tests were run
8- [ ] Build succeeded
9- [ ] Documentation updated
Use for:
- Reminders about required steps
- Completion checklists
- Process enforcement
prompt Events
Match user prompt content (advanced):
1---
2event: prompt
3conditions:
4 - field: user_prompt
5 operator: contains
6 pattern: deploy to production
7---
8
9Production deployment checklist:
10- [ ] Tests passing?
11- [ ] Reviewed by team?
12- [ ] 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:
1python3 -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:
1pattern: log # Matches "log", "login", "dialog", "catalog"
Better: console\.log\(|logger\.
Too specific:
1pattern: rm -rf /tmp # Only matches exact path
Better: 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
- 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 root - Test immediately - rules are read dynamically on next tool use
Refining a Rule
- Edit the
.local.mdfile - Adjust 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:
1---
2name: my-rule
3enabled: true
4event: bash
5pattern: dangerous_command
6---
7
8Warning message here
Rule with conditions:
1---
2name: my-rule
3enabled: true
4event: file
5conditions:
6 - field: file_path
7 operator: regex_match
8 pattern: \.ts$
9 - field: new_text
10 operator: contains
11 pattern: any
12---
13
14Warning message
Event 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
What Users Are Saying
Real feedback from the community
Environment Matrix
Dependencies
Context Window
Security & Privacy
Information
- Author
- anthropics
- Updated
- 2026-01-30
- Category
- productivity-tools
Related Skills
Rule Identifier
This skill should be used when the user asks to "create a hookify rule", "write a hook rule", …
View Details →Command Development
This skill should be used when the user asks to "create a slash command", "add a command", "write a …
View Details →Command Development
This skill should be used when the user asks to "create a slash command", "add a command", "write a …
View Details →