create-hook
Skill4 starsChanged 3 months agoMITView on GitHub
Create Cursor hooks. Use when you want to create a hook, write hooks.json, add hook scripts, or automate behavior around agent events.
We split this skill into the rules it gives an agent
35 rules. 0 are common, 24 are distinctive, and 11 are very specific to this project.
0
Common
Most of the 13 edited versions we read keep these.
24
Distinctive
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 9
Create hooks when you want Cursor to run custom logic before or after agent events.
- Distinctive: line 11
When the user asks for a hook, don't stop at describing the format.
- Distinctive: line 15
Before you write anything, determine:
- Distinctive: line 17
Scope: Should this be a project hook or a user hook?
- Distinctive: line 19
Behavior: Should it audit, deny/allow, rewrite input, inject context, or continue a workflow?
- Distinctive: line 20
Implementation: Should it be a command hook (script) or a prompt hook?
- Distinctive: line 22
Safety: Should failures fail open or fail closed?
- Very specific: line 33
Project hooks: run from the project root, so use paths like .cursor/hooks/my-hook.sh
- Very specific: line 34
User hooks: run from ~/.cursor/, so use paths like ./hooks/my-hook.sh or hooks/my-hook.sh
- Distinctive: line 36
Prefer project hooks when the behavior should be shared with the repository and checked into version control.
- Distinctive: line 40
Use the narrowest event that matches the user's goal.
- Very specific: line 74
Create a hooks.json file with schema version 1:
- Distinctive: line 100
Use matchers to avoid running the hook on every event.
- Very specific: line 112
Do not use POSIX classes like [[:space:]].
- Distinctive: line 113
If the matcher is at all tricky, start by getting the hook working without one or with a very simple matcher, then tighten it after the …
- Distinctive: line 115
If the user wants a hook for only one risky command family, prefer script-side filtering for the first working version and add a matcher …
- Distinctive: line 121
Before using a command hook, verify that every executable it depends on will actually run in the hook environment:
- Very specific: line 125
if the script depends on tools like jq, python3, node, or repo-local CLIs, verify that explicitly before finishing
- Distinctive: line 127
Do not assume a binary exists just because it is common on your machine.
- Distinctive: line 170
Always make hook scripts executable after creating them.
- Distinctive: line 191
Use prompt hooks for lightweight policy decisions.
- Distinctive: line 195
Use the event's supported output fields only.
- Very specific: line 203
When the user wants to rewrite a tool call, prefer preToolUse.
- Very specific: line 208
Create or update the correct hooks.json file
- Distinctive: line 209
Start with no matcher or the simplest safe matcher
- Distinctive: line 210
Create the script under the matching hooks directory
- Distinctive: line 211
Read stdin JSON and implement the required behavior
- Very specific: line 213
Verify any helper executables the script uses are installed and on $PATH
- Distinctive: line 215
Verify behavior in Cursor's Hooks settings tab or the Hooks output channel
- Distinctive: line 217
If you are editing an existing hooks setup, preserve unrelated hooks and only change the minimum necessary entries.
- Distinctive: line 222
If hooks still do not load, restart Cursor
- Distinctive: line 226
If the hook does not appear to load at all, suspect matcher/config parsing first.
- Very specific: line 227
If the script runs external commands, verify each one is installed and reachable from the hook process with command -v or equivalent
- Very specific: line 228
If the hook should block on failure, set failClosed: true
- Very specific: line 229
If a command hook should intentionally block, returning exit code 2 is valid
“Common” is measured: kept by at least 6 in 10 of the 13 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Creating Cursor Hooks
Create hooks when you want Cursor to run custom logic before or after agent events. Hooks are scripts or prompt-based checks that exchange JSON over stdin/stdout and can observe, block, modify, or follow up on behavior.
When the user asks for a hook, don't stop at describing the format. Gather the missing requirements, then create or update the hook files directly.
Gather Requirements
Before you write anything, determine:
- Scope: Should this be a project hook or a user hook?
- Trigger: Which event should run the hook?
- Behavior: Should it audit, deny/allow, rewrite input, inject context, or continue a workflow?
- Implementation: Should it be a command hook (script) or a prompt hook?
- Filtering: Does it need a matcher so it only runs for certain tools, commands, or subagent types?
- Safety: Should failures fail open or fail closed?
Infer these from the conversation when possible. Only ask for the missing pieces.
Choose the Right Location
- Project hooks:
.cursor/hooks.jsonand.cursor/hooks/* - User hooks:
~/.cursor/hooks.jsonand~/.cursor/hooks/*
Path behavior matters:
- Project hooks run from the project root, so use paths like
.cursor/hooks/my-hook.sh - User hooks run from
~/.cursor/, so use paths like./hooks/my-hook.shorhooks/my-hook.sh
Prefer project hooks when the behavior should be shared with the repository and checked into version control.
Choose the Hook Event
Use the narrowest event that matches the user's goal.
Common Agent events
sessionStart,sessionEnd: set up or audit a sessionpreToolUse,postToolUse,postToolUseFailure: work across all toolssubagentStart,subagentStop: control or continue Task/subagent workflowsbeforeShellExecution,afterShellExecution: gate or audit terminal commandsbeforeMCPExecution,afterMCPExecution: gate or audit MCP tool callsbeforeReadFile,afterFileEdit: control file reads or post-process editsbeforeSubmitPrompt: validate prompts before they are sentpreCompact: observe context compactionstop: handle agent completionafterAgentResponse,afterAgentThought: track agent output or reasoning
Tab events
beforeTabFileRead: control file access for inline completionsafterTabFileEdit: post-process edits made by Tab
Quick event chooser
- Block or approve shell commands ->
beforeShellExecution - Audit shell output ->
afterShellExecution - Format files after edits ->
afterFileEdit - Block or rewrite a specific tool call ->
preToolUse - Add follow-up context after a tool succeeds ->
postToolUse - Control whether subagents can run ->
subagentStart - Chain subagent loops ->
subagentStop - Check prompts for secrets or policy violations ->
beforeSubmitPrompt - Protect MCP calls ->
beforeMCPExecution
Hooks File Format
Create a hooks.json file with schema version 1:
{
"version": 1,
"hooks": {
"afterFileEdit": [
{
"command": ".cursor/hooks/format.sh"
}
]
}
}Each hook definition can include:
command: shell command or script pathtype:"command"or"prompt"(defaults to"command")timeout: timeout in secondsmatcher: filter for when the hook runsfailClosed: block the action when the hook crashes, times out, or returns invalid JSONloop_limit: mainly forstopandsubagentStopfollow-up loops
Matchers
Use matchers to avoid running the hook on every event.
preToolUse/postToolUse/postToolUseFailure: match on tool type such asShell,Read,Write,Task, or MCP tools inMCP: ...formsubagentStart/subagentStop: match on subagent type such asgeneralPurpose,explore, orshellbeforeShellExecution/afterShellExecution: match on the full shell command stringbeforeReadFile: match on tool type such asReadorTabReadafterFileEdit: match on tool type such asWriteorTabWritebeforeSubmitPrompt: matches the valueUserPromptSubmit
Important matcher warning:
- Matchers use JavaScript-style regular expressions, not POSIX/grep syntax
- Do not use POSIX classes like
[[:space:]]; use JavaScript equivalents like\s - If the matcher is at all tricky, start by getting the hook working without one or with a very simple matcher, then tighten it after the hook is confirmed to load and fire
If the user wants a hook for only one risky command family, prefer script-side filtering for the first working version and add a matcher afterward only if it is simple and clearly correct.
Command Hooks
Command hooks are the default. They receive JSON on stdin and can return JSON on stdout.
Before using a command hook, verify that every executable it depends on will actually run in the hook environment:
- the script itself has a valid shebang and is executable
- any helper binary it calls is already installed and on
$PATH - if the script depends on tools like
jq,python3,node, or repo-local CLIs, verify that explicitly before finishing
Do not assume a binary exists just because it is common on your machine.
Minimal project-level example
{
"version": 1,
"hooks": {
"beforeShellExecution": [
{
"command": ".cursor/hooks/approve-network.sh",
"matcher": "curl|wget|nc ",
"failClosed": true
}
]
}
}#!/bin/bash
input=$(cat)
command=$(echo "$input" | jq -r '.command // empty')
if [[ "$command" =~ curl|wget|nc ]]; then
echo '{
"permission": "ask",
"user_message": "This command may make a network request. Please review it before continuing.",
"agent_message": "A hook flagged this shell command as a possible network call."
}'
exit 0
fi
echo '{ "permission": "allow" }'
exit 0Important behavior:
- Exit code
0: success - Exit code
2: block the action, same as returning deny - Other non-zero exit codes: fail open by default unless
failClosed: true
Always make hook scripts executable after creating them.
Prompt Hooks
Prompt hooks are useful when the policy is easier to describe than to script.
{
"version": 1,
"hooks": {
"beforeShellExecution": [
{
"type": "prompt",
"prompt": "Does this command look safe to execute? Only allow read-only operations. Here is the hook input: $ARGUMENTS",
"timeout": 10
}
]
}
}Use prompt hooks for lightweight policy decisions. Prefer command hooks when the logic must be deterministic or when the user needs exact, auditable behavior.
Event Output Cheat Sheet
Use the event's supported output fields only.
preToolUse: can returnpermission,user_message,agent_message, andupdated_inputpostToolUse: can returnadditional_context; for MCP tools it can also returnupdated_mcp_tool_outputsubagentStart: can returnpermissionanduser_messagesubagentStop: can returnfollowup_messagebeforeShellExecution/beforeMCPExecution: can returnpermission,user_message, andagent_message
When the user wants to rewrite a tool call, prefer preToolUse. When they want to gate only shell commands, prefer beforeShellExecution.
Implementation Workflow
- Pick the correct location and event
- Create or update the correct
hooks.jsonfile - Start with no matcher or the simplest safe matcher
- Create the script under the matching hooks directory
- Read stdin JSON and implement the required behavior
- Make the script executable
- Verify any helper executables the script uses are installed and on
$PATH - Trigger the relevant action to test the hook
- Verify behavior in Cursor's Hooks settings tab or the Hooks output channel
If you are editing an existing hooks setup, preserve unrelated hooks and only change the minimum necessary entries.
Validation and Troubleshooting
- Cursor watches
hooks.jsonand reloads on save - If hooks still do not load, restart Cursor
- Double-check relative paths:
- project hooks -> relative to the project root
- user hooks -> relative to
~/.cursor/
- If the hook does not appear to load at all, suspect matcher/config parsing first; remove the matcher and confirm the base hook works before tightening it
- If the script runs external commands, verify each one is installed and reachable from the hook process with
command -vor equivalent - If the hook should block on failure, set
failClosed: true - If a command hook should intentionally block, returning exit code
2is valid
Final Checklist
- Used the correct hook location and path style
- Chose the narrowest correct event
- Added a matcher when appropriate
- Returned only fields supported by that hook event
- Made the script executable
- Tested the hook by triggering the real event
- Checked the Hooks tab or Hooks output channel if debugging was needed
Other versions17 projects use a version of this.
Word for word · 4
- Goodnessmbakara/codex-skills★ 1100% same
- whyymj/page-agent-sdk★ 1100% same
- filipefalcaofs/repo-padrao★ 0100% same
- marslo/skills★ 0100% same
Edited · 3
- JameMy0001/antigravity-skills-hub★ 197% same
- leishifu666/skills★ 197% same
- PandelisZ/skills★ 198% same
Wrote their own version · 10
- microsoft/vscode★ 194ksame name
- am-will/codex-skills★ 1ksame name
- zhuangwenhui/CodingSkills★ 82same name
- KhaledSaeed18/dotclaude★ 5same name
- MacHatter1/bb-plugin-hooks★ 4same name
- tony-hoang-ai-automation/mkt-skills★ 4same name
- 0mlkrizzz655335v/claude-skills-zh★ 2same name
- Iteam-company/claude-code-boilerplates★ 2same name
- farzanmrz/meta-dev★ 0same name
- pahlevikun/levistack★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Used alongsideProjects with it also use review-bugbot, origin and 2 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
0mlkrizzz655335vSkillreview-bugbot
缺陷导向代码审查。用 Bugbot 子代理找 bug。
Also in 5 projects that use this
0mlkrizzz655335vSkillorigin
origin CLI 管理。安装、登录、更新、修复 origin.cursor.com 的 CLI。"disabled-environments:
Also in 3 projects that use this
HermeticOrmusSkillautomate
Turn a repetitive task into a reliable automation script. Scope the task and its frequency/inputs/outputs/edge cases, pick the simplest tool, implement the smallest version, add error handling and idempotency, dry-run then schedule. Use when the task is "automate this", "write a script for", or scheduling an unattended job.
Also in 4 projects that use this
- +1 more from 0mlkrizzz655335v
In this repository48 other files it gives its agents.
- .claude/templates/AGENTS.mdAGENTS.md
- docs/agents.mdAGENTS.md
- .claude/CLAUDE.mdCLAUDE.md
- .cursor/rules/core.mdcCursor rule
- .cursor/rules/go.mdcCursor rule
- .cursor/rules/k8s.mdcCursor rule
- .cursor/rules/node.mdcCursor rule
- .cursor/rules/python.mdcCursor rule
- .cursor/rules/rust.mdcCursor rule
- .cursor/rules/tdd.mdcCursor rule
- .cursor/rules/workbench.mdcCursor rule
- llms-full.txtllms.txt
- llms.txtllms.txt
- cmux-sprint-orchestratorSkill
- config-auditSkill
- doneSkill
- eurekaSkill
- goalSkill
- go-reviewSkill
- handoffSkill
- js-reviewSkill
- k8s-debugSkill
- k8s-reviewSkill
- kickoffSkill
- pr-review-ingestSkill
- pr-reviewSkill
- python-reviewSkill
- reflectionSkill
- skill-evalSkill
- tdd-protocolSkill
- team-executeSkill
- team-planSkill
- team-shutdownSkill
- test-reviewSkill
- validate-recommendationSkill
- worktree-guideSkill
- babysitSkill
- canvasSkill
- create-ruleSkill
- create-skillSkill
- create-subagentSkill
- migrate-to-skillsSkill
- sdkSkill
- shellSkill
- split-to-prsSkill
- statuslineSkill
- update-cli-configSkill
- update-cursor-settingsSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

