crush-hooks
Qué hace
Esta habilidad te ayuda a escribir hooks para Crush, una herramienta de código. Los hooks ejecutan tus propios comandos en puntos definidos, como antes de una llamada a herramienta, para permitirla, bloquearla o cambiarla. Es para quienes quieren reglas firmes sobre lo que puede hacer la herramienta.
Cuándo usarla
- ✓Cuando quieres bloquear o permitir ciertas llamadas a herramientas en Crush.
- ✓Cuando quieres cambiar la entrada de una herramienta antes de que se ejecute o añadir contexto a los resultados.
- ✓Cuando un hook de Crush no se comporta como se espera y necesita depuración.
Link de la skill
https://github.com/charmbracelet/crush/blob/main/internal/skills/builtin/crush-hooks/SKILL.mdCópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.
Cómo usar
La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.
Mensaje listo para pegar
Para Claude Code, Codex o Cursor: ejecútalo en la carpeta del proyecto y la skill queda instalada.
Descarga el SKILL.md y ponlo en la carpeta de skills de tu agente.
Ejemplo de qué pedirle a la IA
“Escribe un hook de Crush que bloquee cualquier comando de shell que borre archivos fuera de mi carpeta de proyecto.”
5 skills nuevas por semana. 1 minuto de lectura.
Cómo funciona
Tu agente escribe el hook en crush.json para el evento correcto, como PreToolUse. Los hooks se ejecutan antes de las comprobaciones de permisos, y solo para las llamadas a herramientas del agente principal, no de los subagentes.
Contenido técnico (SKILL.md original)
Texto original del autor, en inglés, directo de 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
Preguntas frecuentes
¿Qué eventos pueden usar los hooks?
Crush admite 13 eventos, como PreToolUse, PostToolUse y SessionStart.
¿Se ejecutan los hooks para subagentes?
No. Los hooks solo se ejecutan para las llamadas a herramientas del agente de nivel superior, no para las de subagentes.
¿Dónde se configuran los hooks?
Se configuran en el archivo crush.json.
Detalles
Descripción original del autor
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
Popularidad
- Estrellas en GitHub
- 29 mil
- Posición en el ranking
- #9766
- Licencia
- —
- Actualizada
- 2/11/2026
Comentarios
- …
Más skills de este repositorio
crush-config
29 milAyuda a tu agente a configurar Crush escribiendo su archivo crushrc o crush.json, incluyendo proveedores, modelos, servidores MCP, hooks y permisos.
jq
29 milAyuda a tu agente a consultar y reestructurar datos JSON, como respuestas de API, archivos de configuración o registros, usando el comando jq integrado.
Skills parecidas
diffs
394 milPermite que tu agente genere un diff real y compartible de los cambios, como enlace de visualización o archivo de imagen, en lugar de un resumen escrito a mano.
coding-agent
394 milAyuda a tu agente a pasar un trabajo de programación grande a Codex, Claude Code u OpenCode como trabajador en segundo plano, y después revisar su progreso.
gh-issues
394 milAyuda a tu agente a encontrar incidencias de GitHub, elegir cuáles trabajar y abrir pull requests con correcciones, incluido el seguimiento de los comentarios de revisión.