agentleFS
joris887joris887/exosuit/.claude/skills/custom-hooks/SKILL.md

custom-hooks

Skill9 starsChanged 3 months agoMITView on GitHub

Create project-specific hook scripts and register them in settings.json. Extends the framework's enforcement layer.

  • Installs packages

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 7 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Blocking vs Advisory: Should it block (exit 2) or just warn (exit 0)?

    line 41
  2. Distinctive:

    Create a POSIX shell script following the framework's hook conventions:

    line 50
  3. Very specific:

    Read .claude/settings.json and add the new hook entry under the appropriate event:

    line 93
  4. Very specific:

    Important: Use the cd "$(git rev-parse --show-toplevel ...)" pattern for path resolution, NOT __PROJECT_ROOT__.

    line 108
  5. Distinctive:

    For all hooks: Verify normal operations aren't affected (no false positives)

    line 116
  6. Very specific:

    Add the hook to .claude/hooks/README.md:

    line 120
  7. Distinctive:

    ALWAYS use POSIX sh, never bash (matches framework convention)

    line 137
  8. Distinctive:

    ALWAYS handle missing jq gracefully (sed fallback)

    line 138
  9. Distinctive:

    ALWAYS test the hook before marking complete

    line 139
  10. Distinctive:

    NEVER let a custom hook's own failure block the user — wrap logic in conditions

    line 140
  11. Very specific:

    If the hook uses external rule files, create them in .claude/hooks/rules/ with the @@-delimited format

    line 141

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “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

custom-hooks

Creating a custom hook: $ARGUMENTS

Supported Hook Events

Present available Claude Code hook events:

EventWhen It FiresCan Block?Input Fields
SessionStartOnce at session startNosession data
PreToolUseBefore any tool callYes (exit 2)tool_name, tool_input
PostToolUseAfter any tool callNotool_name, tool_input, tool_output
StopWhen model wants to stopYes (exit 2)last_assistant_message
UserPromptSubmitWhen user submits promptNouser_prompt
SubagentStopWhen a subagent completesNolast_assistant_message
WorktreeCreateWhen a worktree is createdNo—
WorktreeRemoveWhen a worktree is removedNo—

Matchers (for PreToolUse and PostToolUse): Filter by tool name — Bash, Edit, Write, Read, Glob, Grep, or combinations with | (e.g., Edit|Write).

1. Understand Requirements

Parse $ARGUMENTS to determine:

  • Event type: Which hook event to listen to
  • Purpose: What the hook should do
  • Blocking vs Advisory: Should it block (exit 2) or just warn (exit 0)?

If unclear, ask:

  • "Should this hook block the action or just warn?"
  • "Should it fire on specific tools only, or all tools?"
  • "Should it run on subagents too?"

2. Generate Hook Script

Create a POSIX shell script following the framework's hook conventions:

#!/bin/sh
# [Event] handler: [description].
# [Blocking|Advisory] — [behavior summary].
# POSIX-compliant — no bash required.
#
# Input:  JSON on stdin ([relevant fields])
# Output: exit 0 = allow, exit 2 = block (message on stderr)

HOOKS_DIR="$(cd "$(dirname "$0")" && pwd)"

# --- JSON field extraction ---
extract_json_string() {
    _field="$1"
    if command -v jq >/dev/null 2>&1; then
        jq -r ".$_field // empty"
    else
        sed -n 's/.*"'"$_field"'"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -1
    fi
}

# Read stdin once
INPUT=$(cat)

# --- Hook logic ---
# [Custom logic here]

exit 0

Convention Checklist

  • POSIX sh (not bash) — for portability
  • Reads JSON from stdin via jq with sed fallback
  • Blocking hooks output message on stderr before exit 2
  • Advisory hooks output warnings on stderr, always exit 0
  • Graceful degradation — own errors never block the user
  • One-off warnings use state files in $HOOKS_DIR/state/ to avoid noise

3. Register in settings.json

Read .claude/settings.json and add the new hook entry under the appropriate event:

{
    "matcher": "[tool-matcher or omit for all]",
    "hooks": [
        {
            "type": "command",
            "command": "cd \"$(git rev-parse --show-toplevel 2>/dev/null || echo .)\" && sh .claude/hooks/<script-name>.sh",
            "statusMessage": "[User-visible status message]..."
        }
    ]
}

Important: Use the cd "$(git rev-parse --show-toplevel ...)" pattern for path resolution, NOT __PROJECT_ROOT__.

4. Test the Hook

Guide the user to test:

  1. For blocking hooks: Trigger the condition and verify the block message appears
  2. For advisory hooks: Trigger the condition and verify the warning appears
  3. For all hooks: Verify normal operations aren't affected (no false positives)

5. Document

Add the hook to .claude/hooks/README.md:

  • Script name and purpose
  • Event type and matcher
  • Blocking or advisory
  • Any rule files it uses

Examples

/custom-hooks PreToolUse "Block npm install without --save-exact flag"
/custom-hooks PostToolUse "Log all database migration commands to a separate file"
/custom-hooks Stop "Require changelog entry when files in src/api/ were modified"
/custom-hooks UserPromptSubmit "Warn when user asks to skip tests"

Rules

  • ALWAYS use POSIX sh, never bash (matches framework convention)
  • ALWAYS handle missing jq gracefully (sed fallback)
  • ALWAYS test the hook before marking complete
  • NEVER let a custom hook's own failure block the user — wrap logic in conditions
  • If the hook uses external rule files, create them in .claude/hooks/rules/ with the @@-delimited format
  • Save the script to .claude/hooks/ alongside the framework hooks

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.