Harness Notes

Hooks

Updated 2026-11-24,

On this page

Which moments a hook can attach to, and what it can do there. Event names link to each harness’s documentation. “Block”, “deny” and “modify” change what the agent does; “observe only” can watch but not intervene. Where hook files live is on the Locations page.

MomentCursor AgentHook commands
Hook types
  • command
  • prompt
Session and workspace
Session starts
sessionStart

add context, set environment

Fire-and-forget; continue:false does not block session creation.

Workspace opens
workspaceOpen

load extra resources

Returns pluginPaths to load; fires on every workspace folder change.

Session ends
sessionEnd

observe only

Prompt and turn
User submits a prompt
beforeSubmitPrompt

block

Cursor's 2.4 changelog mentions modifying prompts, but the hooks reference documents no output field for it.

After the agent thinks
afterAgentThought

observe only

After the agent responds
afterAgentResponse

observe only

Agent finishes its turn
stop

queue follow-up

loop_limit caps follow-ups (default 5).

Tools
Before a tool runs
preToolUse

allow, deny, modify

ask is accepted by the schema but not enforced for preToolUse.

After a tool succeeds
postToolUse

add context, modify

Output can be replaced only for MCP tools.

After a tool fails
postToolUseFailure

add context

Also fires on timeouts and permission denials.

Shell, terminals and files
Before a shell command
beforeShellExecution

allow, deny, ask user

After a shell command
Before a file is read
beforeReadFile

allow, deny

Before Tab reads a file
beforeTabFileRead

allow, deny

Tab completions only, not the agent.

After a file is edited
afterFileEdit

observe only

After Tab edits a file
afterTabFileEdit

observe only

Tab completions only, not the agent.

MCP
Before an MCP tool runs
beforeMCPExecution

allow, deny, ask user

Cursor recommends failClosed: true for security-critical MCP hooks.

After an MCP tool runs
afterMCPExecution

observe only

Subagents
Subagent starts
subagentStart

allow, deny

ask is treated as deny.

Subagent finishes
subagentStop

queue follow-up

The follow-up is used only when the subagent completed.

Context and compaction
Before context is compacted
preCompact

observe only

Cannot block or modify compaction; can show a message to the user.

Notes and sources

Cursor Agent
  • Permission hooks block when output is invalid JSON or does not match the schema; crashes, timeouts and other exit codes fail open unless the hook sets failClosed: true.
  • When several hooks answer, deny beats ask and ask beats allow.
  • Sources run in priority order enterprise, team, project, user; project hooks run only in trusted workspaces.
  • Cloud agents run only command hooks and skip sessionStart, sessionEnd, workspaceOpen, MCP and Tab hooks; no hooks run during early read-only turns.