writing-hooks

Solid

How to write Claude Code hooks -- event selection, hook types, matcher patterns, blocking vs advisory, portable paths. Use when creating hooks for quality gates, automation, or policy enforcement.

AI & Automation 52 stars 15 forks Updated today ISC

Install

View on GitHub

Quality Score: 79/100

Stars 20%
57
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Writing Hooks > Scope: covers hooks.json authoring and hook script design. For plugin architecture, see [[writing-plugins]]. For rules (which are simpler but static), see [[writing-rules]]. ## 1. Three Hook Types | Type | What it does | When to use | Complexity | |------|-------------|-------------|------------| | `command` | Runs a shell script, reads JSON from stdin | Deterministic checks: file existence, JSON validation, regex matching | Medium | | `prompt` | Injects text into Claude's context | Advisory: reminders, context injection, style guidance | Low | | `agent` | Spawns a verification agent | Complex verification: code quality, semantic analysis, multi-file checks | High | ### Type Selection Flowchart ``` Is the check deterministic (regex, file exists, JSON schema)? YES --> command hook (shell script) NO --> Does it need AI judgment? YES --> agent hook NO --> prompt hook (context injection) ``` ### Command Hook Example ```json { "hooks": { "PreToolUse": [ { "matcher": "Write|Edit", "hooks": [ { "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/scripts/check-loc.sh", "timeout": 10000 } ] } ] } } ``` Hook script receives JSON on stdin with tool name and parameters. It outputs JSON to stdout. ### Prompt Hook Example ```json { "hooks": { "UserPromptSubmit": [ { "hooks": [ { "type": "prompt", ...

Details

Author
xiaolai
Repository
xiaolai/nlpm-for-claude
Created
2 months ago
Last Updated
today
Language
HTML
License
ISC

Similar Skills

Semantically similar based on skill content — not just same category