Blog · Guide · 27 November 2026

Cursor Hooks: A Practical Guide for Teams of Agents

Cursor hooks are commands Cursor runs at fixed points in an agent's work: when a session starts, before a prompt is sent, before and after each tool call, and when the agent stops. They are configured in a hooks.json file at user, project or enterprise level. A hook reads JSON on stdin and answers JSON on stdout, so it can deny a tool call, add text after a tool result, or send a follow-up message when the agent finishes. This guide covers the events that matter when Cursor works alongside other agents, the limits worth knowing before you rely on them, and how to wire Cursor into a shared coordination layer.

Facts about Cursor come from its documentation, read on 27 Nov 2026 and listed at the end.

Where Cursor hooks live

Cursor reads hooks.json from four places, highest priority first:

Level Location Notes
Enterprise /Library/Application Support/Cursor/hooks.json (macOS), /etc/cursor/hooks.json (Linux, WSL), C:\ProgramData\Cursor\hooks.json (Windows) Managed by MDM
Team Web dashboard Enterprise only, synced to members
Project <project-root>/.cursor/hooks.json Runs only in a trusted workspace; commands run from the project root
User ~/.cursor/hooks.json Commands run from ~/.cursor/

The file has version: 1 and a hooks object that maps event names to lists of definitions. Each definition needs a command and may set type (command or prompt), timeout, loop_limit, failClosed and a matcher:

{
  "version": 1,
  "hooks": {
    "preToolUse": [
      { "command": ".cursor/hooks/check-claims.sh", "matcher": "Shell|Write", "timeout": 30 }
    ]
  }
}

The events that matter for a team

Cursor lists about twenty agent events. Five do most of the work when several agents share a repository.

preToolUse and beforeShellExecution: refuse a tool call. preToolUse sees tool_name and tool_input and answers with permission (allow or deny), an optional user_message, an agent_message the model reads, and updated_input to rewrite the call. beforeShellExecution is the shell-only version and also accepts ask. The docs say ask is accepted by the preToolUse schema but "not enforced for preToolUse today", so do not build an approval flow on it.

postToolUse: hand the agent some text. Its additional_context is "injected into the conversation after the tool result". This is the cleanest way to deliver a message to an agent that is busy: it arrives with the next tool result, not as an interruption.

afterFileEdit: know what changed. It receives the absolute file_path and the edits. It produces no output, so it is for reporting, not refusing.

stop: keep the agent going. A non-empty followup_message "is automatically submitted as the next user message". loop_limit caps how many times in a row this can happen; it defaults to 5 for Cursor hooks.

sessionStart and sessionEnd: bookkeeping only. Session start is fire-and-forget. Cursor's docs say session creation "is not blocked" even when a hook returns continue: false. It can return env and additional_context, but it cannot stop a session from starting.

Exit codes and failing open

Exit 0 means Cursor reads the JSON. For permission hooks, invalid JSON or a schema mismatch blocks the action. Exit 2 blocks, the same as permission: "deny". Any other exit code means the hook failed and the action proceeds. Set failClosed: true on a definition to make crashes and timeouts block instead. For a hook that guards files another agent owns, decide which failure you prefer: a stuck hook that blocks every edit, or a crashed hook that lets one through.

What Cursor cannot do through hooks

Three gaps shape any design:

  1. No permission-request event. Claude Code and Codex fire a hook when the agent is about to ask a person for approval, so a remote answer can replace the terminal prompt. Cursor does not. Its third-party hooks page lists PermissionRequest among the Claude Code events it does not support.
  2. ask is not enforced on preToolUse. You can allow or deny, not pause for a person.
  3. Session start cannot block. A hook cannot refuse a session whose key has been revoked; it can only refuse that session's later tool calls.

The double-reporting trap: Cursor also runs Claude Code's hooks

Cursor's "Third-Party Imports" setting loads hooks from .claude/settings.local.json, .claude/settings.json and ~/.claude/settings.json, and the docs say "The setting is on by default." Cursor maps Claude Code's event names to its own (PreToolUse to preToolUse, Stop to stop, and so on) and its tool names (Bash to Shell, Edit to Write; Glob is unsupported).

If you have Claude Code hooks installed and you add Cursor hooks too, the same script can run twice for one event: once from hooks.json, once from the imported Claude file. A script that reports changed files will report them twice; a script that counts tool calls will double-count. Either turn the import off, or make the script notice it has already run natively.

Example: refuse edits to files another agent claimed

The common team case: agent A is rewriting src/router.ts, and Cursor should not touch it until A is done. A preToolUse hook on Write reads the target path from tool_input, asks a shared service whether someone else holds that path, and denies with the holder's name:

#!/bin/sh
# .cursor/hooks/check-claims.sh (sketch)
input=$(cat)
path=$(printf '%s' "$input" | jq -r '.tool_input.file_path // empty')
holder=$(lookup-holder "$path")   # your claims service
if [ -n "$holder" ]; then
  printf '{"permission":"deny","agent_message":"%s is being edited by %s. Pick other work or ask them."}' "$path" "$holder"
else
  printf '{"permission":"allow"}'
fi

The agent_message matters more than the refusal. An agent told only "denied" often retries; an agent told who holds the file and what to do instead usually moves on. File locking for AI agents covers why time-limited claims work better than hard locks.

Example: give a busy agent a message

Hand a message over in postToolUse:

{ "additional_context": "Message from the planner: the API now returns cents, not dollars. Update the totals in your change." }

The agent sees it next to the result of the tool it just ran, carries on, and is not interrupted mid-command.

Setting up Cursor with Forkit

Forkit's hook script does the above for Cursor, Claude Code, Codex and others from one file. As of 26 Nov 2026:

  • Detecting Cursor. The script recognises Cursor by cursor_version in the payload or CURSOR_VERSION in the environment, turns Cursor's payload into one internal shape, and answers in Cursor's own fields: permission, additional_context and followup_message.
  • No double reporting. When Cursor runs the script through the imported .claude/settings.json but Cursor's own hooks.json already has Forkit, the imported call is skipped.
  • Claims. An edit under another agent's exclusive claim is refused, naming the holder.
  • Messages. Messages from other agents and replies from people arrive through postToolUse and stop.

For your own machine, npx forkit-cli init writes Forkit's hooks into ~/.cursor/hooks.json when it finds Cursor (for sessionStart, beforeSubmitPrompt, preToolUse, postToolUse, stop and sessionEnd), with a backup first. For a repository that sandboxes or teammates clone:

npx forkit-cli init --sandbox --project --agents cursor

That writes .cursor/hooks.json to commit, and the key comes from FORKIT_API_KEY at run time.

Limits, stated plainly

  • Not yet run against a real Cursor. Forkit's Cursor support was built on 26 Nov 2026 from Cursor's documentation and tested with the payloads the docs describe. It has not yet been run against a real Cursor session. Treat it as a preview until it has.
  • Cursor's CLI. Cursor's docs mention the CLI only for workspaceOpen. Users have reported, in Cursor's forum rather than its docs, that some cursor-agent versions skip hooks.json or load only project-level hooks. Test the CLI on your platform before relying on it.
  • No remote approval. Since Cursor has no permission-request event, Forkit cannot hold a Cursor prompt and answer it from the inbox the way it does for Claude Code.

When you do not need any of this

If you run one Cursor agent at a time, Cursor's own approvals and a project rules file are enough. Hooks earn their keep once several agents, possibly from different vendors, share a repository and need to keep off each other's files. For how Cursor's hooks line up with the other agents', see Claude Code hooks vs MCP and the Codex hooks guide.

Checklist

  • Decide user-level or project-level hooks.json (project hooks need a trusted workspace).
  • Check whether Third-Party Imports is on, and avoid running the same script twice.
  • Use preToolUse to deny, with an agent_message that says what to do instead.
  • Use postToolUse additional_context to deliver messages.
  • Set loop_limit on stop hooks so a follow-up cannot loop forever.
  • Choose failClosed deliberately for guard hooks.
  • Test cursor-agent separately from the IDE.

Forkit has a Free plan; Pro is $20 a month and Team $40 per seat a month, billed per person, never per agent. More at forkit-mcp.com.

Sources

Read on 27 Nov 2026: