Communitygithub.com

hookify 规则编写指南

当用户请求创建 hookify 规则、编写钩子规则、配置 hookify、添加 hookify 规则,或需要指导 hookify 规则语法与模式时使用此技能。

hookify 规则编写指南 是什么?

该技能提供了编写 Hookify 规则的完整指南。Hookify 规则是基于 Markdown 的文件,包含 YAML 前置元数据,用于定义需要监视的模式以及在匹配时显示的消息。规则存储在 `.claude/hookify.{规则名称}.local.md` 文件中。 主要特性包括:基本的 YAML 前置元数据字段(如名称、启用状态、事件类型、模式等),支持多条件的复杂规则格式,针对不同事件类型(bash、file、stop、prompt)的条件字段和运算符。此外还提供了正则表达式编写技巧、常见陷阱避免、测试方法以及文件组织规范。 该技能适用于需要在开发工作流中增强安全性和编码规范的场景,可配合 /hookify、/hookify-list、/hookify-configure 等命令使用。技能全平台支持,兼容多种开发工具。其工作方式是通过解析规则文件,在对应事件触发时检查匹配情况并执行相应动作(警告或阻止)。

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

在你喜欢的 AI 中提问

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

文档

编写 Hookify 规则

概述

Hookify 规则是带有 YAML 前置元数据的 Markdown 文件,用于定义需要监视的模式以及在匹配时显示的消息。规则存储在 .claude/hookify.{规则名称}.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触发该规则的钩子事件
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/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

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.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相关技能