Cursor Hooks Pack: 8 Ready hooks.json Hooks + Installer + Validator

Make Cursor's agent ask before it runs rm -rf, reads your .env or calls an MCP server you never approved.

Cursor Hooks Pack: 8 Ready hooks.json Hooks + Installer + Validator product illustration

What it does

Eight ready Cursor hooks (.cursor/hooks.json) that stop the agent from doing damage, keep secrets out of the model, and keep it working until the tests pass, plus hookcheck, a checker and simulator that tells you why a hook isn't running.

Python 3.9+, standard library only. No accounts, no network. Written against the Cursor hooks reference as of Nov 2026.

What you get

The screenshot is real output from the kit’s own commands. Tested from a fresh download of this exact zip: ./run_tests.sh ran 18 tests OK on Python 3.13 and 3.10.

Real terminal output from Cursor Hooks Pack: 8 Ready hooks.json Hooks + Installer + Validator: demo and passing tests

The hooks

Hook scriptCursor eventWhat it does
guard_shell.pybeforeShellExecutiondeny: rm -rf / or ~, disk wipes, fork bombs, curl ... | sh, cat .env, bare printenv. ask: force push, reset --hard, DROP TABLE, terraform destroy, kubectl delete, npm publish, docker system prune, sudo, commands with a secret in them. Everything else is allowed.
guard_mcp.pybeforeMCPExecution (failClosed: true)allow-list of MCP servers by mcp_server_name; unknown servers are denied; write-like tools (create_, delete_, send_, merge_...) ask first; secrets in tool arguments ask first.
guard_read.pybeforeReadFilekeeps .env, *.pem, SSH keys, .npmrc, .netrc, *secrets*.json and any file containing an API key or private key out of the model context. .env.example and *.pub stay readable.
scan_prompt.pybeforeSubmitPromptblocks a prompt that contains an API key, token, private key or a database URL with a password (OpenAI, Anthropic, AWS, GitHub, Stripe, Slack, Google, JWT). The secret itself is never printed.
format_on_edit.pyafterFileEditruns the first installed formatter for the file (ruff/black, prettier from your node_modules, gofmt, rustfmt). Missing tools are skipped silently.
stop_tests.pystop (loop_limit: 3)when the agent says it's done, runs your test command; if it fails, the failure tail goes back to the agent as a follow-up so it keeps fixing (max 3 rounds). Off until you set stop.test_command.
session_context.pysessionStartadds a short briefing to each new chat: git branch, uncommitted files, last commit, a warning on main, and which instruction files (AGENTS.md, CLAUDE.md, rules) to read.
audit_log.pyshell, MCP, edits, stopappends one JSON line per event to .cursor/hooks/logs/audit.jsonl, with secrets redacted and long fields cut.

All rules live in one file, .cursor/hooks/policy.json: add your MCP servers to mcp.allow_servers, set stop.test_command (for example npm test or pytest -q), and add or remove patterns. The installer never overwrites your edited policy.json.

Install

python3 tools/install.py /path/to/your/project --dry-run     # see what it will add
python3 tools/install.py /path/to/your/project               # all hooks, project level (.cursor/hooks.json)
python3 tools/install.py /path/to/your/project --only guard_shell,guard_read,scan_prompt
python3 tools/install.py --user                              # for every project (~/.cursor/hooks.json)
python3 tools/install.py /path/to/your/project --uninstall   # removes only what this pack added

The installer merges into an existing hooks.json (your own hooks stay, nothing is added twice), puts guards before observers, and saves hooks.json.bak-<time> first. Cursor reloads hooks.json on save; open the Hooks tab in Customize (or the Hooks output channel) to see them. Commit .cursor/hooks.json and .cursor/hooks/ to share them with your team; cloud agents run project command hooks too (except sessionStart and beforeMCPExecution, which Cursor does not run there).

hookcheck: why isn't my hook running?

python3 tools/hookcheck.py check                         # .cursor/hooks.json in this project
python3 tools/hookcheck.py check --user                  # also ~/.cursor/hooks.json
python3 tools/hookcheck.py simulate beforeShellExecution --command "git push --force"
python3 tools/hookcheck.py simulate beforeReadFile --file .env
python3 tools/hookcheck.py simulate stop --status completed
python3 tools/hookcheck.py simulate beforeMCPExecution --input samples/beforeMCPExecution.json
python3 tools/hookcheck.py events                        # every event, its matcher value and output fields

check catches: invalid JSON (trailing commas, comments), missing "version": 1, unknown or Claude Code event names (PreToolUse -> preToolUse), misspelled options, script paths that don't resolve from where the hook runs (project hooks run from the project root, so ./hooks/x.sh must be .cursor/hooks/x.sh; user hooks run from ~/.cursor), scripts that aren't executable or have no #! line or Windows line endings, interpreters or jq that aren't installed, invalid matcher regexes, matchers that can never match (afterFileEdit is matched against Write, so "matcher": "Edit" never runs), timeout given in milliseconds, loop_limit on the wrong event, and security hooks without failClosed.

simulate runs the hooks for one event exactly as Cursor would (same working directory, JSON on stdin, CURSOR_PROJECT_DIR, matcher, timeout) and checks the output: one JSON object on stdout, valid permission values for that event, exit code 2 = deny, crashes fail open unless failClosed. It prints the merged decision (deny beats ask beats allow). samples/ has a realistic input for every event.

Demo

./tools/demo.sh installs the pack into a throwaway project, checks it and simulates four events (see the preview image).

How it was tested

./run_tests.sh (18 tests, Python 3.13 and 3.10): 11 deny, 11 ask and 10 allow shell cases (including look-alikes such as rm -rf /tmp/build and curl ... | jq), MCP allow-list and write-tool rules, protected files and secret content, prompt secret detection, audit redaction, the stop loop (fails -> follow-up, stops at the limit), the session briefing in a real git repo, install/merge/uninstall that keeps your own hooks and policy, and the checker/simulator on broken configs.

Honest limits

  • Hooks are a safety net, not a sandbox: a determined agent can still do damage through a path no rule covers. Keep Cursor's own approval settings on for anything that matters.
  • Pattern rules can miss obfuscated commands (variables, base64, aliases) and can flag harmless ones; edit policy.json.
  • The scripts are tested on macOS/Linux/WSL. On Windows, Cursor runs hooks through PowerShell: install with --python py (or python) and run hookcheck check there.
  • simulate runs your hooks locally with sample events; real Cursor input can carry more fields. Event names and fields follow the Cursor docs as of Nov 2026; Cursor may change them.

Format and license

Zip, 37 KB, v1.0, 38 files. You may use and modify this kit for your own work and for clients you serve, including paid client work. Not affiliated with or endorsed by Cursor.

FAQ

Does this work in Cursor's cloud agents?
Partly: shell, file and stop hooks do; MCP and session hooks don't run in cloud agents (Cursor's rule, Nov 2026).
Will it break my existing hooks.json?
No. The installer merges, backs up the old file and never overwrites your policy.json.
Is it a sandbox?
No. Hooks are a tripwire on what the agent asks to do; use a container for untrusted code.
How do I get the files?
Pay by card right here on youraitools.co: your download links appear on this page the moment the payment goes through (claim window: 72 hours, up to 5 downloads per 7 days). Need the files re-sent later? Email hello@youraitools.co.
Refunds?
Email hello@youraitools.co within 14 days if it doesn’t work and we can’t fix it.
Can I pay with crypto?
Yes. Pay the same price in USDC or USDT on Base, Ethereum, Arbitrum, Optimism, Polygon or Solana from the "Pay with crypto" button, with no account or KYC. We check the payment on-chain and show your download links as soon as it confirms.

Get Cursor Hooks Pack: 8 Ready hooks.json Hooks + Installer + Validator

8 ready Cursor hooks: block rm -rf and force pushes, protect .env, allowlist MCP servers, scan prompts for secrets, run tests on stop. Installer + validator.

Save with a bundle

Pairs well with

Download$19

Claude Code Safety Hooks

Tested Claude Code hooks as a plugin: block rm -rf and force-push to main, protect .env and lockfiles, catch API keys in files, audit log. $19 once.

View Claude Code Safety Hooks

Related

1 email a week: new x402 + MCP tools and free kits.

Short weekly digest of new x402 + MCP tools and free kits, including the MCP OAuth Checker. No spam, unsubscribe any time.