crush-hooks
できること
このスキルは、コーディングツールのCrushのフックを書くのに役立ちます。フックは、ツールの呼び出しの前など、決められた時点で自分のコマンドを実行し、許可、ブロック、または変更します。ツールができることに厳格なルールを設けたい人向けです。
使う場面
- ✓Crushで、特定のツールの呼び出しをブロックまたは許可したいとき。
- ✓ツールの入力を実行の前に変えたり、ツールの結果に文脈を追加したりしたいとき。
- ✓Crushのフックが期待どおりに動かず、デバッグが必要なとき。
スキルのリンク
https://github.com/charmbracelet/crush/blob/main/internal/skills/builtin/crush-hooks/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私のプロジェクトフォルダの外にあるファイルを削除するシェルコマンドを、すべてブロックするCrushのフックを書いてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、適切なイベント(PreToolUseなど)のフックを、crush.jsonに書きます。フックは権限の確認より前に実行され、メインのエージェントのツールの呼び出しにのみ適用され、サブエージェントには適用されません。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Crush Hooks
Hooks are user-defined commands in crush.json that fire at specific points
during execution, giving deterministic control over tool behavior. They run
before permission checks and only on the top-level agent's tool calls —
sub-agent calls (task tool, agentic_fetch, etc.) are not intercepted, though
the sub-agent tool call itself is.
For the full reference, see docs/hooks/README.md. This skill covers what you
need to author correct hooks.
Supported Events
Crush supports 13 hook events: PreToolUse, PostToolUse,
PostToolUseFailure, PermissionRequest, PermissionResult,
SessionStart, SessionEnd, TurnStart, TurnEnd, StopFailure,
Interrupt, PreCompact, PostCompact. Event names are case-insensitive
and accept snake_case (PreToolUse, pretooluse, pre_tool_use all work);
an unknown name is a config error. The five events that carry a tool call
(PreToolUse, PostToolUse, PostToolUseFailure, PermissionRequest,
PermissionResult) accept matcher; the rest run every configured hook and
reject matcher.
Only PreToolUse (allow/deny/halt/rewrite/context), PostToolUse
(halt/replace output/context/feedback), PostToolUseFailure
(halt/context), and PreCompact (block) honor output. The rest are
observe-only. Turn and tool events fire only for the top-level agent, never
for sub-agents (agentic_fetch, the task tool), so a TurnEnd hook runs
once per user prompt.
Per-event payload extras: PostToolUse has tool_response (the output
string), PostToolUseFailure and StopFailure have error, TurnEnd has
last_assistant_message, PermissionResult has decision
(granted/denied/cancelled), SessionStart has source
(startup/resume), SessionEnd has reason, and the compaction events
have trigger (auto/manual). Payloads also carry hook_event_name and
tool_use_id, and hooks see CLAUDE_PROJECT_DIR, so scripts written for
Claude Code usually work unchanged.
Configuration
{
"hooks": {
"PreToolUse": [
{
"matcher": "^bash$", // regex against tool name (optional; omit to match all)
"command": "./hooks/my-hook.sh", // required: shell command to run
"timeout": 10 // optional: seconds, default 30
}
]
}
}
Project-level hooks take precedence over global. Matching hooks are deduped by
command, run in parallel, and aggregated in config order (not finish order).
Language
command is a shell command, so hooks can be written in any language by
invoking the interpreter: node ./hooks/h.js, python3 ./hooks/h.py,
./hooks/h.sh, inline echo '…', etc. The rest of this skill shows bash, but
the input/output contract is identical regardless of language.
Input
Environment variables:
| Variable | Description |
|---|---|
CRUSH_EVENT |
Event name (e.g. PreToolUse) |
CRUSH_TOOL_NAME |
Tool being called (e.g. bash) |
CRUSH_SESSION_ID |
Current session ID |
CRUSH_CWD |
Working directory |
CRUSH_PROJECT_DIR |
Project root directory |
CLAUDE_PROJECT_DIR |
Same value, for Claude Code scripts |
CRUSH_TOOL_INPUT_COMMAND |
For bash calls: the shell command |
CRUSH_TOOL_INPUT_FILE_PATH |
For file tools: the target file path |
The CRUSH_TOOL_* variables are only set on events that carry a tool call.
JSON on stdin:
{
"event": "PreToolUse",
"hook_event_name": "PreToolUse",
"session_id": "313909e",
"cwd": "/home/user/project",
"tool_name": "bash",
"tool_input": {"command": "rm -rf /"},
"tool_use_id": "call_01"
}
Output
Communicate back via exit code (+ stderr) or JSON on stdout.
| Exit Code | Meaning |
|---|---|
| 0 | Success. Stdout is parsed as the JSON envelope below. |
| 2 | Block this tool call. Stderr becomes the deny reason. |
| 49 | Halt the whole turn. Stderr becomes the halt reason. |
| Other | Non-blocking error unless stdout holds a JSON object. |
Exit 2 blocks one tool call (agent sees the rea
よくある質問
フックにはどのイベントを使えますか?
PreToolUse、PostToolUse、SessionStartなど、13のイベントに対応しています。
サブエージェントにもフックは動きますか?
いいえ、フックはトップレベルのエージェントのツールの呼び出しにのみ動き、サブエージェントの呼び出しには動きません。
フックはどこで設定しますか?
crush.jsonファイルで設定します。
詳細
作者による元の説明
Use when the user wants to add, write, debug, or configure a Crush hook — gating or blocking tool calls, approving or rewriting tool input before execution, injecting context into tool results, or troubleshooting hook behavior in crush.json.
repo: charmbracelet/crush
人気
- GitHubのスター
- 29k
- ランキング
- #9766
- ライセンス
- —
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
crush-config
29kエージェントが、crushrcまたはcrush.jsonの設定ファイルを書いてCrushを設定できるよう支援します。プロバイダー、モデル、MCPサーバー、フック、権限を含みます。
jq
29kエージェントが、組み込みのjqコマンドを使って、APIの応答、設定ファイル、ログなどのJSONデータを検索し、組み替えられるよう支援します。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。