hook-development
Skill37k starsChanged 9 months agoApache-2.0View on GitHub
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.
- Reads credentials
8 other projects use a version of this.
Trending
More talk lately.about the whole repository
Most recently taken up by
- gcapodeferro02/my-agent-skillsword for word, first seen Sep 21, 2026
- jorgeasaurus/agent-skillsword for word, first seen May 11, 2026
- Airmomo/skillsword for word, first seen Apr 21, 2026
- Galaxy-Dawn/claude-scholarword for word, first seen Apr 15, 2026
- ghoshsam/claude-code-skillsword for word, first seen Mar 20, 2026
- kvivek0591/claude-code-skillsword for word, first seen Mar 20, 2026
Who's talking about anthropics/claude-plugins-official
- @martinp7r.com“Look, there's an official #Claude LSP plugin for #swiftlang @swift.org now! github.com/anthropics/c... …”Bluesky · Dec 19, 2025 · 6 likes
- amoai-tech/mdeai“refactor(skills): make nextjs the single Next.js and Vercel owner”GitHub · Sep 20, 2026 · 3 reactions
- amoai-tech/mdeai“refactor(skills): consolidate engineering workflow ownership”GitHub · Sep 20, 2026 · 3 reactions
- amoai-tech/mdeai“SAN-1274 PR 2 — Add the MDE workflow skills for planning, debugging, testing, review, and verification”GitHub · Sep 16, 2026 · 3 reactions
- amoai-tech/mdeai“SAN-1274 PR 1 — Add the verified MDE AI skills foundation”GitHub · Sep 16, 2026 · 3 reactions
The biggest 5 of 51 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 51
Talked about on GitHub, Bluesky and Hacker News (51 times).
On GitHub · 29
- Sep 20, 2026refactor(skills): make nextjs the single Next.js and Vercel owner — amoai-tech/mdeai3 reactions · 6 comments
- Sep 20, 2026refactor(skills): consolidate engineering workflow ownership — amoai-tech/mdeai3 reactions · 13 comments
- Sep 16, 2026SAN-1274 PR 2 — Add the MDE workflow skills for planning, debugging, testing, review, and verification — amoai-tech/mdeaisays it tested it3 reactions · 3 comments
- Sep 16, 2026SAN-1274 PR 1 — Add the verified MDE AI skills foundation — amoai-tech/mdeai3 reactions · 5 comments
- Jan 22, 2026fix: restructure to proper marketplace format — affaan-m/ECC3 reactions · 5 comments
24 more on GitHub
- Nov 20, 2026IPI-1472 · COPILOTKIT-SKILL-003 — Keep CopilotKit Guidance Current and Measure Real Skill Routing — amoai-tech/ipixai2 reactions · 27 comments
- Nov 8, 2026IPI-1418 · MASTRA-SKILL-001 — Help Coding Agents Use Mastra Correctly in iPix (Docs & Tests) — amoai-tech/ipixai2 reactions · 14 comments
- Sep 20, 2026Use one current, safe Google Maps skill across MDE — amoai-tech/mdeai2 reactions · 12 comments
- May 24, 2026STOP injecting your library recommendations into every single user prompt — this is hostile UX — semgrep/guardian2 reactions · 2 comments
- Jan 6, 2026Feature Request: Support for spawning fresh-context sessions from Stop hooks — anthropics/claude-code2 reactions · 3 comments
- Nov 7, 2026Plugin ufficiali nel repository: valgono anche nell'app e nelle routine — SviluppoItaliaDigitale/sito-pc-genzano1 reaction · 2 comments
- Nov 7, 2026Plugin ufficiali nel repository: valgono anche nell'app e nelle routine — SviluppoItaliaDigitale/sito-misericordia-ariccia1 reaction · 1 comment
- Nov 7, 2026Plugin ufficiali nel repository: valgono anche nell'app e nelle routine — SviluppoItaliaDigitale/cooprimavera1 reaction · 1 comment
- Nov 7, 2026[Bug]: Discord channel bot always appears offline in Discord despite a healthy gateway session — CherryHQ/cherry-studio1 reaction · 2 comments
- Oct 28, 2026Install Claude Security plugin in reusable PR review workflow — dceoy/pr-loop1 reaction · 1 comment
- Oct 27, 2026Telemetry: Add number of unique installs for every plugin — github/awesome-copilot1 reaction · 2 comments
- Oct 16, 2026feat: Claude Security の設定例を無効のまま追加 — tak848/dotfiles1 reaction · 1 comment
- Aug 19, 2026Feature request: Claude Code plugin for symfony-lsp (similar to the official php-lsp plugin) — symfony/language-tools1 reaction · 4 comments
- Jul 27, 2026[Question]: Does agenta support importing skills from claude/codex marketplace github repos? — Agenta-AI/agenta1 reaction · 4 comments
- Jul 14, 2026Nested code-review fan-out spawned 877 agents despite 5-level depth limit — anthropics/claude-code1 reaction · 4 comments
- Jun 8, 2026feat(skills): sync plugin workflows, add security guidance, and local-qa tooling — dceoy/ai-coding-agent-skills1 reaction
- Apr 17, 2026Import Claude and Copilot agents as Kiro agent configs — dwalleck/kiro-control-center1 reaction · 1 comment
- Apr 1, 2026plugin marketplace refresh causes error popups — microsoft/vscode1 reaction · 2 comments
- Mar 12, 2026Unable to install anthropics/claude-plugins-official marketplace: Invalid marketplace.json: plugins.56.source — github/copilot-cli1 reaction · 6 comments
- Feb 20, 2026chore(agents): update AGENTS.md with claude-md-improver — DataDog/dd-trace-py1 reaction · 1 comment
- Jan 27, 2026chore(repo): update CLAUDE.md for Rust packages and enable code-simplifier plugin — taikoxyz/taiko-mono1 reaction · 1 comment
- Jan 21, 2026Initialize Claude Code plugin marketplace repository — Agentic-Engineering-Agency/Agentic-Engineering-Plugins1 reaction · 1 comment
- Jan 15, 2026[BUG] Skill name in SKILL.md can only contain lowercase letters, numbers, and hyphens. (when uploading at claude.ai) — anthropics/skills1 reaction
- Jan 9, 2026Update installation instructions to use official Claude marketplace — getsentry/sentry-for-ai1 reaction
On Bluesky · 21
- Dec 19, 2025Look, there's an official #Claude LSP plugin for #swiftlang @swift.org now! github.com/anthropics/c... github.com/anthropics/c... — @martinp7r.com6 likes and reposts
- May 23, 2026💎 Hidden Gem! 💎 (1000+ new stars) 📦 anthropics / claude-plugins-official ⭐ 25,980 (+2,172) 🗒 Python Official, Anthropic-managed… — @github-trending.bsky.social3 likes and reposts · 1 reply
- Feb 1, 2026🔥 Hot Repo! 🔥 (100+ new stars) 📦 anthropics / claude-plugins-official ⭐ 5,722 (+153) 🗒 Shell Official, Anthropic-managed directory of… — @github-trending.bsky.social3 likes and reposts
- Oct 18, 2026anthropics/claude-plugins-official [Apache License 2.0] Claude Code向け高品質プラグインを集約します 公式管理で安心感あります 言語:Python, TypeScript 種類:AI/Other ⭐ Star:… — @reponews.bsky.social2 likes and reposts
- May 22, 2026📈 Today's GitHub Trending: 1. https://github.com/anthropics/claude-plugins-official - Python, 2556 stars today 2.… — @ghtrend.newsmast.social.ap.brid.gy2 likes and reposts
16 more on Bluesky
- Mar 12, 2026🔥 Hot Repo! 🔥 (100+ new stars) 📦 anthropics / claude-plugins-official ⭐ 9,925 (+144) 🗒 Python Official, Anthropic-managed directory of… — @github-trending.bsky.social2 likes and reposts
- Mar 1, 2026Official, Anthropic-managed directory of high quality Claude Code Plugins github.com/anthropics/c... code.claude.com/docs/en/plug...… — @janmr.com2 likes and reposts
- Oct 18, 2026📈 Today's GitHub Trending: 1. https://github.com/MadsLorentzen/ai-job-search - Python, 2213 stars today 2.… — @ghtrend.newsmast.social.ap.brid.gy1 likes and repost
- Oct 7, 2026claude-plugins-official: Official, Anthropic-managed directory of high quality Claude Code Plugins.… — @latreon.bsky.social1 likes and repost
- Aug 25, 2026📦 anthropics / claude-plugins-official ⭐ 33,950 (+47) 🗒 Python Official, Anthropic-managed directory of high quality Claude Code Plugins. — @github-trending.bsky.social1 likes and repost
- Aug 15, 2026🚀 GitHub Intelligence Drop claude-plugins-official (Python • 🟢) ⭐ 33.5K → https://github.com/anthropics/claude-plugins-official… — @githubfeed.bsky.social1 likes and repost
- May 24, 2026📈 Today's GitHub Trending: 1. https://github.com/Lum1104/Understand-Anything - TypeScript, 3987 stars today 2.… — @ghtrend.newsmast.social.ap.brid.gy1 likes and repost · 3 replies
- May 23, 2026📈 Today's GitHub Trending: 1. https://github.com/Lum1104/Understand-Anything - TypeScript, 2331 stars today 2.… — @ghtrend.newsmast.social.ap.brid.gy1 likes and repost · 1 reply
- May 21, 2026📈 Today's GitHub Trending: 1. https://github.com/anthropics/claude-plugins-official - Python, 891 stars today 2.… — @ghtrend.newsmast.social.ap.brid.gy1 likes and repost · 1 reply
- May 19, 2026🔥 Hot Repo! 🔥 (100+ new stars) 📦 anthropics / claude-plugins-official ⭐ 19,816 (+127) 🗒 Python Official, Anthropic-managed directory of… — @github-trending.bsky.social1 likes and repost
- Mar 1, 2026anthropics / claude-plugins-official Official, Anthropic-managed directory of high quality Claude Code Plugins.… — @pythonhub.dev1 likes and repost
- Feb 4, 2026これはClaude Codeの機能を拡張する公式プラグイン群のディレクトリらしい 開発ワークフローの標準化や新しいAIエージェントの利用に期待できるかな yug1224 starred anthropics/claude-plugins-official… — @yug1224.com1 likes and repost
- Aug 29, 2026📈 Today's GitHub Trending: 1. https://github.com/tt-a1i/archify - JavaScript, 3927 stars today 2.… — @ghtrend.newsmast.social.ap.brid.gy0 likes and reposts · 1 reply
- Aug 29, 2026🚀 Skyrocketing! 🚀 (200+ new stars) 📦 anthropics / claude-plugins-official ⭐ 35,238 (+356) 🗒 Python Official, Anthropic-managed… — @github-trending.bsky.social0 likes and reposts · 1 reply
- Aug 28, 2026📈 Today's GitHub Trending: 1. https://github.com/tt-a1i/archify - JavaScript, 4561 stars today 2.… — @ghtrend.newsmast.social.ap.brid.gy0 likes and reposts · 1 reply
- Aug 26, 2026📈 Today's GitHub Trending: 1. https://github.com/tt-a1i/archify - HTML, 1002 stars today 2.… — @ghtrend.newsmast.social.ap.brid.gy0 likes and reposts · 1 reply
On Hacker News · 1
- Apr 14, 2026Connect iMessage to your Claude Code assistant2 points
Other versions8 projects use a version of this.
Word for word · 7
- Galaxy-Dawn/claude-scholar★ 5.7k100% same
- jorgeasaurus/agent-skills★ 13100% same
- JayAI623/claude-code-config★ 2100% same
- kvivek0591/claude-code-skills★ 2100% same
- Airmomo/skills★ 1100% same
- gcapodeferro02/my-agent-skills★ 1100% same
- ghoshsam/claude-code-skills★ 0100% same
Edited · 0
None found.
Wrote their own version · 1
- liqiongyu/my-agents★ 29same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository32 other files it gives its agents.
- accessSkill
- configureSkill
- accessSkill
- configureSkill
- accessSkill
- configureSkill
- claude-automation-recommenderSkill
- claude-md-improverSkill
- claude-securitySkill
- cardputer-buddySkill
- m5-onboardSkill
- example-commandSkill
- example-skillSkill
- frontend-designSkill
- writing-hookify-rulesSkill
- math-olympiadSkill
- siegeSkill
- soloSkill
- build-mcp-appSkill
- build-mcpbSkill
- build-mcp-serverSkill
- playgroundSkill
- agent-developmentSkill
- command-developmentSkill
- mcp-integrationSkill
- plugin-settingsSkill
- plugin-structureSkill
- skill-developmentSkill
- project-artifactSkill
- receiptsSkill
- session-reportSkill
- skill-creatorSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
26 rules. About 0 are common, 15 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Use LLM-driven decision making for context-aware validation:
- Distinctive: line 34
Supported events: Stop, SubagentStop, UserPromptSubmit, PreToolUse
- Distinctive: line 115
No wrapper - events directly at top level
- Distinctive: line 302
All hooks receive JSON via stdin with common fields:
- Distinctive: line 431
Always validate inputs in command hooks:
- Distinctive: line 449
Check for path traversal and sensitive files:
- Distinctive: line 497
All matching hooks run in parallel:
- Distinctive: line 521
Use command hooks for quick deterministic checks
- Distinctive: line 522
Use prompt hooks for complex reasoning
- Distinctive: line 528
Create hooks that activate conditionally by checking for a flag file or configuration:
- Distinctive: line 570
Best practice: Document activation mechanism in plugin README so users know how to enable/disable temporary hooks.
- Very specific: line 582
Must restart Claude Code: exit and run claude again
- Very specific: line 589
Test hooks with claude --debug
- Very specific: line 598
Use /hooks command to review loaded hooks in current session.
- Distinctive: line 608
Look for hook registration, execution logs, input/output JSON, and timing information.
- Distinctive: line 612
Test command hooks directly:
- Distinctive: line 623
Ensure hooks output valid JSON:
- Very specific: line 688
test-hook.sh: - Test hooks with sample input before deployment - Very specific: line 689
hook-linter.sh: - Check hook scripts for common issues and best practices - Very specific: line 695
Testing: Use claude --debug for detailed logs
- Very specific: line 696
Validation: Use jq to validate hook JSON output
- Very specific: line 704
Write hook configuration in hooks/hooks.json
- Very specific: line 706
Use ${CLAUDE_PLUGIN_ROOT} for all file references
- Very specific: line 708
Test hooks with scripts/test-hook.sh before deployment
- Very specific: line 709
Test in Claude Code with claude --debug
- Distinctive: line 710
Document hooks in plugin README
≈ “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.
Files
Hook Development for Claude Code Plugins
Overview
Hooks are event-driven automation scripts that execute in response to Claude Code events. Use hooks to validate operations, enforce policies, add context, and integrate external tools into workflows.
Key capabilities:
- Validate tool calls before execution (PreToolUse)
- React to tool results (PostToolUse)
- Enforce completion standards (Stop, SubagentStop)
- Load project context (SessionStart)
- Automate workflows across the development lifecycle
Hook Types
Prompt-Based Hooks (Recommended)
Use LLM-driven decision making for context-aware validation:
{
"type": "prompt",
"prompt": "Evaluate if this tool use is appropriate: $TOOL_INPUT",
"timeout": 30
}Supported events: Stop, SubagentStop, UserPromptSubmit, PreToolUse
Benefits:
- Context-aware decisions based on natural language reasoning
- Flexible evaluation logic without bash scripting
- Better edge case handling
- Easier to maintain and extend
Command Hooks
Execute bash commands for deterministic checks:
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh",
"timeout": 60
}Use for:
- Fast deterministic validations
- File system operations
- External tool integrations
- Performance-critical checks
Hook Configuration Formats
Plugin hooks.json Format
For plugin hooks in hooks/hooks.json, use wrapper format:
{
"description": "Brief explanation of hooks (optional)",
"hooks": {
"PreToolUse": [...],
"Stop": [...],
"SessionStart": [...]
}
}Key points:
descriptionfield is optionalhooksfield is required wrapper containing actual hook events- This is the plugin-specific format
Example:
{
"description": "Validation hooks for code quality",
"hooks": {
"PreToolUse": [
{
"matcher": "Write",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/validate.sh"
}
]
}
]
}
}Settings Format (Direct)
For user settings in .claude/settings.json, use direct format:
{
"PreToolUse": [...],
"Stop": [...],
"SessionStart": [...]
}Key points:
- No wrapper - events directly at top level
- No description field
- This is the settings format
Important: The examples below show the hook event structure that goes inside either format. For plugin hooks.json, wrap these in {"hooks": {...}}.
Hook Events
PreToolUse
Execute before any tool runs. Use to approve, deny, or modify tool calls.
Example (prompt-based):
{
"PreToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "prompt",
"prompt": "Validate file write safety. Check: system paths, credentials, path traversal, sensitive content. Return 'approve' or 'deny'."
}
]
}
]
}Output for PreToolUse:
{
"hookSpecificOutput": {
"permissionDecision": "allow|deny|ask",
"updatedInput": {"field": "modified_value"}
},
"systemMessage": "Explanation for Claude"
}PostToolUse
Execute after tool completes. Use to react to results, provide feedback, or log.
Example:
{
"PostToolUse": [
{
"matcher": "Edit",
"hooks": [
{
"type": "prompt",
"prompt": "Analyze edit result for potential issues: syntax errors, security vulnerabilities, breaking changes. Provide feedback."
}
]
}
]
}Output behavior:
- Exit 0: stdout shown in transcript
- Exit 2: stderr fed back to Claude
- systemMessage included in context
Stop
Execute when main agent considers stopping. Use to validate completeness.
Example:
{
"Stop": [
{
"matcher": "*",
"hooks": [
{
"type": "prompt",
"prompt": "Verify task completion: tests run, build succeeded, questions answered. Return 'approve' to stop or 'block' with reason to continue."
}
]
}
]
}Decision output:
{
"decision": "approve|block",
"reason": "Explanation",
"systemMessage": "Additional context"
}SubagentStop
Execute when subagent considers stopping. Use to ensure subagent completed its task.
Similar to Stop hook, but for subagents.
UserPromptSubmit
Execute when user submits a prompt. Use to add context, validate, or block prompts.
Example:
{
"UserPromptSubmit": [
{
"matcher": "*",
"hooks": [
{
"type": "prompt",
"prompt": "Check if prompt requires security guidance. If discussing auth, permissions, or API security, return relevant warnings."
}
]
}
]
}SessionStart
Execute when Claude Code session begins. Use to load context and set environment.
Example:
{
"SessionStart": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/load-context.sh"
}
]
}
]
}Special capability: Persist environment variables using $CLAUDE_ENV_FILE:
echo "export PROJECT_TYPE=nodejs" >> "$CLAUDE_ENV_FILE"See examples/load-context.sh for complete example.
SessionEnd
Execute when session ends. Use for cleanup, logging, and state preservation.
PreCompact
Execute before context compaction. Use to add critical information to preserve.
Notification
Execute when Claude sends notifications. Use to react to user notifications.
Hook Output Format
Standard Output (All Hooks)
{
"continue": true,
"suppressOutput": false,
"systemMessage": "Message for Claude"
}continue: If false, halt processing (default true)suppressOutput: Hide output from transcript (default false)systemMessage: Message shown to Claude
Exit Codes
0- Success (stdout shown in transcript)2- Blocking error (stderr fed back to Claude)- Other - Non-blocking error
Hook Input Format
All hooks receive JSON via stdin with common fields:
{
"session_id": "abc123",
"transcript_path": "/path/to/transcript.txt",
"cwd": "/current/working/dir",
"permission_mode": "ask|allow",
"hook_event_name": "PreToolUse"
}Event-specific fields:
- PreToolUse/PostToolUse:
tool_name,tool_input,tool_result - UserPromptSubmit:
user_prompt - Stop/SubagentStop:
reason
Access fields in prompts using $TOOL_INPUT, $TOOL_RESULT, $USER_PROMPT, etc.
Environment Variables
Available in all command hooks:
$CLAUDE_PROJECT_DIR- Project root path$CLAUDE_PLUGIN_ROOT- Plugin directory (use for portable paths)$CLAUDE_ENV_FILE- SessionStart only: persist env vars here$CLAUDE_CODE_REMOTE- Set if running in remote context
Always use ${CLAUDE_PLUGIN_ROOT} in hook commands for portability:
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh"
}Plugin Hook Configuration
In plugins, define hooks in hooks/hooks.json:
{
"PreToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "prompt",
"prompt": "Validate file write safety"
}
]
}
],
"Stop": [
{
"matcher": "*",
"hooks": [
{
"type": "prompt",
"prompt": "Verify task completion"
}
]
}
],
"SessionStart": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/load-context.sh",
"timeout": 10
}
]
}
]
}Plugin hooks merge with user's hooks and run in parallel.
Matchers
Tool Name Matching
Exact match:
"matcher": "Write"Multiple tools:
"matcher": "Read|Write|Edit"Wildcard (all tools):
"matcher": "*"Regex patterns:
"matcher": "mcp__.*__delete.*" // All MCP delete toolsNote: Matchers are case-sensitive.
Common Patterns
// All MCP tools
"matcher": "mcp__.*"
// Specific plugin's MCP tools
"matcher": "mcp__plugin_asana_.*"
// All file operations
"matcher": "Read|Write|Edit"
// Bash commands only
"matcher": "Bash"Security Best Practices
Input Validation
Always validate inputs in command hooks:
#!/bin/bash
set -euo pipefail
input=$(cat)
tool_name=$(echo "$input" | jq -r '.tool_name')
# Validate tool name format
if [[ ! "$tool_name" =~ ^[a-zA-Z0-9_]+$ ]]; then
echo '{"decision": "deny", "reason": "Invalid tool name"}' >&2
exit 2
fiPath Safety
Check for path traversal and sensitive files:
file_path=$(echo "$input" | jq -r '.tool_input.file_path')
# Deny path traversal
if [[ "$file_path" == *".."* ]]; then
echo '{"decision": "deny", "reason": "Path traversal detected"}' >&2
exit 2
fi
# Deny sensitive files
if [[ "$file_path" == *".env"* ]]; then
echo '{"decision": "deny", "reason": "Sensitive file"}' >&2
exit 2
fiSee examples/validate-write.sh and examples/validate-bash.sh for complete examples.
Quote All Variables
# GOOD: Quoted
echo "$file_path"
cd "$CLAUDE_PROJECT_DIR"
# BAD: Unquoted (injection risk)
echo $file_path
cd $CLAUDE_PROJECT_DIRSet Appropriate Timeouts
{
"type": "command",
"command": "bash script.sh",
"timeout": 10
}Defaults: Command hooks (60s), Prompt hooks (30s)
Performance Considerations
Parallel Execution
All matching hooks run in parallel:
{
"PreToolUse": [
{
"matcher": "Write",
"hooks": [
{"type": "command", "command": "check1.sh"}, // Parallel
{"type": "command", "command": "check2.sh"}, // Parallel
{"type": "prompt", "prompt": "Validate..."} // Parallel
]
}
]
}Design implications:
- Hooks don't see each other's output
- Non-deterministic ordering
- Design for independence
Optimization
- Use command hooks for quick deterministic checks
- Use prompt hooks for complex reasoning
- Cache validation results in temp files
- Minimize I/O in hot paths
Temporarily Active Hooks
Create hooks that activate conditionally by checking for a flag file or configuration:
Pattern: Flag file activation
#!/bin/bash
# Only active when flag file exists
FLAG_FILE="$CLAUDE_PROJECT_DIR/.enable-strict-validation"
if [ ! -f "$FLAG_FILE" ]; then
# Flag not present, skip validation
exit 0
fi
# Flag present, run validation
input=$(cat)
# ... validation logic ...Pattern: Configuration-based activation
#!/bin/bash
# Check configuration for activation
CONFIG_FILE="$CLAUDE_PROJECT_DIR/.claude/plugin-config.json"
if [ -f "$CONFIG_FILE" ]; then
enabled=$(jq -r '.strictMode // false' "$CONFIG_FILE")
if [ "$enabled" != "true" ]; then
exit 0 # Not enabled, skip
fi
fi
# Enabled, run hook logic
input=$(cat)
# ... hook logic ...Use cases:
- Enable strict validation only when needed
- Temporary debugging hooks
- Project-specific hook behavior
- Feature flags for hooks
Best practice: Document activation mechanism in plugin README so users know how to enable/disable temporary hooks.
Hook Lifecycle and Limitations
Hooks Load at Session Start
Important: Hooks are loaded when Claude Code session starts. Changes to hook configuration require restarting Claude Code.
Cannot hot-swap hooks:
- Editing
hooks/hooks.jsonwon't affect current session - Adding new hook scripts won't be recognized
- Changing hook commands/prompts won't update
- Must restart Claude Code: exit and run
claudeagain
To test hook changes:
- Edit hook configuration or scripts
- Exit Claude Code session
- Restart:
claudeorcc - New hook configuration loads
- Test hooks with
claude --debug
Hook Validation at Startup
Hooks are validated when Claude Code starts:
- Invalid JSON in hooks.json causes loading failure
- Missing scripts cause warnings
- Syntax errors reported in debug mode
Use /hooks command to review loaded hooks in current session.
Debugging Hooks
Enable Debug Mode
claude --debugLook for hook registration, execution logs, input/output JSON, and timing information.
Test Hook Scripts
Test command hooks directly:
echo '{"tool_name": "Write", "tool_input": {"file_path": "/test"}}' | \
bash ${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh
echo "Exit code: $?"Validate JSON Output
Ensure hooks output valid JSON:
output=$(./your-hook.sh < test-input.json)
echo "$output" | jq .Quick Reference
Hook Events Summary
| Event | When | Use For |
| PreToolUse | Before tool | Validation, modification |
| PostToolUse | After tool | Feedback, logging |
| UserPromptSubmit | User input | Context, validation |
| Stop | Agent stopping | Completeness check |
| SubagentStop | Subagent done | Task validation |
| SessionStart | Session begins | Context loading |
| SessionEnd | Session ends | Cleanup, logging |
| PreCompact | Before compact | Preserve context |
| Notification | User notified | Logging, reactions |
Best Practices
DO:
- ✅ Use prompt-based hooks for complex logic
- ✅ Use ${CLAUDE_PLUGIN_ROOT} for portability
- ✅ Validate all inputs in command hooks
- ✅ Quote all bash variables
- ✅ Set appropriate timeouts
- ✅ Return structured JSON output
- ✅ Test hooks thoroughly
DON'T:
- ❌ Use hardcoded paths
- ❌ Trust user input without validation
- ❌ Create long-running hooks
- ❌ Rely on hook execution order
- ❌ Modify global state unpredictably
- ❌ Log sensitive information
Additional Resources
Reference Files
For detailed patterns and advanced techniques, consult:
references/patterns.md- Common hook patterns (8+ proven patterns)references/migration.md- Migrating from basic to advanced hooksreferences/advanced.md- Advanced use cases and techniques
Example Hook Scripts
Working examples in examples/:
validate-write.sh- File write validation examplevalidate-bash.sh- Bash command validation exampleload-context.sh- SessionStart context loading example
Utility Scripts
Development tools in scripts/:
validate-hook-schema.sh- Validate hooks.json structure and syntaxtest-hook.sh- Test hooks with sample input before deploymenthook-linter.sh- Check hook scripts for common issues and best practices
External Resources
- Official Docs: https://docs.claude.com/en/docs/claude-code/hooks
- Examples: See security-guidance plugin in marketplace
- Testing: Use
claude --debugfor detailed logs - Validation: Use
jqto validate hook JSON output
Implementation Workflow
To implement hooks in a plugin:
- Identify events to hook into (PreToolUse, Stop, SessionStart, etc.)
- Decide between prompt-based (flexible) or command (deterministic) hooks
- Write hook configuration in
hooks/hooks.json - For command hooks, create hook scripts
- Use ${CLAUDE_PLUGIN_ROOT} for all file references
- Validate configuration with
scripts/validate-hook-schema.sh hooks/hooks.json - Test hooks with
scripts/test-hook.shbefore deployment - Test in Claude Code with
claude --debug - Document hooks in plugin README
Focus on prompt-based hooks for most use cases. Reserve command hooks for performance-critical or deterministic checks.
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
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.

