2 min lesson
beforeShellExecution denies rm -rf in-product
Tell someone how to act on this idea: "The job: you can distinguish steering from enforcement and place hooks at the right lifecycle point."
Step 1 of 2
The job: you can distinguish steering from enforcement and place hooks at the right lifecycle point. Start with this check: The gated action is stopped before it runs, not merely discouraged by a Rule. Keep it small enough to check the result yourself instead of taking the summary on trust.
Hooks stop the shell before it runs
0:26 · narratedRead this demo as text
- Ask the agent to run rm -rf on a temp directory. A Rule might say please don't. That is not enough.
- Rejected before the shell ran. The deny-rm hook fired. Change that gate in Cursor Settings, Hooks — not by hoping the model remembers.
Practice next: Now do the module workflow: place a deterministic deny on beforeShellExecution and test both the blocked and allowed paths.
Simulated Cursor 3.12 (macOS, light) — beta educational reconstruction, not the real product.
Learn more
Full explanation
Agent hooks, beforeShellExecution
[[ "$command" =~ git[[:space:]]+push ]] && [[ "$command" =~ --force|--force-with-lease|-f ]] && [[ "$command" =~ (^|[[:space:]])main([[:space:]]|$) ]]{ "permission": "deny", "user_message": "Force-push to main is blocked. Open a PR instead." }Learn more
Optional practice
Practice: beforeShellExecution denies rm -rf in-product
QYou've applied it. What actually proves the work is done, not just a plausible answer?