This repo gives you copy‑paste ready recipes for Cursor's Agent Hooks. Hooks are lightweight scripts that exchange JSON with Cursor so you can observe, block, or mutate agent behavior.
Create a minimal hook that runs after every file edit. This repo already includes hooks.json and all referenced scripts under hooks/, so setup is just copying the files into ~/.cursor/.
- Copy
hooks.jsonto~/.cursor/hooks.json. - Copy every script from
hooks/to~/.cursor/hooks/. - Run
chmod +x ~/.cursor/hooks/*.shto make them executable. - Restart Cursor and verify the hook runs after edits. Tail
/tmp/agent-audit.logor/tmp/hooks.logto confirm activity.
With a handful of scripts you can:
- run formatters or linters immediately after Cursor edits a file
- audit or block shell commands before they execute
- redact secrets before the agent reads sensitive content
- apply safety guardrails around MCP tool usage
Each hook definition maps to an executable script. Cursor streams JSON input on stdin and expects JSON back on stdout, letting you tailor the agent loop without patching Cursor itself.
Everything you need to mirror the documentation examples lives in this repository:
hooks.jsonwires each documented hook event to the scripts inhooks/.hooks/format.shis the minimal formatter-style hook used in the Quickstart.hooks/audit.shcaptures every payload into/tmp/agent-audit.logfor auditing.hooks/block-git.shdenies raw git usage, requests approval forgh, and logs decisions to/tmp/hooks.log.hooks/redact-secrets.shprevents Cursor from reading files that look like they contain GitHub tokens.
- Copy
hooks.jsonand the scripts inhooks/into~/.cursor/. - Run
chmod +x ~/.cursor/hooks/*.shso Cursor can execute them. - Tail
/tmp/hooks.logor/tmp/agent-audit.logto verify hook activity. - Restart Cursor after modifying any hook.
Issues and pull requests are welcome. Please open an issue first if you plan to add new recipes or extend existing ones.
Released under the MIT License. See LICENSE.