Skip to content

Hook Development Guide

Lets the agent write and validate Claude Code hooks that automate or check actions at key events.

Stars
45,770
Licence
Apache-2.0
Files
11 files

What it does

Hooks are small automated checks that run at specific moments in a Claude Code session, such as before a tool runs, after an edit, or when the agent tries to stop. This skill teaches the agent how to design, configure and debug these hooks, including LLM-judged prompt hooks and bash command hooks. Once installed, the agent can write hook configuration, example validation scripts, and linting or schema checks for them.

Great for

  • Plugin developers building safety checks, such as blocking dangerous shell commands or risky file writes
  • Teams that want automatic context loading or completion checks at session start or stop
  • Developers learning how Claude Code hook events and exit codes work

Skip it if

  • Non-developers looking for an end-user productivity tool; it assumes familiarity with JSON configuration and shell scripting
  • Security-critical enforcement relied on alone: the example pattern checks are simple string matches and can be bypassed, so they should not be the only control

Try asking

  • “Create a PreToolUse hook that blocks rm -rf and asks before writing to .env files”
  • “Add a Stop hook that checks tests ran and the build succeeded before the agent finishes”
  • “Write a SessionStart hook that detects the project type and saves it as an environment variable”
  • “Lint my hook scripts for missing set -euo pipefail, quoting, and exit code problems”
Step-by-step guide: how to use Hook Development GuideInstall, first run, examples, tips and FAQs

Install in 3 steps

  1. 1

    Download the skill

    The ZIP contains the 11 original files, the Apache-2.0 licence and an attribution note.

    hook-development.zip
  2. 2

    Add it to your agent

    Claude Code (all projects)

    mkdir -p ~/.claude/skills && unzip hook-development.zip -d ~/.claude/skills/

    Claude Code / Agent SDK (this project only)

    mkdir -p .claude/skills && unzip hook-development.zip -d .claude/skills/

    Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.

  3. 3

    Ask for the task

    No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.

Get better results

  • Use prompt-based hooks for context-sensitive judgment and command hooks for fast deterministic checks
  • Review any hook script before installing a plugin, since hooks run automatically with your permissions
  • Test hook scripts with the included test and linter scripts before relying on them

What's inside

  • examples/load-context.sh
  • examples/validate-bash.sh
  • examples/validate-write.sh
  • references/advanced.md
  • references/migration.md
  • references/patterns.md
  • scripts/hook-linter.sh
  • scripts/README.md
  • scripts/test-hook.sh
  • scripts/validate-hook-schema.sh
  • SKILL.md

Redistributed unmodified from anthropics/claude-plugins-official under the Apache-2.0 licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.