|
|
hai 4 días | |
|---|---|---|
| .. | ||
| .claude-plugin | hai 4 días | |
| agents | hai 4 días | |
| commands | hai 4 días | |
| core | hai 4 días | |
| examples | hai 4 días | |
| hooks | hai 4 días | |
| matchers | hai 4 días | |
| skills | hai 4 días | |
| utils | hai 4 días | |
| .gitignore | hai 4 días | |
| LICENSE | hai 4 días | |
| README.md | hai 4 días | |
Easily create custom hooks to prevent unwanted behaviors by analyzing conversation patterns or from explicit instructions.
The hookify plugin makes it simple to create hooks without editing complex hooks.json files. Instead, you create lightweight markdown configuration files that define patterns to watch for and messages to show when those patterns match.
Key features:
/hookify Warn me when I use rm -rf commands
This analyzes your request and creates .claude/hookify.warn-rm.local.md.
No restart needed! Rules take effect on the very next tool use.
Ask Claude to run a command that should trigger the rule:
Run rm -rf /tmp/test
You should see the warning message immediately!
With arguments:
/hookify Don't use console.log in TypeScript files
Creates a rule from your explicit instructions.
Without arguments:
/hookify
Analyzes recent conversation to find behaviors you've corrected or been frustrated by.
List all rules:
/hookify:list
Configure rules interactively:
/hookify:configure
Enable/disable existing rules through an interactive interface.
Get help:
/hookify:help
.claude/hookify.dangerous-rm.local.md:
---
name: block-dangerous-rm
enabled: true
event: bash
pattern: rm\s+-rf
action: block
---
⚠️ **Dangerous rm command detected!**
This command could delete important files. Please:
- Verify the path is correct
- Consider using a safer approach
- Make sure you have backups
Action field:
warn: Shows warning but allows operation (default)block: Prevents operation from executing (PreToolUse) or stops session (Stop events).claude/hookify.sensitive-files.local.md:
---
name: warn-sensitive-files
enabled: true
event: file
action: warn
conditions:
- field: file_path
operator: regex_match
pattern: \.env$|credentials|secrets
- field: new_text
operator: contains
pattern: KEY
---
🔐 **Sensitive file edit detected!**
Ensure credentials are not hardcoded and file is in .gitignore.
All conditions must match for the rule to trigger.
bash: Triggers on Bash tool commandsfile: Triggers on Edit, Write, MultiEdit toolsstop: Triggers when Claude wants to stop (for completion checks)prompt: Triggers on user prompt submissionall: Triggers on all eventsUse Python regex syntax:
| Pattern | Matches | Example |
|---|---|---|
rm\s+-rf |
rm -rf | rm -rf /tmp |
console\.log\( |
console.log( | console.log("test") |
(eval\|exec)\( |
eval( or exec( | eval("code") |
\.env$ |
files ending in .env | .env, .env.local |
chmod\s+777 |
chmod 777 | chmod 777 file.txt |
Tips:
\s for whitespace\. for literal dot| for OR: (foo|bar).* to match anythingaction: block for dangerous operationsaction: warn (or omit) for informational warnings---
name: block-destructive-ops
enabled: true
event: bash
pattern: rm\s+-rf|dd\s+if=|mkfs|format
action: block
---
🛑 **Destructive operation detected!**
This command can cause data loss. Operation blocked for safety.
Please verify the exact path and use a safer approach.
This rule blocks the operation - Claude will not be allowed to execute these commands.
---
name: warn-debug-code
enabled: true
event: file
pattern: console\.log\(|debugger;|print\(
action: warn
---
🐛 **Debug code detected**
Remember to remove debugging statements before committing.
This rule warns but allows - Claude sees the message but can still proceed.
---
name: require-tests-run
enabled: false
event: stop
action: block
conditions:
- field: transcript
operator: not_contains
pattern: npm test|pytest|cargo test
---
**Tests not detected in transcript!**
Before stopping, please run tests to verify your changes work correctly.
This blocks Claude from stopping if no test commands appear in the session transcript. Enable only when you want strict enforcement.
Check multiple fields simultaneously:
---
name: api-key-in-typescript
enabled: true
event: file
conditions:
- field: file_path
operator: regex_match
pattern: \.tsx?$
- field: new_text
operator: regex_match
pattern: (API_KEY|SECRET|TOKEN)\s*=\s*["']
---
🔐 **Hardcoded credential in TypeScript!**
Use environment variables instead of hardcoded values.
regex_match: Pattern must match (most common)contains: String must contain patternequals: Exact string matchnot_contains: String must NOT contain patternstarts_with: String starts with patternends_with: String ends with patternFor bash events:
command: The bash command stringFor file events:
file_path: Path to file being editednew_text: New content being added (Edit, Write)old_text: Old content being replaced (Edit only)content: File content (Write only)For prompt events:
user_prompt: The user's submitted prompt textFor stop events:
Temporarily disable:
Edit the .local.md file and set enabled: false
Re-enable:
Set enabled: true
Or use interactive tool:
/hookify:configure
Simply delete the .local.md file:
rm .claude/hookify.my-rule.local.md
/hookify:list
This plugin is part of the Claude Code Marketplace. It should be auto-discovered when the marketplace is installed.
Manual testing:
cc --plugin-dir /path/to/hookify
Rule not triggering:
.claude/ directory (in project root, not plugin directory)enabled: true in frontmatter/hookify:list to see if rule is loadedImport errors:
python3 --versionPattern not matching:
python3 -c "import re; print(re.search(r'pattern', 'text'))"Hook seems slow:
Found a useful rule pattern? Consider sharing example files via PR!
MIT License