spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / plugins / hookify / commands / help.md
175 lines · 4.5 KBPreviewCodeRaw
1---
2description: Get help with the hookify plugin
3allowed-tools: ["Read"]
4---
5
6# Hookify Plugin Help
7
8Explain how the hookify plugin works and how to use it.
9
10## Overview
11
12The hookify plugin makes it easy to create custom hooks that prevent unwanted behaviors. Instead of editing `hooks.json` files, users create simple markdown configuration files that define patterns to watch for.
13
14## How It Works
15
16### 1. Hook System
17
18Hookify installs generic hooks that run on these events:
19- **PreToolUse**: Before any tool executes (Bash, Edit, Write, etc.)
20- **PostToolUse**: After a tool executes
21- **Stop**: When Claude wants to stop working
22- **UserPromptSubmit**: When user submits a prompt
23
24These hooks read configuration files from `.claude/hookify.*.local.md` and check if any rules match the current operation.
25
26### 2. Configuration Files
27
28Users create rules in `.claude/hookify.{rule-name}.local.md` files:
29
30```markdown
31---
32name: warn-dangerous-rm
33enabled: true
34event: bash
35pattern: rm\s+-rf
36---
37
38⚠️ **Dangerous rm command detected!**
39
40This command could delete important files. Please verify the path.
41```
42
43**Key fields:**
44- `name`: Unique identifier for the rule
45- `enabled`: true/false to activate/deactivate
46- `event`: bash, file, stop, prompt, or all
47- `pattern`: Regex pattern to match
48
49The message body is what Claude sees when the rule triggers.
50
51### 3. Creating Rules
52
53**Option A: Use /hookify command**
54```
55/hookify Don't use console.log in production files
56```
57
58This analyzes your request and creates the appropriate rule file.
59
60**Option B: Create manually**
61Create `.claude/hookify.my-rule.local.md` with the format above.
62
63**Option C: Analyze conversation**
64```
65/hookify
66```
67
68Without arguments, hookify analyzes recent conversation to find behaviors you want to prevent.
69
70## Available Commands
71
72- **`/hookify`** - Create hooks from conversation analysis or explicit instructions
73- **`/hookify:help`** - Show this help (what you're reading now)
74- **`/hookify:list`** - List all configured hooks
75- **`/hookify:configure`** - Enable/disable existing hooks interactively
76
77## Example Use Cases
78
79**Prevent dangerous commands:**
80```markdown
81---
82name: block-chmod-777
83enabled: true
84event: bash
85pattern: chmod\s+777
86---
87
88Don't use chmod 777 - it's a security risk. Use specific permissions instead.
89```
90
91**Warn about debugging code:**
92```markdown
93---
94name: warn-console-log
95enabled: true
96event: file
97pattern: console\.log\(
98---
99
100Console.log detected. Remember to remove debug logging before committing.
101```
102
103**Require tests before stopping:**
104```markdown
105---
106name: require-tests
107enabled: true
108event: stop
109pattern: .*
110---
111
112Did you run tests before finishing? Make sure `npm test` or equivalent was executed.
113```
114
115## Pattern Syntax
116
117Use Python regex syntax:
118- `\s` - whitespace
119- `\.` - literal dot
120- `|` - OR
121- `+` - one or more
122- `*` - zero or more
123- `\d` - digit
124- `[abc]` - character class
125
126**Examples:**
127- `rm\s+-rf` - matches "rm -rf"
128- `console\.log\(` - matches "console.log("
129- `(eval|exec)\(` - matches "eval(" or "exec("
130- `\.env$` - matches files ending in .env
131
132## Important Notes
133
134**No Restart Needed**: Hookify rules (`.local.md` files) take effect immediately on the next tool use. The hookify hooks are already loaded and read your rules dynamically.
135
136**Block or Warn**: Rules can either `block` operations (prevent execution) or `warn` (show message but allow). Set `action: block` or `action: warn` in the rule's frontmatter.
137
138**Rule Files**: Keep rules in `.claude/hookify.*.local.md` - they should be git-ignored (add to .gitignore if needed).
139
140**Disable Rules**: Set `enabled: false` in frontmatter or delete the file.
141
142## Troubleshooting
143
144**Hook not triggering:**
145- Check rule file is in `.claude/` directory
146- Verify `enabled: true` in frontmatter
147- Confirm pattern is valid regex
148- Test pattern: `python3 -c "import re; print(re.search('your_pattern', 'test_text'))"`
149- Rules take effect immediately - no restart needed
150
151**Import errors:**
152- Check Python 3 is available: `python3 --version`
153- Verify hookify plugin is installed correctly
154
155**Pattern not matching:**
156- Test regex separately
157- Check for escaping issues (use unquoted patterns in YAML)
158- Try simpler pattern first, then refine
159
160## Getting Started
161
1621. Create your first rule:
163 ```
164 /hookify Warn me when I try to use rm -rf
165 ```
166
1672. Try to trigger it:
168 - Ask Claude to run `rm -rf /tmp/test`
169 - You should see the warning
170
1714. Refine the rule by editing `.claude/hookify.warn-rm.local.md`
172
1735. Create more rules as you encounter unwanted behaviors
174
175For more examples, check the `${CLAUDE_PLUGIN_ROOT}/examples/` directory.