| title | Hooks |
|---|---|
| description | Deterministic lifecycle hooks for controlling agent behavior (Cursor and compatible hook systems). |
Hooks are deterministic scripts that run at defined points in an agent loop (before shell execution, before reading files, after edits, at stop, etc). Unlike rules, hooks can block, allow, or modify actions reliably because they execute outside the model.
This repo ships an optional Cursor hooks pack under hooks/cursor/:
- Guardrails for risky commands (
beforeShellExecution) - Guardrails for sensitive file reads (
beforeReadFile) - Lightweight audit logging (optional)
Important
Hooks are not enabled by default. Start with project hooks (per-repo) before enabling global user hooks.
Cursor loads hooks from:
- Project:
<repo>/.cursor/hooks.json(runs from repo root) - User:
~/.cursor/hooks.json(runs from~/.cursor)
Hook scripts communicate via JSON over stdio (stdin input, stdout output). Cursor docs: https://cursor.com/docs/agent/hooks
- File:
hooks/cursor/guard_before_shell.py - Goal: deterministically gate dangerous/destructive commands and remote writes.
Behavior:
- deny: clearly destructive commands that are almost never correct to run autonomously (example:
rm -rf /) - ask: remote writes and high-blast-radius commands (example:
git push,terraform apply) - allow: everything else
- File:
hooks/cursor/guard_before_read_file.py - Goal: block sending sensitive file contents to the model.
Behavior:
- deny: obvious secret files (example:
.env, private keys) and binary-ish content - allow: everything else
- File:
hooks/cursor/audit_log.py - Goal: append a redacted JSON line log of hook events to a local file.
Copy the example config and scripts into your repo:
mkdir -p .cursor/hooks
cp -R /path/to/agent-engineering-handbook/hooks/cursor/*.py .cursor/hooks/
cp /path/to/agent-engineering-handbook/hooks/cursor/hooks.project.example.json .cursor/hooks.json
chmod +x .cursor/hooks/*.pyOnly after you like the behavior in a few repos, install globally:
/path/to/agent-engineering-handbook/scripts/cursor-hooks-install.sh --user- Hooks run with your user permissions - treat them like any other local automation.
- Prefer fail-open while iterating (Cursor supports
failClosedif you want fail-closed later). - Keep matchers narrow to reduce noise and performance overhead.