writing-hookify-rules
Skill này làm gì
Nó cho agent của bạn cú pháp và các mẫu để viết quy tắc hookify, những file nhỏ cảnh báo hoặc chặn một số hành động nhất định. Nó dành cho lập trình viên muốn có lan can bảo vệ trong Claude Code.
Khi nào nên dùng
- ✓Khi bạn muốn một quy tắc cảnh báo khi một lệnh hoặc chỉnh sửa nhất định xảy ra.
- ✓Khi bạn muốn một quy tắc chặn một hành động rủi ro không được chạy.
- ✓Khi bạn muốn sửa hoặc hiểu một file quy tắc hookify đã có.
Liên kết skill
https://github.com/anthropics/claude-plugins-official/blob/main/plugins/hookify/skills/writing-rules/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bạn có thể viết một quy tắc hookify để cảnh báo tôi trước khi lệnh nào xóa file bằng rm không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent viết một file quy tắc gồm tên, công tắc bật tắt, sự kiện được theo dõi và mẫu cần khớp. Nó đặt hành động là cảnh báo hoặc chặn tùy theo ý bạn.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
---
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 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:
event: bash
pattern: rm\s+-rf
Advanced Format (Multiple Conditions)
For complex rules with multiple conditions:
---
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
- 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:
⚠️ **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:
---
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:
---
event: file
pattern: console\.log\(|eval\(|innerHTML\s*=
---
Potentially problematic code pattern detected!
Match on different fields:
---
event: file
conditions:
- field: file_path
operator: regex_match
pattern: \.tsx?$
- field: new_text
operator: regex_match
pattern: console\.log\(
---
Console.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):
---
event: stop
pattern: .*
---
Before stopping, verify:
- [ ] Tests were run
- [ ] Build succeeded
- [ ] Documentation updated
Use for:
- Reminders about required steps
- Completion checklists
- Process enforcement
prompt Events
Match user prompt content (advanced):
---
event: prompt
conditions:
- field: user_prompt
Câu hỏi thường gặp
Các quy tắc được lưu ở đâu?
Skill nói chúng được lưu trong thư mục .claude của dự án dưới dạng file markdown cục bộ.
Quy tắc có thể theo dõi những sự kiện nào?
Skill liệt kê lệnh bash, chỉnh sửa file, sự kiện dừng, prompt của người dùng và tất cả sự kiện.
Tôi có thể tắt một quy tắc mà không xóa không?
Có. Mỗi quy tắc có một cài đặt enabled có thể chuyển sang tắt.
Chi tiết
Mô tả gốc của tác giả
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.
Độ phổ biến
- Sao GitHub
- 46k
- Vị trí xếp hạng
- #6336
- Giấy phép
- Apache-2.0
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
access
46kCho phép bạn quản lý ai được nhắn tin với trợ lý qua kênh Discord, bao gồm duyệt ghép đôi và danh sách cho phép.
configure
46kThiết lập kênh Discord cho trợ lý của bạn bằng cách lưu bot token và kiểm tra ai có thể tiếp cận nó.
access
46kCho phép bạn quản lý ai được nhắn tin cho trợ lý qua kênh iMessage, bao gồm duyệt và danh sách cho phép.
configure
46kKiểm tra thiết lập kênh iMessage của bạn, gồm Full Disk Access, và giải thích ai có thể tiếp cận trợ lý của bạn.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.