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.
| Moment | Cursor AgentHook commands |
|---|---|
| Hook types |
|
| Session and workspace | |
| Session starts | sessionStartadd context, set environment Fire-and-forget; continue:false does not block session creation. |
| Workspace opens | workspaceOpenload extra resources Returns pluginPaths to load; fires on every workspace folder change. |
| Session ends | sessionEndobserve only |
| Prompt and turn | |
| User submits a prompt | beforeSubmitPromptblock Cursor's 2.4 changelog mentions modifying prompts, but the hooks reference documents no output field for it. |
| After the agent thinks | afterAgentThoughtobserve only |
| After the agent responds | afterAgentResponseobserve only |
| Agent finishes its turn | |
| Tools | |
| Before a tool runs | |
| After a tool succeeds | |
| After a tool fails | |
| Shell, terminals and files | |
| Before a shell command | beforeShellExecutionallow, deny, ask user |
| After a shell command | afterShellExecutionobserve only |
| Before a file is read | beforeReadFileallow, deny |
| Before Tab reads a file | |
| After a file is edited | afterFileEditobserve only |
| After Tab edits a file | |
| MCP | |
| Before an MCP tool runs | beforeMCPExecutionallow, deny, ask user Cursor recommends failClosed: true for security-critical MCP hooks. |
| After an MCP tool runs | afterMCPExecutionobserve only |
| Subagents | |
| Subagent starts | |
| Subagent finishes | |
| Context and compaction | |
| Before context is compacted | |
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.
- Cursor hooks, Documentation, checked 2026-10-15