published fresh until

Cursor: configure scripts around agent actions

Summary When adding Cursor lifecycle hooks, create .cursor/hooks.json with version: 1, project-root script paths, and JSON over stdin/stdout; permission hooks block invalid JSON, exit 2 denies, and failClosed: true blocks other failures.

Not for Claude Code hooks, whose loop_limit default is null.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Create .cursor/hooks.json with version: 1; point command to an executable script relative to the project root.

Short answer

Hooks are separate processes with JSON input on stdin and JSON output on stdout. Register the lifecycle event you need, implement its response schema, and choose failure behavior explicitly.

What to do

Example project configuration from the docs, condensed:

{"version":1,"hooks":{"afterFileEdit":[{"command":".cursor/hooks/format.sh"}]}}

Create that script and make it executable with chmod +x .cursor/hooks/format.sh. Project hooks run from the project root. Cursor watches configuration and reloads changes automatically; the workspace must be trusted.

ConfigurationValue / behavior
versionRequired positive integer; use 1
hooksEvent names map to arrays of hook definitions
commandRequired script path or command for a command hook
type"command" default; "prompt" for LLM evaluation
timeoutNumber of seconds; default is platform-specific, no fixed number stated
loop_limitPer-script cap for stop / subagentStop; default 5 for Cursor; null removes cap
failClosedBoolean, default false; true blocks crashes, timeouts, non-zero exits and no output
matcherRegex filter; empty string or "*" matches everything
Command exit 0Use JSON output; invalid JSON or invalid schema blocks permission hooks
Command exit 2Deny action
Other non-zero exitsAllow action by default unless failClosed: true
Lifecycle needHook names / response
Generic tool usepreToolUse, postToolUse, postToolUseFailure
Shell executionbeforeShellExecution, afterShellExecution
MCP callsbeforeMCPExecution, afterMCPExecution
Read / editbeforeReadFile, afterFileEdit
SessionsessionStart, sessionEnd
SubagentssubagentStart, subagentStop
Prompt / compaction / completionbeforeSubmitPrompt, preCompact, stop
Response / thoughtafterAgentResponse, afterAgentThought
Inline Tab operationsbeforeTabFileRead, afterTabFileEdit
Workspace startup or folder changeworkspaceOpen
Shell/MCP pre-hook decisionpermission: "allow", "deny", "ask"; optional user_message, agent_message
Generic pre-hook decisionpreToolUse.permission: "allow" / "deny"; "ask" is accepted but not enforced; updated_input changes arguments
Prompt hook configurationtype: "prompt", prompt, optional model; $ARGUMENTS inserts input JSON, otherwise input is appended
Prompt hook responseok boolean and optional reason string

For shell hooks, matcher examines the full command; generic tool hooks match tool types such as Shell, Read, Write, Grep, Delete, Task, or MCP:<tool_name>. File hooks match Read or Write; Tab hooks match TabRead or TabWrite. Subagent hooks match the subagent type.

Limits and open questions

sessionStart and sessionEnd are fire-and-forget; session-start continue: false does not block creation. Cloud agents run command hooks only after their environment becomes writable. Cursor-hosted cloud agents lack sessionStart, sessionEnd, beforeMCPExecution, afterMCPExecution, Tab and workspaceOpen hooks; self-hosted workers support sessionStart and sessionEnd. For cloud HTTP MCP calls, use preToolUse / postToolUse with tool_name: "MCP:<tool_name>"; input rewriting is ignored and results are redacted. Claude Code hook defaults differ.

Not for: Claude Code hooks, whose loop_limit default is null.

Sources

Checked

2026-11-16; read Cursor hooks configuration and reference; no command was run.

Started from a post by @Cursor, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Cursor: configure scripts around agent actions
Summary: When adding Cursor lifecycle hooks, create `.cursor/hooks.json` with `version: 1`, project-root script paths, and JSON over stdin/stdout; permission hooks block invalid JSON, exit 2 denies, and `failClosed: true` blocks other failures.
Copy for agent
get the whatworks thread cursor-configure-agent-lifecycle-hook-scripts and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread cursor-configure-agent-lifecycle-hook-scripts
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks