Cursor Hooks Reference: hooks.json, Run Modes and failClosed
Short answer. A Cursor hook is a command listed in hooks.json that runs before or after an agent action. beforeShellExecution and beforeMCPExecution can return permission: "deny" to block a call. If a hook crashes, the call goes through unless that hook sets failClosed: true. This is the entry the ACP installer writes to ~/.cursor/hooks.json, under both preToolUse and postToolUse:
{
"hooks": {
"preToolUse": [
{ "matcher": ".*",
"hooks": [ { "type": "command", "timeout": 5,
"command": "env ACP_CLIENT=cursor node $HOME/.acp/govern.mjs" } ] }
],
"postToolUse": [ /* same entry */ ]
}
}
Install the ACP hook in one command → · Cursor's full control model → · free up to 5 agents
Cursor’s permission settings changed a lot this year. Yolo mode became Auto-Run, then Run Modes. Two modes were deleted in May, and a week later an LLM classifier became the recommended default. Hooks stayed put through all of it: a long event list, a documented input and output format, and the same behavior every time a hook runs. This page covers what goes in hooks.json, what each event receives and returns, and the one default you should know before relying on a hook.
Where hooks live
hooks.json is read at four layers. The highest layer wins on a conflict, and all matching hooks run.
| Scope | Location |
|---|---|
| Enterprise (MDM) | /Library/Application Support/Cursor/hooks.json (macOS), /etc/cursor/hooks.json (Linux/WSL), C:\ProgramData\Cursor\hooks.json (Windows) |
| Team | Web dashboard, Enterprise only, synced roughly every 30 minutes |
| Project | <project-root>/.cursor/hooks.json, requires a trusted workspace |
| User | ~/.cursor/hooks.json, where the ACP installer writes |
The top level has a version number (default 1) and a hooks object that maps event names to arrays of definitions. Each definition takes command (required), type ("command" by default, or "prompt"), timeout in seconds, matcher, and failClosed. Project hooks run from the project root. User hooks run from ~/.cursor/.
The events
Cursor lists more events than most harnesses. The agent-facing ones, in loop order:
sessionStart, sessionEnd, preToolUse, postToolUse, postToolUseFailure, subagentStart, subagentStop, beforeShellExecution, afterShellExecution, beforeMCPExecution, afterMCPExecution, beforeReadFile, afterFileEdit, beforeSubmitPrompt, preCompact, stop, afterAgentResponse, afterAgentThought.
Three more sit outside the agent loop. beforeTabFileRead and afterTabFileEdit apply to inline Tab completions only, not Cmd+K or Agent Chat. workspaceOpen fires when a workspace opens or its folders change, and its payload has no session, conversation, or model fields.
For blocking, the shell and MCP pair matter most. beforeShellExecution and beforeMCPExecution can stop a call before it runs, with a full permission: allow | deny | ask contract. preToolUse fires for every tool and can rewrite input through updated_input. Its ask value is accepted by the schema but not enforced, so use it to observe and rewrite, not to hold a call for a human.
What each hook receives and returns
beforeShellExecution: in: command, cwd, sandbox. Out: permission (allow/deny/ask), user_message, agent_message.
beforeMCPExecution: in: tool_name, tool_input (a JSON string), mcp_server_name, plus url / mcp_server_url for HTTP/SSE servers or command for stdio ones. Out: the same permission shape. The docs advise treating a missing or unexpected mcp_server_name as a deny.
preToolUse: in: tool_name, tool_input, tool_use_id, cwd, agent_message. Out: permission (allow/deny; ask accepted, not enforced), user_message, agent_message, updated_input.
postToolUse: in: tool_name, tool_input, tool_output (JSON-stringified), tool_use_id, cwd, duration. Out: updated_mcp_tool_output (MCP calls only), additional_context.
beforeReadFile: in: file_path, content, attachments. Out: permission (allow/deny). Like the rest, it lets the call through on a crash unless the hook sets failClosed: true.
Exit codes. 0 with JSON on stdout is the normal path. 2 blocks, the same as permission: "deny". Any other exit code counts as no decision, so the call goes through.
Matchers
A matcher decides when a hook fires. What it matches depends on the event:
preToolUse,postToolUseandpostToolUseFailurematch a tool type:Shell,Read,Write,Grep,Delete,Task, orMCP:<tool_name>.beforeShellExecutionandafterShellExecutionmatch the full command string.subagentStartandsubagentStopmatch the subagent type.
With no matcher, the hook sees every call for that event.
Common input, and the prompt hook type
Every payload except workspaceOpen carries conversation_id, generation_id, model, model_id, hook_event_name, cursor_version, workspace_roots, user_email, and transcript_path. A sessionStart hook can return an env object that carries into later hooks in the session.
Cursor has a second hook type besides command. A type: "prompt" hook runs a fast LLM against a plain-English condition and returns { ok: boolean, reason }, with $ARGUMENTS replaced by the hook’s input JSON. You write and register it yourself. The Run Modes classifier below is different: it is a default that looks at every call no rule matched.
failClosed: the default to design around
failClosed defaults to false on every event. A crashed hook, a timeout, or invalid JSON on stdout does not hold the call. It goes through as if no hook were registered. If a hook is your enforcement (a deny rule, a policy check, an approval gate), an outage in that hook’s own dependencies turns it off without a sound. Cursor’s docs recommend failClosed: true on security-critical beforeMCPExecution hooks. It is also documented on beforeReadFile. Nothing makes you set it on the others.
The ACP hook behaves the same way, for its own reasons. The installer’s entry above does not set failClosed, and the shared script that Cursor, Codex and other hook-file harnesses use fails open in every tier. If the gateway is unreachable, the call runs and the hook prints an UNGOVERNED warning. To block instead, run echo closed > ~/.acp/failmode (or set ACP_FAIL_MODE=closed) on that machine. The Claude Code plugin is a separate case: it also fails open in interactive sessions, but fails closed for subagent, background and API sessions. The Claude Code hooks reference has that contract.
Run Modes and the classifier
Hooks are one layer. The setting around them is the Run Mode, and it decides what a hook’s ask is up against:
- Auto-review (recommended default). Allowlisted calls run. Other shell commands run sandboxed where possible. Whatever is left goes to an LLM classifier, a small Cursor-managed model, that returns allow, try-something-different, or ask. It covers shell, MCP and fetch.
- Allowlist. Listed actions run and everything else prompts. No classifier, and the sandbox is optional.
- Run Everything. Everything auto-runs: no sandbox, no classifier, no prompts.
The classifier is a judgment call, not a rule. Cursor’s own docs call the allowlist beneath it “best-effort, not a security boundary.” A beforeShellExecution or beforeMCPExecution hook that returns deny is checked separately from the Run Mode. A preToolUse ask is not enforced, so it cannot hold a call in any of the three.
What the ACP hook does on Cursor
The ACP integration for Cursor installs the same govern.mjs script that Codex and other hook-file harnesses use, registered under both preToolUse and postToolUse in ~/.cursor/hooks.json. It also adds an ACP entry to ~/.cursor/mcp.json. Before a call, preToolUse posts to the gateway and blocks on deny. After a call, postToolUse posts the result for the audit log and flags PII and secrets. The installer detects Cursor by ~/.cursor or cursor on your PATH, and you can re-run it safely.
Because ACP uses preToolUse, where ask is not enforced, a call that needs approval is blocked. You approve it on the Approvals page or from the email, then ask the agent to retry. Cursor does not show the hold as a prompt. The coverage matrix lists this for every harness.
Two limits. Cursor’s hook API is newer and less settled than Claude Code’s, so field names have moved and may move again. And postToolUse is observe-only: ACP can log findings but cannot rewrite tool output before Cursor passes it to the model. Some built-in Cursor tools also don’t fire hooks at all, so a rule can’t see them.
No skip-permissions flag, but Run Everything exists
Cursor has no flag like Claude Code’s --dangerously-skip-permissions. Run Everything is the closest thing: it auto-runs tools with no prompts. Cursor’s docs treat hooks as a separate layer from Run Modes, so a hook still runs. We have not tested every mode, so check your own setup. Antigravity’s yolo mode is different, because it removes hooks entirely, ACP’s included.
Known limitations
preToolUse’saskisn’t enforced. To hold a call for a person, usebeforeShellExecutionorbeforeMCPExecution, which both honorask.failClosedis opt-in, per hook. A hook you rely on for enforcement has to set it.- The allowlist under the classifier is best-effort. Cursor’s docs name three published CVEs of allowlist bypass. A hook’s
denyis a fixed rule. The classifier’s verdict is a judgment. - Cloud agents only read project hooks.
.cursor/hooks.jsonin the repo applies.~/.cursor/hooks.jsondoes not reach a cloud agent run.
Compared with Claude Code and Antigravity
Claude Code’s PreToolUse contract is the closest match: the same exit-code-2-or-JSON shape and the same matcher idea. The Claude Code hooks reference has it in full. The Antigravity hooks reference covers its fail-closed core and its native force_ask decision, which neither Claude Code nor Cursor has.
Frequently asked questions
What hook events does Cursor support?
A wide agent set: sessionStart, sessionEnd, preToolUse, postToolUse, postToolUseFailure, subagentStart, subagentStop, beforeShellExecution, afterShellExecution, beforeMCPExecution, afterMCPExecution, beforeReadFile, afterFileEdit, beforeSubmitPrompt, preCompact, stop, afterAgentResponse, afterAgentThought. Tab has its own two (beforeTabFileRead, afterTabFileEdit), and workspaceOpen fires when a workspace opens, outside any agent session.
Does failClosed default to true or false in Cursor?
False. A crashed, timed-out, or invalid-JSON hook lets the action through unless that hook sets failClosed: true. Cursor’s docs recommend true for security-critical beforeMCPExecution hooks. It is also supported on beforeReadFile.
What are Cursor's three Run Modes?
Auto-review (the recommended default) runs allowlisted calls, sandboxes other shell commands where possible, and sends whatever is left to an LLM classifier that returns allow, try-something-different, or ask. Allowlist runs listed actions and prompts for the rest, with no classifier. Run Everything auto-runs everything: no sandbox, no classifier, no prompts.
Can a Cursor hook block an MCP tool call?
Yes. beforeMCPExecution receives the MCP server name and tool input and can return permission: deny. The generic preToolUse hook also sees MCP calls (matcher MCP:
What does the ACP hook do on Cursor if the gateway is down?
It lets the call run and prints an UNGOVERNED warning. The shared hook Cursor uses fails open unless you set ACP_FAIL_MODE=closed or put the word closed in ~/.acp/failmode on that machine.
Where to read more
- Cursor hooks docs: the upstream reference this page checks against
- Cursor’s full control model: Run Modes, the sandbox, the allowlist CVEs, and where the model ends
- Cursor
permissions.jsonreference:terminalAllowlist,mcpAllowlist,autoRunwithallow_instructions/block_instructions, examples, precedence - Install ACP for Cursor: the hook, what it writes, and its documented limits
- Harness coverage matrix: what ACP sees on each coding agent
- Cursor cost tracking reference: what hooks can’t see
- Claude Code hooks reference: the closest matching contract
- Codex CLI hooks reference: a narrower, shell-first hook set
Running Cursor? One command adds a hook. Each tool call it sees is recorded, and a force-push, destructive SQL or curl | sh is blocked until you approve it on the console or from the email.
curl -fsSL https://agenticcontrolplane.com/install.sh | bash
irm https://agenticcontrolplane.com/install.ps1 | iex
What the installer writes · Cursor guide · free up to 5 agents