create-hook

A guide for creating Cursor hooks, which are scripts or checks that run around coding-agent events and can observe, block, change, or follow up on actions.

In plain words
What is it for?
Use it to create project or user hooks, configure event filters, and choose between command-based and prompt-based behavior.
Why use it?
It helps define when automation should run, what it should inspect or change, and whether failures should stop the workflow.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/xyruscode/ai-sync/create-hook
Any agent
npx skills add XyrusCode/ai-sync --skill create-hook
Clone the repo
git clone --depth 1 https://github.com/XyrusCode/ai-sync

Made for: Claude Code, Codex.

Per session 31 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,178 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin 100% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00031 $0.02178
Opus 5 $0.00015 $0.01089
Sonnet 5 $0.00006 $0.00436
Haiku 4.5 $0.00003 $0.00218

Measured yesterday against content hash 28bfa0c6cd13, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

create-hook scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

"matcher": "curl|wget|nc ",
Origin

This is a copy

100% identical to create-hook — 0 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

skills/create-hook/SKILL.md · 240 lines

How it starts

The opening of the file, as written. The whole thing — 240 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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:

  1. Scope: Should this be a project hook or a user hook?
  2. Trigger: Which event should run the hook?
  3. Behavior: Should it audit, deny/allow, rewrite input, inject context, or continue a workflow?
  4. Implementation: Should it be a command hook (script) or a prompt hook?
  5. Filtering: Does it need a matcher so it only runs for certain tools, commands, or subagent types?
  6. 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.json and .cursor/hooks/*
  • User hooks: ~/.cursor/hooks.json and ~/.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.sh or hooks/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 session
  • preToolUse, postToolUse, postToolUseFailure: work across all tools
  • subagentStart, subagentStop: control or continue Task/subagent workflows
  • beforeShellExecution, afterShellExecution: gate or audit terminal commands
  • beforeMCPExecution, afterMCPExecution: gate or audit MCP tool calls
  • beforeReadFile, afterFileEdit: control file reads or post-process edits
  • beforeSubmitPrompt: validate prompts before they are sent
  • preCompact: observe context compaction
  • stop: handle agent completion
  • afterAgentResponse, afterAgentThought: track agent output or reasoning

Read the full file on GitHub · 240 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 240 lines · 31 tokens per session scan A 28bfa0c6cd13

Subscribe to this mod's changes

create-hook is a skill published in the GitHub repository XyrusCode/ai-sync (2 stars, last pushed 2d ago), licensed MIT. It adds 31 tokens to every session and 2,178 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). It is 100% identical to create-hook, differing in 0 lines, and is treated as a copy.

Related

Other skills, from other repositories

weekly-digests

Generate a serial week-by-week narrative digest of a project's full claude-mem timeline. Splits the timeline into per-ISO-week files, then runs one consecutive subagent per week — each receiving the prior week's carry-forward block — to produce one chapter per ISO week of data. Use when asked for "weekly digests"…

thedotmack/claude-mem · 93 tokens

agentmail

Use when an agent needs AgentMail CLI email inboxes.

NousResearch/hermes-agent · 15 tokens

skill-template

Template for creating new Agent Skills for context engineering. Use this template when adding new skills to the collection.

muratcankoylan/Agent-Skills-for-Context-Engineering · 24 tokens

Agent Development

This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development…

anthropics/claude-code · 80 tokens

skill-creator

Scaffold a new yoyo skill when a human or community issue asks for one ("add a skill for X", "create a skill that does Y"). Generates correct frontmatter, validates, writes to disk.

yologdev/yoyo-evolve · 46 tokens

subagent-delegation

Canonical protocol for delegating GSD work to native Antigravity subagents — when to delegate, how to invoke, workspace isolation modes, and the inline fallback for older IDE versions.

toonight/get-shit-done-for-antigravity · 42 tokens