← 返回
未分类 中文

Nm Hookify Writing Rules

Create markdown-based behavioral rules to prevent unwanted actions and block dangerous commands
在 Markdown 中创建行为规则,用于阻止危险命令或限制 AI 行为
athola athola 来源
未分类 clawhub v1.9.12 3 版本 99775.8 Key: 无需
★ 0
Stars
📥 445
下载
💾 1
安装
3
版本
#latest

概述

> Night Market Skill — ported from claude-night-market/hookify. For the full experience with agents, hooks, and commands, install the Claude Code plugin.

Table of Contents

Hookify Rule Writing Guide

When To Use

  • Creating behavioral rules to prevent unwanted actions
  • Defining persistent guardrails for Claude Code sessions

When NOT To Use

  • Complex multi-step workflows - use agents instead
  • One-time operations that do not need persistent behavioral 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.

Quick Start

Create .claude/hookify.dangerous-rm.local.md:

---
name: dangerous-rm
enabled: true
event: bash
pattern: rm\s+-rf
action: block
---

🛑 **Dangerous rm command detected!**

This command could delete important files.

Verification: Run the command with --help flag to verify availability.

The rule activates immediately - no restart needed!

Rule File Format

Frontmatter Fields

name (required): Unique identifier (kebab-case)

enabled (required): true or false

event (required): bash, file, stop, prompt, or all

action (optional): warn (default) or block

pattern (simple): Regex pattern to match

Event Types

  • bash: Bash tool commands
  • file: Edit, Write, MultiEdit tools
  • stop: When agent wants to stop
  • prompt: User prompt submission
  • all: All events

Advanced Conditions

For multiple field checks:

---
name: warn-env-edits
enabled: true
event: file
action: warn
conditions:
  - field: file_path
    operator: regex_match
    pattern: \.env$
  - field: new_text
    operator: contains
    pattern: API_KEY
---

🔐 **API key in .env file!**
Ensure file is in .gitignore.

Operators

  • regex_match: Pattern matching
  • contains: Substring check
  • equals: Exact match
  • not_contains: Must NOT contain
  • starts_with: Prefix check
  • ends_with: Suffix check

Field Reference

bash events: command

file events: file_path, new_text, old_text, content

prompt events: user_prompt

stop events: transcript

Pattern Writing

Regex Basics

  • \s - whitespace
  • \d - digit
  • \w - word character
  • . - any character (use \. for literal dot)
  • + - one or more
  • * - zero or more
  • | - OR

Examples

rm\s+-rf          → rm -rf
console\.log\(    → console.log(
chmod\s+777       → chmod 777

Test Patterns

python3 -c "import re; print(re.search(r'pattern', 'text'))"

Example Rules

Block Destructive Commands

---
name: block-destructive
enabled: true
event: bash
pattern: rm\s+-rf|dd\s+if=|mkfs
action: block
---

🛑 **Destructive operation blocked!**
Can cause data loss.

Warn About Debug Code

---
name: warn-debug
enabled: true
event: file
pattern: console\.log\(|debugger;
action: warn
---

🐛 **Debug code detected!**
Remove before committing.

Require Tests

---
name: require-tests
enabled: true
event: stop
action: warn
conditions:
  - field: transcript
    operator: not_contains
    pattern: pytest|npm test
---

⚠️ **Tests not run!**
Please verify changes.

Protect Production Files

---
name: protect-prod
enabled: true
event: file
action: block
conditions:
  - field: file_path
    operator: regex_match
    pattern: /production/|\.prod\.
---

🚨 **Production file!**
Requires review.

Management

Enable/Disable:

Edit .local.md file: enabled: false

Delete:

rm .claude/hookify.my-rule.local.md

List:

/hookify:list

Related Skills

  • abstract:hook-scope-guide - Hook placement decisions
  • abstract:hook-authoring - SDK hook development
  • abstract:hooks-eval - Hook evaluation

Best Practices

  1. Start with simple patterns
  2. Test regex thoroughly
  3. Use clear, helpful messages
  4. Prefer warnings over blocks initially
  5. Name rules descriptively
  6. Document intent in messages
  7. Troubleshooting

Common Issues

If a rule doesn't trigger, verify that the event type matches the tool being used (e.g., use bash for command line tools). Check that the regex pattern is valid and matches the target text by testing it with a short Python script. If you encounter permission errors when creating rule files in .claude/, ensure that the directory is writable by your user.

版本历史

共 3 个版本

  • v1.9.12 当前
    2026-06-19 19:56
  • v1.0.2
    2026-05-09 16:38 安全 安全
  • v1.0.1
    2026-05-07 11:37 安全 安全

安全检测

腾讯云安全 (Keen)

队列中

腾讯云安全 (Sanbu)

队列中

🔗 相关推荐

ai-agent

Find Skills

guipi888
场景驱动+关键词双模式技能发现工具。当用户用自然语言描述场景/需求(如"我想做一个海报""帮我分析股票"),或明确说"安装技能/find skills/找个skill"时,自动从官方内置、本地已安装、SkillHub、虾评、GitHub、C
★ 1,459 📥 510,774
dev-programming

Nm Parseltongue Python Performance

athola
分析 Python 代码的性能瓶颈和内存问题
★ 0 📥 735
ai-agent

self-improving agent

pskoett
捕获经验教训、错误及修正内容,以实现持续改进。适用于以下场景:(1)命令或操作意外失败;(2)用户纠正Claude(如“不,那不对……”“实际上……”);(3)用户请求的功能不存在;(4)外部API或工具出现故障;(5)Claude发现自身
★ 4,097 📥 824,423