agentleFS
pahlevikunpahlevikun/levistack/skills/agent-authoring/create-hook/SKILL.md

create-hook

Skill0 starsChanged 18 days agoMITView on GitHub

Create, wire up and test agent hooks: Claude Code settings.json or plugin hooks, Cursor hooks.json, or a shared hooks/ tree. Use when asked to run something automatically on an agent event, block or rewrite a tool call, format after edits, inject session context, or debug a hook that never fires.

  • Deletes or force-pushes
  • Commits and pushes

17 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use review-bugbot, update-cli-config and 9 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.
  • 0mlkrizzz655335vSkill

    review-bugbot

    缺陷导向代码审查。用 Bugbot 子代理找 bug。

    Also in 5 projects that use this

  • PandelisZSkill

    update-cli-config

    View and modify Cursor CLI configuration settings in ~/.cursor/cli-config.json. Use when the user wants to change CLI settings, configure permissions, switch approval mode, enable vim mode, toggle display options, configure sandbox, or manage any CLI preferences.

    Also in 7 projects that use this

  • 32103210Skill

    migrate-to-skills

    Convert 'Applied intelligently' Cursor rules (.cursor/rules/*.mdc) and slash commands (.cursor/commands/*.md) to Agent Skills format (.cursor/skills/). Use when you want to migrate rules or commands to skills, convert .mdc rules to SKILL.md format, or consolidate commands into the skills directory.

    Also in 7 projects that use this

  • 32103210Skill

    update-cursor-settings

    Modify Cursor/VSCode user settings in settings.json. Use when you want to change editor settings, preferences, configuration, themes, font size, tab size, format on save, auto save, keybindings, or any settings.json values.

    Also in 7 projects that use this

  • 0mlkrizzz655335vSkill

    origin

    origin CLI 管理。安装、登录、更新、修复 origin.cursor.com 的 CLI。"disabled-environments:

    Also in 3 projects that use this

  • Tsumugii24Skill

    split-to-prs

    Split current work into small reviewable PRs. Use when the user asks to split a chat, set of changes, branch, or PR.

    Also in 7 projects that use this

  • +1 more from 32103210
  • +2 more from 0mlkrizzz655335v

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 17 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Portable: Prefer Node over shell, and verify every binary the script calls exists on the hook's PATH.

    line 34
  2. Distinctive:

    If a repo already has hooks, extend its setup and keep unrelated entries.

    line 53
  3. Distinctive:

    Try it by hand: before the harness does:

    line 57
  4. Very specific:

    Add a Stop hook that blocks without checking stop_hook_active.

    line 80
  5. Distinctive:

    Put secrets or personal paths in a shared hook, or call the network in a hot-path hook.

    line 81

“Common” is measured: kept by at least 6 in 10 of the 17 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Create a hook

A hook is a script or check the harness runs on an agent event. The harness runs it, not the model, so it happens every time. Use a hook to observe, block, rewrite or add context. If the guidance only needs to be remembered, write a rule instead.

Principles

  1. Hooks are for what must happen every time. "Always format after an edit", "never run rm -rf /". Preferences belong in rules.
  2. Narrowest event, narrowest matcher. PreToolUse on Bash is better than a hook on every event. Filter in the script when a matcher gets tricky.
  3. Fail open unless it is a deliberate blocker. A crash, a timeout or unexpected input should let the action proceed. Reserve blocking (deny, exit 2, failClosed) for a rule you would defend.
  4. Fast and quiet. A hook on the hot path runs on every call. Set a short timeout, do no network work, and keep stdout to the JSON the harness expects.
  5. Deterministic over clever. A script beats a prompt hook when the result must be auditable. Use a prompt hook only for policy that is easier to describe than to code.
  6. Portable. Prefer Node over shell, and verify every binary the script calls exists on the hook's PATH.
  7. Opt-in for personal tooling. A hook shared through a plugin or repo affects everyone who installs it. Keep it conservative, or gate it behind a flag file.

Steps

  1. Gather requirements. Infer from the conversation; ask only for what is missing:
    • Trigger: which event, and which tool, command or file it should react to.
    • Behavior: audit, block, ask, rewrite input, inject context, or continue a workflow.
    • Scope: this user, this project, or a shared plugin or catalog.
    • Failure: fail open or closed.
  2. Pick the target.

    TargetConfigReference
    Claude Code, project or user.claude/settings.json, ~/.claude/settings.jsonclaude-code.md
    Claude Code pluginhooks/hooks.jsonclaude-code.md
    Cursor.cursor/hooks.json, ~/.cursor/hooks.jsoncursor.md
    A shared hooks tree (hooks/<name>.mjs with a launcher)the tree's own conventionits hooks/README.md

    If a repo already has hooks, extend its setup and keep unrelated entries.

  3. Choose the event from the table in the reference for your target. Check what that event can return; not every event can block.
  4. Write the script (Node by default). Read the JSON from stdin, decide, print only the output JSON, and exit 0. Block with the event's documented decision or with exit 2, never with prose on stdout. Ambiguous input returns allow.
  5. Wire it up with the smallest matcher that works. Start with no matcher or a simple one and tighten after it fires. Quote path placeholders ("$CLAUDE_PROJECT_DIR"), because paths contain spaces.
  6. Try it by hand before the harness does:

    node scripts/try-hook.mjs --event PreToolUse --tool Bash --command "git push --force" --expect ask -- node .claude/hooks/guard.mjs

    It builds a Claude Code payload, runs the command, and reports the exit code, the decision and any invalid JSON. --json '<payload>' sends a raw payload for other events or for Cursor. Run it for one input that should trigger and one that should pass. A hook behind an opt-in flag file reports allow until the flag exists.

  7. Trigger it for real in a session and read the harness's hook log (claude --debug-file <path>, or Cursor's Hooks tab). Confirm the matcher matched.
  8. Check the repo's gates. In a catalog with its own hook tests or sync step, add a test and run them.

Output at a glance

GoalClaude CodeCursor
Allowexit 0, no output{"permission":"allow"}
Ask the userPreToolUse permissionDecision: "ask"{"permission":"ask"}
BlockpermissionDecision: "deny" or exit 2 with a stderr reason{"permission":"deny"} or exit 2
Add contexthookSpecificOutput.additionalContextadditional_context (post events)

Do not

  • Print anything but JSON on stdout (a shell profile banner also breaks it).
  • Block on an ambiguous or unparseable input.
  • Add a Stop hook that blocks without checking stop_hook_active; it can loop.
  • Put secrets or personal paths in a shared hook, or call the network in a hot-path hook.
  • Overwrite a user's existing settings.json hooks; merge.

Related skills

  • create-rule: a request is enough and nothing must be enforced.
  • create-command: the action should run on /name, not on an event.
  • create-skill: the automation needs a procedure the model follows.
  • create-agent: the event should start a delegated job.

Done when

  • The event, matcher and handler are the narrowest that work.
  • try-hook.mjs shows the expected decision for one triggering input and one passing input.
  • It fired in a real session, and the log shows the expected result.
  • It fails open on bad input, unless blocking is its stated purpose.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.