SKILL.md--- name: crush-hooks description: 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. --- # 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 — subagent calls (task tool, agentic_fetch, etc.) are not intercepted, though the subagent 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 subagents (`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 ```jsonc { "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 b