Communitygithub.com

hookify-rules

用于创建、配置和管理 Hookify 规则,支持正则匹配与多条件触发。

hookify-rules 是什么?

Hookify 规则是一种基于 Markdown 文件和 YAML 前置数据的配置机制,允许开发者定义特定模式(如命令、文件内容、用户提示等),并在模式匹配时向 AI 助手(如 Claude)显示自定义消息或阻止操作。规则文件以 `.claude/hookify.{rule-name}.local.md` 格式存储,支持 `bash`、`file`、`stop`、`prompt` 四种事件类型。每个规则可包含名称、启用状态、事件、正则模式、可选操作(warn 或 block)以及多条件字段。该工具特别适合在开发环境中强制执行编码规范、检测危险操作或确保工作流合规。支持的平台包括 Claude Code 等支持 `hookify` 指令的 AI 编程助手。通过 `/hookify`、`/hookify-list`、`/hookify-configure` 等命令可快速创建、查看和切换规则,提高开发安全性与一致性。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/hookify-rules

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

编写 Hookify 规则

概述

Hookify 规则是带有 YAML 前置数据的 Markdown 文件,用于定义要监视的模式以及当模式匹配时显示的消息。规则存储在 .claude/hookify.{rule-name}.local.md 文件中。

规则文件格式

基本结构

---
name: rule-identifier
enabled: true
event: bash|file|stop|prompt|all
pattern: regex-pattern-here
---

当此规则触发时向 Claude 显示的消息。
可以包含 Markdown 格式、警告、建议等。

前置数据字段

字段必填值描述
name是kebab-case 字符串唯一标识符(动词优先:warn-, block-, require-*)
enabled是true/false无需删除即可切换开关
event是bash/file/stop/prompt/all触发此规则的 Hook 事件
action否warn/blockwarn(默认)显示消息;block 阻止操作
pattern是*正则字符串要匹配的模式(*或使用 conditions 实现复杂规则)

高级格式(多条件)

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

你正在向 .env 文件添加 API 密钥。请确保此文件在 .gitignore 中!

各事件的条件字段:

  • bash:command
  • file:file_path、new_text、old_text、content
  • prompt:user_prompt

运算符: regex_match、contains、equals、not_contains、starts_with、ends_with

所有条件必须同时匹配,规则才会触发。

事件类型指南

bash 事件

匹配 Bash 命令模式:

  • 危险命令:rm\s+-rf、dd\s+if=、mkfs
  • 权限提升:sudo\s+、su\s+
  • 权限问题:chmod\s+777

file 事件

匹配编辑/写入/批量编辑操作:

  • 调试代码:console\.log\(、debugger
  • 安全风险:eval\(、innerHTML\s*=
  • 敏感文件:\.env$、credentials、\.pem$

stop 事件

完成检查与提醒。模式 .* 始终匹配。

prompt 事件

匹配用户提示内容以强制执行工作流。

模式编写技巧

正则基础

  • 转义特殊字符:. 转 \.,( 转 \(
  • \s 空白符,\d 数字,\w 单词字符
  • + 一个或多个,* 零个或多个,? 可选
  • | OR 运算符

常见陷阱

  • 过于宽泛:log 会匹配 "login"、"dialog"——请使用 console\.log\(
  • 过于具体:rm -rf /tmp——请使用 rm\s+-rf
  • YAML 转义:使用无引号模式;带引号的字符串需要 \\s

测试

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

文件组织

  • 位置:项目根目录的 .claude/ 目录
  • 命名:.claude/hookify.{描述性名称}.local.md
  • Gitignore:将 .claude/*.local.md 添加到 .gitignore

命令

  • /hookify [描述] - 创建新规则(若不带参数,则自动分析对话)
  • /hookify-list - 以表格形式查看所有规则
  • /hookify-configure - 交互式开关规则
  • /hookify-help - 完整文档

快速参考

最小可行规则:

---
name: my-rule
enabled: true
event: bash
pattern: dangerous_command
---
在此处显示警告消息

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能