Awesome-omni-skill create-hook
Creates or adds Cursor agent lifecycle hooks. Use when the user asks to create a hook, add a hook, set up a lifecycle hook, or automate something on agent stop, afterFileEdit, afterAgentResponse, or other Cursor hook events. Hooks live in .cursor/hooks/ and are registered in .cursor/hooks.json.
install
source · Clone the upstream repo
git clone https://github.com/diegosouzapw/awesome-omni-skill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/ai-agents/create-hook" ~/.claude/skills/diegosouzapw-awesome-omni-skill-create-hook && rm -rf "$T"
manifest:
skills/ai-agents/create-hook/SKILL.mdsource content
Create Hook
Type: Utility skill (procedural, no agentic lead or sub-agents).
Adds a Cursor lifecycle hook: a script that runs when a specific agent event fires. Hooks are project-level only (
.cursor/hooks/ and .cursor/hooks.json).
1. Choose the lifecycle event
Register the hook under one of these keys in
hooks.json:
| Event | When it runs |
|---|---|
| When the agent stops (end of turn) |
| After the agent edits a file |
| After the agent sends a response |
| Before the user's prompt is submitted |
/ / etc. | See Cursor docs for full list |
2. Add the script
- Path:
(or.cursor/hooks/<name>.js
if shell). Use a clear name (e.g..sh
,memory-reminder.js
).on-stop.js - Runtime: Node.js is typical; command in
is run with Cursor's working directory set so thathooks.json
resolves (run fromnode hooks/<name>.js
)..cursor - Input: The hook receives a single JSON object on stdin. Read it like this:
let input = ""; process.stdin.setEncoding("utf8"); process.stdin.on("data", (chunk) => { input += chunk; }); process.stdin.on("end", () => { const payload = JSON.parse(input); const roots = payload.workspace_roots || [process.cwd()]; const root = path.resolve(roots[0]); // repo root // ... use root for paths like path.join(root, '.cursor', 'next-step.md') });
- Payload: Often includes
(array of repo roots). Use the first root as the project root for paths. Event-specific payloads may includeworkspace_roots
,file_path
, etc.prompt - Output: Hook can write files (e.g.
), log to stderr, or exit; avoid writing to stdout if the protocol expects JSON there..cursor/next-step.md - Shebang: Start Node scripts with
.#!/usr/bin/env node
3. Register in hooks.json
- Path:
.cursor/hooks.json - Format:
{ "version": 1, "hooks": { "stop": [ { "command": "node hooks/on-stop.js" }, { "command": "node hooks/my-new-hook.js" } ] } }
- Append to the array for the chosen event; do not remove existing hooks unless the user asks to replace them.
Checklist
- Script created under
(or.cursor/hooks/<name>.js
).sh - Script reads JSON from stdin and uses
for repo root when neededworkspace_roots - Entry added to
under the correct event key.cursor/hooks.json - Command is
(ornode hooks/<name>.js
); path is relative to./hooks/<name>.sh.cursor
Reference
- Existing hooks in this repo:
,.cursor/hooks/on-stop.js
,.cursor/hooks/after-file-edit.js
— use them as patterns for stdin handling and.cursor/hooks/memory-reminder.js
.path.join(root, ...) - Project memory (
) notes that new hooks should be added under.cursor/memory.md
and registered in.cursor/hooks/
..cursor/hooks.json