Cursor Hooks and Regression Tests

afterFileEdit, beforeShellExecution, and afterShellExecution are hook stages in Cursor hooks, and Auto-review shipped as the recommended default in 3.6 on May 29, 2026 in Cursor’s run modes. That means Cursor gives you controls around agent actions and a safety review for higher-risk calls, but a full regression suite should usually sit in a Cursor skill or CI workflow. Use a hook when a check must happen every time without judgment. Use a skill when the agent needs to follow a testing procedure and a missed run is recoverable.
For Cursor training, this is a useful Test and Review boundary. The question “should Cursor hooks run regression tests after every change” has a narrow answer: small mandatory gates can be hooks, full regression runs should be skills plus PR evidence.
Decide whether the test is a gate or a workflow
Regression testing is usually a workflow. It often needs scope, setup, a command, failure interpretation, and a decision about follow-up. That shape fits a Cursor skill better than a hook because the agent can call the procedure when the task reaches the testing step.
A hook is better when there is no real decision to make. For example, beforeShellExecution can control shell commands before they run. That is useful for a hard safety rule around a command, but it is a poor place to hide a long suite that the agent may need to understand and summarize.
This topic belongs with Subagents and skills, because the practical design is about where reusable agent behavior lives. A Cursor skill can carry the runbook. A hook can enforce the small boundary.
Rolling this out in your team?
We train engineering teams on their own codebase in two days. Cursor setup, shared rules and review included.
Use hooks for narrow enforcement
Cursor hooks run as spawned processes and communicate over stdio using JSON in both directions. Cursor can define them in hooks.json at the project or user level, or install them through plugins from Customize.
The merge rule matters. When several matching hooks run, any deny wins over ask, and ask wins over allow. That makes hooks useful for hard checks, especially around file edits, shell execution, and MCP tool usage.
Hooks still need maintenance. An agent can sometimes reach the same outcome through a path the hook author did not cover. When that happens, tighten the hook and keep the test evidence somewhere reviewers can inspect.
For a related hook-shaped workflow, see Cursor Progress Log Hook Events. Progress logging is a cleaner fit for hook events than making every edit wait on a full regression suite.
Keep PR evidence as the review layer
Auto-review is a run mode for reducing prompts while adding a safety review before higher-risk calls run. It is useful, but it is still about agent action safety. It is not proof that the regression suite passed.
A reviewer should trust the PR evidence: CI status and the code diff. Having an automatic review on a pull request is no reason to review less carefully.
This sits in the Review step of our methodology. Delegate the test run to the agent or CI, then review the evidence before merging.
Choose the right place for the check
| Place | Use it when | Limit to remember |
|---|---|---|
hooks.json hook |
The check is mandatory and maps cleanly to a hook stage such as afterFileEdit or beforeShellExecution. |
Hooks can need tightening when an indirect path appears. |
| Cursor skill | The regression run is a procedure the agent should follow and explain. | The agent must choose or be asked to use the skill. |
| CI or PR review | The team needs merge evidence a reviewer can trust. | It runs later than the edit loop, so fast feedback may need a smaller local check. |
Implement the split in Cursor
Put the full regression procedure in a Cursor skill. Give it a clear activation description, include the exact command the team uses, and tell the agent what output should be returned to the reviewer.
Keep hooks.json small. Use it for rules that must fire at a defined stage of the agent loop, such as blocking a risky shell command before it runs or asking before a sensitive action.
Make the PR check the source of truth for merge readiness. If the skill reports a passing run but CI fails, review the CI failure. If CI passes but the diff looks wrong, the reviewer still owns the decision.
Further reading
Next step
For the next change, write the regression run as a Cursor skill and keep hooks.json only for a small gate that must run every time.
Related research
Train your team on Cursor
Two days on your team's own repository, onsite or remote, with a written proposal before you commit.
Book a callPrefer to measure first? Take the free team check.