Ir al contenido
angel.library

Hooks

.cursor/hooks.json
{
"hooks": {
"afterFileEdit": [{ "command": "npx prettier --write \"$FILE_PATH\"" }],
"beforeShellExecution": [
{ "command": "scripts/bloquear-comandos-peligrosos.sh" }
]
}
}
EventoCuándo corre
sessionStart / sessionEndAl empezar/terminar la sesión
beforeSubmitPromptAntes de mandar el prompt al modelo
beforeShellExecutionAntes de correr un comando de shell (puede bloquear)
beforeMCPExecutionAntes de invocar una tool de MCP
beforeReadFileAntes de leer un archivo (útil para redactar contenido sensible)
afterFileEditDespués de editar un archivo
stopCuando el agente termina de responder
scripts/bloquear-comandos-peligrosos.sh
#!/bin/bash
input=$(cat)
command=$(echo "$input" | jq -r '.command')
if echo "$command" | grep -qE 'rm -rf /'; then
echo '{"decision": "block", "message": "Comando bloqueado por hook"}'
exit 0
fi
exit 0

El hook recibe JSON por stdin y puede devolver JSON por stdout para bloquear/permitir.

Uso típicoEvento
Formatear código automáticamenteafterFileEdit
Bloquear comandos destructivosbeforeShellExecution
Redactar archivos sensiblesbeforeReadFile
Logging/auditoríabeforeMCPExecution, beforeShellExecution
  • Los hooks son bundleables dentro de un Cursor Plugin (no de la spec Agent Plugins portable) — si el plugin necesita ser portable a otras herramientas, los hooks no viajan con él.
  • Shippeado en Cursor 1.7 (~octubre 2025) — relativamente nuevo, verificar la doc oficial si algo no se comporta como aquí.