agentleFS
cfircoocfircoo/claude-code-toolkit/skills/create-hooks/SKILL.md

manage-hooks

Skill17 starsChanged 9 months agoMITView on GitHub

This skill should be used when the user asks to "create a hook", "add a PreToolUse hook", "debug a hook", "fix a hook", "hook not working", or mentions hook configuration, hook events, hook types, automating workflows, or understanding hooks. Provides expert guidance for creating, configuring, debugging, and managing Claude Code hooks.

  • Deletes or force-pushes

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    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:

    Stop hook loops: Always check stop_hook_active field in Stop/SubagentStop hooks — exit 0 if true

    line 35
  2. Distinctive:

    Create a new hook

    line 46
  3. Distinctive:

    Create a toolkit hook (distributable)

    line 48
  4. Very specific:

    No infinite loops in Stop/SubagentStop hooks (checks stop_hook_active flag)

    line 125
  5. Distinctive:

    No shell profile interference with JSON output </success_criteria>

    line 128

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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

<essential_principles> Hooks are event-driven automation for Claude Code that execute shell commands, LLM prompts, or multi-turn agents in response to tool usage, session events, and user interactions. They provide deterministic control over Claude's behavior without modifying core code.

1. Three Hook Types:

  • command — shell command, deterministic, fast. Exit 0 = proceed, exit 2 = block. JSON stdout for structured control.
  • prompt — single-turn LLM evaluation (Haiku default). Returns {"ok": true} or {"ok": false, "reason": "..."}.
  • agent — multi-turn subagent with tool access (up to 50 turns). Same ok/reason output. Use when verification needs codebase access.

2. Event → Matcher → Hook — Events (PreToolUse, Stop, etc.) trigger matchers (regex on tool name/context) which fire hooks. See <quick_reference> for the full event table.

3. Configuration Locations (highest priority first):

  • User-global: ~/.claude/settings.json
  • Project shared: .claude/settings.json
  • Project local: .claude/settings.local.json
  • Or use /hooks interactive menu in Claude Code

4. Environment Variables:

VariableValue
$CLAUDE_PROJECT_DIRProject root directory
${CLAUDE_PLUGIN_ROOT}Plugin directory (plugin hooks only)
$ARGUMENTSHook input JSON (prompt/agent hooks only)
$CLAUDE_ENV_FILEPath for persisting environment variables

5. Safety Essentials:

  • Stop hook loops: Always check stop_hook_active field in Stop/SubagentStop hooks — exit 0 if true
  • Timeouts: Set reasonable values in seconds (default: 10 min commands, 60s agents, 30s prompts)
  • Permissions: chmod +x on script files
  • Path safety: Quote "$CLAUDE_PROJECT_DIR" for spaces
  • Shell profiles: Wrap echo in ~/.zshrc/~/.bashrc with [[ $- == *i* ]] checks — non-interactive shells can corrupt JSON output
  • PermissionRequest: Doesn't fire in headless mode (-p); use PreToolUse instead </essential_principles>
<intake> What would you like to do?
  1. Create a new hook
  2. Debug / fix a hook
  3. Create a toolkit hook (distributable)
  4. Get guidance on hook design

If $ARGUMENTS provides clear intent, skip the menu and route directly. </intake>

<routing> | Response | Intent Phrases | Workflow | |----------|---------------|----------| | 1, "create", "add", "build", "set up" | "create a hook", "add a PreToolUse hook", "block rm -rf" | workflows/create-hook.md | | 2, "debug", "fix", "not working", "broken" | "hook not firing", "debug my hook", "fix hook" | workflows/debug-hook.md | | 3, "toolkit", "package", "distribute", "install" | "create toolkit hook", "package hook" | workflows/create-toolkit-hook.md | | 4, "guidance", "help", "recommend", "which" | "which event?", "how do hooks work?", "recommend" | workflows/get-guidance.md |

Intent-based routing (when $ARGUMENTS provides clear intent):

  • "block dangerous commands" → workflows/create-hook.md
  • "my hook isn't triggering" → workflows/debug-hook.md
  • "package for toolkit" → workflows/create-toolkit-hook.md
  • "what event should I use" → workflows/get-guidance.md

After reading the workflow, follow it exactly. </routing>

<quick_reference>

EventWhen it firesCan block?Matcher filters
PreToolUseBefore tool executionYestool name
PostToolUseAfter tool succeedsYes (decision: "block")tool name
PostToolUseFailureAfter tool failsNotool name
PermissionRequestPermission dialog appearsYestool name
UserPromptSubmitUser submits a promptYesno matcher support
StopClaude finishes respondingYesno matcher support
SubagentStartSubagent is spawnedNoagent type
SubagentStopSubagent finishesYesagent type
SessionStartSession begins/resumesNosource (startup, resume, clear, compact)
SessionEndSession terminatesNoreason (clear, logout, etc.)
PreCompactBefore context compactionNotrigger (manual, auto)
NotificationClaude needs attentionNotype (permission_prompt, idle_prompt, etc.)
TeammateIdleAgent about to go idleYes (exit 2)no matcher support
TaskCompletedTask marked completeYes (exit 2)no matcher support
ConfigChangeConfig file changesYes (decision: "block")config type

See references/hook-types.md for detailed schemas and use cases for each event. </quick_reference>

<reference_index> All in references/:

Types & Events: hook-types.md — complete event schemas and use cases Hook Types: command-vs-prompt.md — decision tree for command vs prompt vs agent Matchers: matchers.md — regex patterns, event-specific matching, MCP tools I/O Schemas: input-output-schemas.md — stdin JSON, exit codes, hookSpecificOutput Examples: examples.md — notifications, file protection, auto-format, logging, Stop hooks Troubleshooting: troubleshooting.md — hooks not triggering, JSON corruption, loops Toolkit: toolkit-structure.md — distributable hook packaging for claude-code-toolkit </reference_index>

<workflows_index> All in workflows/:

WorkflowPurpose
create-hook.mdBuild a hook from scratch
debug-hook.mdDiagnose and fix broken hooks
create-toolkit-hook.mdPackage hook for toolkit distribution
get-guidance.mdHelp decide event, type, and matcher
</workflows_index>

<success_criteria> A working hook configuration has:

  • Valid JSON in the appropriate settings file (validated with jq)
  • Appropriate hook event selected for the use case
  • Correct matcher pattern matching target tools/contexts
  • Command, prompt, or agent that executes without errors
  • Proper output (exit codes for commands, ok/reason for prompts/agents)
  • Tested with --debug flag or Ctrl+O verbose mode showing expected behavior
  • No infinite loops in Stop/SubagentStop hooks (checks stop_hook_active flag)
  • Reasonable timeout set in seconds
  • Executable permissions on script files
  • No shell profile interference with JSON output </success_criteria>

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.