Communitygithub.com

hookify-rules

用於建立、設定 Hookify 規則,或查詢規則語法與模式的技能。

hookify-rules 是什麼?

此技能提供完整的 Hookify 規則撰寫指南,涵蓋從基礎格式、YAML 前端的欄位說明,到進階多條件規則的設定方法。它主要支援 Claude Code 等 CLI 環境,透過 bash、file、stop、prompt 等事件觸發來攔截特定行為(如危險指令、除錯程式碼或敏感檔案操作),並顯示自訂警告或封鎖訊息。技能內含正則表達式撰寫技巧、常見陷阱說明與測試指令,並說明規則檔的存放位置與命名慣例。另提供 `/hookify`、`/hookify-list`、`/hookify-configure` 等指令,方便使用者快速建立、檢視與切換規則。整體而言,這套技能讓開發者能低摩擦地為 AI 助手設定專案專屬的行為規範與安全檢查。

相容平台✓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 前端資料 (frontmatter) 結尾的 Markdown 檔案,用來定義要監控的模式 (pattern),以及在比對成功時顯示的訊息。規則存放在 .claude/hookify.{規則名稱}.local.md 檔案中。

規則檔案格式

基本結構

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

觸發規則時要顯示給 Claude 的訊息。
可包含 Markdown 格式、警告、建議等。

Frontmatter 欄位

欄位必要值說明
name是短橫線分隔的小寫字串唯一識別碼(以動詞開頭: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/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.

相關技能