このスキルは、次のような場合に使用します: - ユーザーが「hookifyルール(自動接続設定の規則)を作成する」と依頼した場合 - 「フック規則を書く」と依頼した場合 - 「hookifyを設定する」と依頼した場合 - 「hookifyルールを追加する」と依頼した場合 - hookifyルールの構文やパターンについてのサポートが必要な場合
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.
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(必須): ルールの一意な識別子
warn-dangerous-rm、block-console-logenabled(必須): ルールを有効/無効にするBoolean値
true: ルールが有効false: ルールが無効(トリガーされない)event(必須): トリガーするhookイベントの種類
bash: Bashツールのコマンドfile: Edit、Write、MultiEditツールstop: agentが停止しようとするときprompt: ユーザーがプロンプトを送信するときall: すべてのイベントaction(省略可): ルールにマッチした際の動作
warn: メッセージを表示するが操作は許可する(デフォルト)block: 操作を禁止する(PreToolUse)またはセッションを停止する(Stopイベント)warn がデフォルトpattern(シンプル形式): マッチさせる正規表現パターン
例:
event: bash
pattern: rm\s+-rf
複数の条件を持つ複雑なルールの場合:
---
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
---
.envファイルにAPIキーを追加しようとしています。このファイルが.gitignoreに含まれているか確認してください!
conditionのフィールド:
field: チェック対象のフィールド
commandfile_path、new_text、old_text、contentoperator: マッチ方法
regex_match: 正規表現によるパターンマッチcontains: 部分文字列チェックequals: 完全一致not_contains: 部分文字列が含まれていないことstarts_with: プレフィックスチェックends_with: サフィックスチェックpattern: マッチさせるパターンまたは文字列すべての条件が一致した場合にのみルールがトリガーされます。
フロントマター以降のMarkdownコンテンツが、ルールのトリガー時にClaudeへ表示されます。
良いメッセージの条件:
例:
⚠️ **console.logが検出されました!**
本番コードにconsole.logを追加しようとしています。
**なぜ問題なのか:**
- デバッグログを本番環境にリリースすべきではありません
- console.logは機密データを露出させる可能性があります
- ブラウザのパフォーマンスに影響します
**代替手段:**
- 適切なロギングライブラリを使用する
- コミット前に削除する
- 条件付きデバッグビルドを使用する
Bashコマンドのパターンにマッチします:
---
event: bash
pattern: sudo\s+|rm\s+-rf|chmod\s+777
---
危険なコマンドが検出されました!
よく使うパターン:
rm\s+-rf、dd\s+if=、mkfssudo\s+、su\s+chmod\s+777、chown\s+rootEdit/Write/MultiEdit 操作にマッチします:
---
event: file
pattern: console\.log\(|eval\(|innerHTML\s*=
---
問題のある可能性があるコードパターンが検出されました!
異なるフィールドでマッチさせる場合:
---
event: file
conditions:
- field: file_path
operator: regex_match
pattern: \.tsx?$
- field: new_text
operator: regex_match
pattern: console\.log\(
---
TypeScriptファイルにconsole.logがあります!
よく使うパターン:
console\.log\(、debugger、print\(eval\(、innerHTML\s*=、dangerouslySetInnerHTML\.env$、credentials、\.pem$node_modules/、dist/、build/agentが停止しようとするタイミングにマッチします(完了チェック用):
---
event: stop
pattern: .*
---
停止する前に以下を確認してください:
- [ ] テストを実行した
- [ ] ビルドが成功した
- [ ] ドキュメントを更新した
次のような場合に使用:
ユーザーのプロンプト内容にマッチします(上級者向け):
---
event: prompt
conditions:
- field: user_prompt
operator: contains
pattern: deploy to production
---
本番デプロイのチェックリスト:
- [ ] テストはパスしていますか?
- [ ] チームによるレビューは完了しましたか?
- [ ] モニタリングの準備は整っていますか?
リテラル文字: ほとんどの文字はそのままマッチします
rm は "rm" にマッチconsole.log は "console.log" にマッチ特殊文字はエスケープが必要:
.(任意の文字)→ \.(リテラルのドット)( ) → \( \)(リテラルの括弧)[ ] → \[ \](リテラルの角括弧)よく使うメタ文字:
\s - 空白文字(スペース、タブ、改行)\d - 数字(0〜9)\w - 単語文字(a〜z、A〜Z、0〜9、_). - 任意の文字+ - 1回以上* - 0回以上? - 0回または1回| - OR例:
rm\s+-rf マッチ: rm -rf, rm -rf
console\.log\( マッチ: console.log(
(eval|exec)\( マッチ: eval( または exec(
chmod\s+777 マッチ: chmod 777, chmod 777
API_KEY\s*= マッチ: API_KEY=, API_KEY =
使用する前に正規表現パターンをテストしてください:
python3 -c "import re; print(re.search(r'your_pattern', 'test text'))"
またはオンラインの正規表現テスター(regex101.com でPythonフレーバーを選択)を使用してください。
パターンが広すぎる:
pattern: log # "log"、"login"、"dialog"、"catalog" にもマッチしてしまう
改善例: console\.log\(|logger\.
パターンが限定的すぎる:
pattern: rm -rf /tmp # この完全なパスにしかマッチしない
改善例: rm\s+-rf
エスケープの問題:
"pattern" ではバックスラッシュを二重に \\s と書く必要があるpattern: \s はそのまま使える保存場所: すべてのルールを .claude/ ディレクトリに配置
命名規則: .claude/hookify.{descriptive-name}.local.md
Gitignore: .claude/*.local.md を .gitignore に追加
良い名前の例:
hookify.dangerous-rm.local.mdhookify.console-log.local.mdhookify.require-tests.local.mdhookify.sensitive-files.local.md悪い名前の例:
hookify.rule1.local.md(説明的でない)hookify.md(.local が欠けている)danger.local.md(hookify プレフィックスが欠けている).claude/hookify.{name}.local.md ファイルを作成する.local.md ファイルを編集する一時的に: フロントマターで enabled: false に設定する
恒久的に: .local.md ファイルを削除する
完全なサンプルは ${CLAUDE_PLUGIN_ROOT}/examples/ を参照してください:
dangerous-rm.local.md - 危険なrmコマンドをブロックconsole-log-warning.local.md - console.logについて警告sensitive-files-warning.local.md - .envファイルの編集について警告最小構成のルール:
---
name: my-rule
enabled: true
event: bash
pattern: dangerous_command
---
警告メッセージをここに記述
条件付きのルール:
---
name: my-rule
enabled: true
event: file
conditions:
- field: file_path
operator: regex_match
pattern: \.ts$
- field: new_text
operator: contains
pattern: any
---
警告メッセージ
イベントタイプ:
bash - Bashコマンドfile - ファイル編集stop - 完了チェックprompt - ユーザー入力all - すべてのイベントフィールドのオプション:
commandfile_path、new_text、old_text、contentuser_promptオペレーター:
regex_match、contains、equals、not_contains、starts_with、ends_withHookify 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.
---
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.
name (required): Unique identifier for the rule
warn-dangerous-rm, block-console-logenabled (required): Boolean to activate/deactivate
true: Rule is activefalse: Rule is disabled (won't trigger)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 eventsaction (optional): What to do when rule matches
warn: Show message but allow operation (default)block: Prevent operation (PreToolUse) or stop session (Stop events)warnpattern (simple format): Regex pattern to match
Example:
event: bash
pattern: rm\s+-rf
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
commandfile_path, new_text, old_text, contentoperator: How to match
regex_match: Regex pattern matchingcontains: Substring checkequals: Exact matchnot_contains: Substring must NOT be presentstarts_with: Prefix checkends_with: Suffix checkpattern: Pattern or string to matchAll conditions must match for rule to trigger.
The markdown content after frontmatter is shown to Claude when the rule triggers.
Good messages:
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
Match Bash command patterns:
---
event: bash
pattern: sudo\s+|rm\s+-rf|chmod\s+777
---
Dangerous command detected!
Common patterns:
rm\s+-rf, dd\s+if=, mkfssudo\s+, su\s+chmod\s+777, chown\s+rootMatch 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:
console\.log\(, debugger, print\(eval\(, innerHTML\s*=, dangerouslySetInnerHTML\.env$, credentials, \.pem$node_modules/, dist/, build/Match when agent wants to stop (completion checks):
---
event: stop
pattern: .*
---
Before stopping, verify:
- [ ] Tests were run
- [ ] Build succeeded
- [ ] Documentation updated
Use for:
Match user prompt content (advanced):
---
event: prompt
conditions:
- field: user_prompt
operator: contains
pattern: deploy to production
---
Production deployment checklist:
- [ ] Tests passing?
- [ ] Reviewed by team?
- [ ] Monitoring ready?
Literal characters: Most characters match themselves
rm matches "rm"console.log matches "console.log"Special characters need escaping:
. (any char) → \. (literal dot)( ) → \( \) (literal parens)[ ] → \[ \] (literal brackets)Common metacharacters:
\s - whitespace (space, tab, newline)\d - digit (0-9)\w - word character (a-z, A-Z, 0-9, _). - any character+ - one or more* - zero or more? - zero or one| - ORExamples:
rm\s+-rf Matches: rm -rf, rm -rf
console\.log\( Matches: console.log(
(eval|exec)\( Matches: eval( or exec(
chmod\s+777 Matches: chmod 777, chmod 777
API_KEY\s*= Matches: API_KEY=, API_KEY =
Test regex patterns before using:
python3 -c "import re; print(re.search(r'your_pattern', 'test text'))"
Or use online regex testers (regex101.com with Python flavor).
Too broad:
pattern: log # Matches "log", "login", "dialog", "catalog"
Better: console\.log\(|logger\.
Too specific:
pattern: rm -rf /tmp # Only matches exact path
Better: rm\s+-rf
Escaping issues:
"pattern" requires double backslashes \\spattern: \s works as-isLocation: All rules in .claude/ directory
Naming: .claude/hookify.{descriptive-name}.local.md
Gitignore: Add .claude/*.local.md to .gitignore
Good names:
hookify.dangerous-rm.local.mdhookify.console-log.local.mdhookify.require-tests.local.mdhookify.sensitive-files.local.mdBad names:
hookify.rule1.local.md (not descriptive)hookify.md (missing .local)danger.local.md (missing hookify prefix).claude/hookify.{name}.local.md file in project root.local.md fileTemporary: Set enabled: false in frontmatter
Permanent: Delete the .local.md file
See ${CLAUDE_PLUGIN_ROOT}/examples/ for complete examples:
dangerous-rm.local.md - Block dangerous rm commandsconsole-log-warning.local.md - Warn about console.logsensitive-files-warning.local.md - Warn about editing .env filesMinimum viable rule:
---
name: my-rule
enabled: true
event: bash
pattern: dangerous_command
---
Warning message here
Rule with conditions:
---
name: my-rule
enabled: true
event: file
conditions:
- field: file_path
operator: regex_match
pattern: \.ts$
- field: new_text
operator: contains
pattern: any
---
Warning message
Event types:
bash - Bash commandsfile - File editsstop - Completion checksprompt - User inputall - All eventsField options:
commandfile_path, new_text, old_text, contentuser_promptOperators:
regex_match, contains, equals, not_contains, starts_with, ends_with原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。