.fyi
SkillsMCPPluginsSubagents

Browse by category

DevOps & CI/CD SkillsProductivity & Workflow SkillsOther SkillsProduct & Project Management SkillsDocumentation & Knowledge SkillsCode Review & Refactor SkillsBackend & APIs SkillsAgent Meta & Communication SkillsResearch SkillsSecurity SkillsUX UI & Design SkillsTesting & QA SkillsSee all →

Every Claude Code skill, MCP server, plugin and subagent in one directory. Searchable, comparable, and one command from installed. Live stats from GitHub, npm and PyPI.

We're on Product HuntYour agent's app storeCheck it out →
Agent SkillsMCP ServersPluginsSubagentsCoding Agents
CollectionsOfficial publishersGlossaryFAQBlogSearchSavedFeedback
PrivacyTermsllms.txtSitemap

made with ♥ · © 2026 aaaa.fyi

Independent project · real data from public registries

…/claude-code/hook-development
home/skills/anthropics/claude-code/hook-development
anthropics avatar

hook-development

byanthropics· 237 skills

Installs

12k

Stars

139k

Forks

22k

Category

Productivity & Workflow

View on GitHub

TL;DR

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.

How to install hook-development?

anthropics/claude-code/hook-development
$npx -y skills add anthropics/claude-code --skill hook-development

Installs into the current project.

›Prefer a prompt? Paste this to your agent

Use this skill

Run `npx skills use "https://github.com/anthropics/claude-code" --skill "anthropics/claude-code/hook-development"` and follow the generated skill instructions now. Read its complete output, redirecting it to a temporary file first if necessary. Resolve relative paths from the supporting-files directory it provides.

Use the whole pack

Use the skills in "https://github.com/anthropics/claude-code" that are relevant to the current task. Run `npx skills add "https://github.com/anthropics/claude-code"` and select the relevant skills, then follow their instructions.

Files · 1

View on GitHub
SKILL.md
1# Hook Development for Claude Code Plugins
2 
3## Overview
4 
5Hooks 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.
6 
7**Key capabilities:**
8- Validate tool calls before execution (PreToolUse)
9- React to tool results (PostToolUse)
10- Enforce completion standards (Stop, SubagentStop)
11- Load project context (SessionStart)
12- Automate workflows across the development lifecycle
13 
14## Hook Types
15 
16### Prompt-Based Hooks (Recommended)
17 
18Use LLM-driven decision making for context-aware validation:
19 
20```json
21{
22 "type": "prompt",
23 "prompt": "Evaluate if this tool use is appropriate: $TOOL_INPUT",
24 "timeout": 30
25}
26```
27 
28**Supported events:** Stop, SubagentStop, UserPromptSubmit, PreToolUse
29 
30**Benefits:**
31- Context-aware decisions based on natural language reasoning
32- Flexible evaluation logic without bash scripting
33- Better edge case handling
34- Easier to maintain and extend
35 
36### Command Hooks
37 
38Execute bash commands for deterministic checks:
39 
40```json
41{
42 "type": "command",
43 "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh",
44 "timeout": 60
45}
46```
47 
48**Use for:**
49- Fast deterministic validations
50- File system operations
51- External tool integrations
52- Performance-critical checks
53 
54## Hook Configuration Formats
55 
56### Plugin hooks.json Format
57 
58**For plugin hooks** in `hooks/hooks.json`, use wrapper format:
59 
60```json
61{
62 "description": "Brief explanation of hooks (optional)",
63 "hooks": {
64 "PreToolUse": [...],
65 "Stop": [...],
66 "SessionStart": [...]
67 }
68}
69```
70 
71**Key points:**
72- `description` field is optional
73- `hooks` field is required wrapper containing actual hook events
74- This is the **plugin-specific format**
75 
76**Example:**
77```json
78{
79 "description": "Validation hooks for code quality",
80 "hooks": {
81 "PreToolUse": [
82 {
83 "matcher": "Write",
84 "hooks": [
85 {
86 "type": "command",
87 "command": "${CLAUDE_PLUGIN_ROOT}/hooks/validate.sh"
88 }
89 ]
90 }
91 ]
92 }
93}
94```
95 
96### Settings Format (Direct)
97 
98**For user settings** in `.claude/settings.json`, use direct format:
99 
100```json
101{
102 "PreToolUse": [...],
103 "Stop": [...],
104 "SessionStart": [...]
105}
106```
107 
108**Key points:**
109- No wrapper - events directly at top level
110- No description field
111- This is the **settings format**
112 
113**Important:** The examples below show the hook event structure that goes inside either format. For plugin hooks.json, wrap these in `{"hooks": {...}}`.
114 
115## Hook Events
116 
117### PreToolUse
118 
119Execute before any tool runs. Use to approve, deny, or modify tool calls.
120 
121**Example (prompt-based):**
122```json
123{
124 "PreToolUse": [
125 {
126 "matcher": "Write|Edit",
127 "hooks": [
128 {
129 "type": "prompt",
130 "prompt": "Validate file write safety. Check: system paths, credentials, path traversal, sensitive content. Return 'approve' or 'deny'."
131 }
132 ]
133 }
134 ]
135}
136```
137 
138**Output for PreToolUse:**
139```json
140{
141 "hookSpecificOutput": {
142 "permissionDecision": "allow|deny|ask",
143 "updatedInput": {"field": "modified_value"}
144 },
145 "systemMessage": "Explanation for Claude"
146}
147```
148 
149### PostToolUse
150 
151Execute after tool completes. Use to react to results, provide feedback, or log.
152 
153**Example:**
154```json
155{
156 "PostToolUse": [
157 {
158 "matcher": "Edit",
159 "hooks": [
160 {
161 "type": "prompt",
162 "prompt": "Analyze edit result for potential issues: syntax errors, security vulnerabilities, breaking changes. Provide feedback."
163 }
164 ]
165 }
166 ]
167}
168```
169 
170**Output behavior:**
171- Exit 0: stdout shown in transcript
172- Exit 2: stderr fed back to Claude
173- systemMessage included in context
174 
175### Stop
176 
177Execute when main agent considers stopping. Use to validate completeness.
178 
179**Example:**
180```json
181{
182 "Stop": [
183 {
184 "matcher": "*",
185 "hooks": [
186 {
187 "type": "prompt",
188 "prompt": "Verify task completion: tests run, build succeeded, questions answered. Return 'approve' to stop or 'block' with reason to continue."
189 }
190 ]
191 }
192 ]
193}
194```
195 
196**Decision output:**
197```json
198{
199 "decision": "approve|block",
200 "reason": "Explanation",
201 "systemMessage": "Additional context"
202}
203```
204 
205### SubagentStop
206 
207Execute when subagent considers stopping. Use to ensure subagent completed its task.
208 
209Similar to Stop hook, but for subagents.
210 
211### UserPromptSubmit
212 
213Execute when user submits a prompt. Use to add context, validate, or block prompts.
214 
215**Example:**
216```json
217{
218 "UserPromptSubmit": [
219 {
220 "matcher": "*",
221 "hooks": [
222 {
223 "type": "prompt",
224 "prompt": "Check if prompt requires security guidance. If discussing auth, permissions, or API security, return relevant warnings."
225 }
226 ]
227 }
228 ]
229}
230```
231 
232### SessionStart
233 
234Execute when Claude Code session begins. Use to load context and set environment.
235 
236**Example:**
237```json
238{
239 "SessionStart": [
240 {
241 "matcher": "*",
242 "hooks": [
243 {
244 "type": "command",
245 "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/load-context.sh"
246 }
247 ]
248 }
249 ]
250}
251```
252 
253**Special capability:** Persist environment variables using `$CLAUDE_ENV_FILE`:
254```bash
255echo "export PROJECT_TYPE=nodejs" >> "$CLAUDE_ENV_FILE"
256```
257 
258See `examples/load-context.sh` for complete example.
259 
260### SessionEnd
261 
262Execute when session ends. Use for cleanup, logging, and state preservation.
263 
264### PreCompact
265 
266Execute before context compaction. Use to add critical information to preserve.
267 
268### Notification
269 
270Execute when Claude sends notifications. Use to react to user notifications.
271 
272## Hook Output Format
273 
274### Standard Output (All Hooks)
275 
276```json
277{
278 "continue": true,
279 "suppressOutput": false,
280 "systemMessage": "Message for Claude"
281}
282```
283 
284- `continue`: If false, halt processing (default true)
285- `suppressOutput`: Hide output from transcript (default false)
286- `systemMessage`: Message shown to Claude
287 
288### Exit Codes
289 
290- `0` - Success (stdout shown in transcript)
291- `2` - Blocking error (stderr fed back to Claude)
292- Other - Non-blocking error
293 
294## Hook Input Format
295 
296All hooks receive JSON via stdin with common fields:
297 
298```json
299{
300 "session_id": "abc123",
301 "transcript_path": "/path/to/transcript.txt",
302 "cwd": "/current/working/dir",
303 "permission_mode": "ask|allow",
304 "hook_event_name": "PreToolUse"
305}
306```
307 
308**Event-specific fields:**
309 
310- **PreToolUse/PostToolUse:** `tool_name`, `tool_input`, `tool_result`
311- **UserPromptSubmit:** `user_prompt`
312- **Stop/SubagentStop:** `reason`
313 
314Access fields in prompts using `$TOOL_INPUT`, `$TOOL_RESULT`, `$USER_PROMPT`, etc.
315 
316## Environment Variables
317 
318Available in all command hooks:
319 
320- `$CLAUDE_PROJECT_DIR` - Project root path
321- `$CLAUDE_PLUGIN_ROOT` - Plugin directory (use for portable paths)
322- `$CLAUDE_ENV_FILE` - SessionStart only: persist env vars here
323- `$CLAUDE_CODE_REMOTE` - Set if running in remote context
324 
325**Always use ${CLAUDE_PLUGIN_ROOT} in hook commands for portability:**
326 
327```json
328{
329 "type": "command",
330 "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh"
331}
332```
333 
334## Plugin Hook Configuration
335 
336In plugins, define hooks in `hooks/hooks.json`:
337 
338```json
339{
340 "PreToolUse": [
341 {
342 "matcher": "Write|Edit",
343 "hooks": [
344 {
345 "type": "prompt",
346 "prompt": "Validate file write safety"
347 }
348 ]
349 }
350 ],
351 "Stop": [
352 {
353 "matcher": "*",
354 "hooks": [
355 {
356 "type": "prompt",
357 "prompt": "Verify task completion"
358 }
359 ]
360 }
361 ],
362 "SessionStart": [
363 {
364 "matcher": "*",
365 "hooks": [
366 {
367 "type": "command",
368 "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/load-context.sh",
369 "timeout": 10
370 }
371 ]
372 }
373 ]
374}
375```
376 
377Plugin hooks merge with user's hooks and run in parallel.
378 
379## Matchers
380 
381### Tool Name Matching
382 
383**Exact match:**
384```json
385"matcher": "Write"
386```
387 
388**Multiple tools:**
389```json
390"matcher": "Read|Write|Edit"
391```
392 
393**Wildcard (all tools):**
394```json
395"matcher": "*"
396```
397 
398**Regex patterns:**
399```json
400"matcher": "mcp__.*__delete.*" // All MCP delete tools
401```
402 
403**Note:** Matchers are case-sensitive.
404 
405### Common Patterns
406 
407```json
408// All MCP tools
409"matcher": "mcp__.*"
410 
411// Specific plugin's MCP tools
412"matcher": "mcp__plugin_asana_.*"
413 
414// All file operations
415"matcher": "Read|Write|Edit"
416 
417// Bash commands only
418"matcher": "Bash"
419```
420 
421## Security Best Practices
422 
423### Input Validation
424 
425Always validate inputs in command hooks:
426 
427```bash
428#!/bin/bash
429set -euo pipefail
430 
431input=$(cat)
432tool_name=$(echo "$input" | jq -r '.tool_name')
433 
434# Validate tool name format
435if [[ ! "$tool_name" =~ ^[a-zA-Z0-9_]+$ ]]; then
436 echo '{"decision": "deny", "reason": "Invalid tool name"}' >&2
437 exit 2
438fi
439```
440 
441### Path Safety
442 
443Check for path traversal and sensitive files:
444 
445```bash
446file_path=$(echo "$input" | jq -r '.tool_input.file_path')
447 
448# Deny path traversal
449if [[ "$file_path" == *".."* ]]; then
450 echo '{"decision": "deny", "reason": "Path traversal detected"}' >&2
451 exit 2
452fi
453 
454# Deny sensitive files
455if [[ "$file_path" == *".env"* ]]; then
456 echo '{"decision": "deny", "reason": "Sensitive file"}' >&2
457 exit 2
458fi
459```
460 
461See `examples/validate-write.sh` and `examples/validate-bash.sh` for complete examples.
462 
463### Quote All Variables
464 
465```bash
466# GOOD: Quoted
467echo "$file_path"
468cd "$CLAUDE_PROJECT_DIR"
469 
470# BAD: Unquoted (injection risk)
471echo $file_path
472cd $CLAUDE_PROJECT_DIR
473```
474 
475### Set Appropriate Timeouts
476 
477```json
478{
479 "type": "command",
480 "command": "bash script.sh",
481 "timeout": 10
482}
483```
484 
485**Defaults:** Command hooks (60s), Prompt hooks (30s)
486 
487## Performance Considerations
488 
489### Parallel Execution
490 
491All matching hooks run **in parallel**:
492 
493```json
494{
495 "PreToolUse": [
496 {
497 "matcher": "Write",
498 "hooks": [
499 {"type": "command", "command": "check1.sh"}, // Parallel
500 {"type": "command", "command": "check2.sh"}, // Parallel
501 {"type": "prompt", "prompt": "Validate..."} // Parallel
502 ]
503 }
504 ]
505}
506```
507 
508**Design implications:**
509- Hooks don't see each other's output
510- Non-deterministic ordering
511- Design for independence
512 
513### Optimization
514 
5151. Use command hooks for quick deterministic checks
5162. Use prompt hooks for complex reasoning
5173. Cache validation results in temp files
5184. Minimize I/O in hot paths
519 
520## Temporarily Active Hooks
521 
522Create hooks that activate conditionally by checking for a flag file or configuration:
523 
524**Pattern: Flag file activation**
525```bash
526#!/bin/bash
527# Only active when flag file exists
528FLAG_FILE="$CLAUDE_PROJECT_DIR/.enable-strict-validation"
529 
530if [ ! -f "$FLAG_FILE" ]; then
531 # Flag not present, skip validation
532 exit 0
533fi
534 
535# Flag present, run validation
536input=$(cat)
537# ... validation logic ...
538```
539 
540**Pattern: Configuration-based activation**
541```bash
542#!/bin/bash
543# Check configuration for activation
544CONFIG_FILE="$CLAUDE_PROJECT_DIR/.claude/plugin-config.json"
545 
546if [ -f "$CONFIG_FILE" ]; then
547 enabled=$(jq -r '.strictMode // false' "$CONFIG_FILE")
548 if [ "$enabled" != "true" ]; then
549 exit 0 # Not enabled, skip
550 fi
551fi
552 
553# Enabled, run hook logic
554input=$(cat)
555# ... hook logic ...
556```
557 
558**Use cases:**
559- Enable strict validation only when needed
560- Temporary debugging hooks
561- Project-specific hook behavior
562- Feature flags for hooks
563 
564**Best practice:** Document activation mechanism in plugin README so users know how to enable/disable temporary hooks.
565 
566## Hook Lifecycle and Limitations
567 
568### Hooks Load at Session Start
569 
570**Important:** Hooks are loaded when Claude Code session starts. Changes to hook configuration require restarting Claude Code.
571 
572**Cannot hot-swap hooks:**
573- Editing `hooks/hooks.json` won't affect current session
574- Adding new hook scripts won't be recognized
575- Changing hook commands/prompts won't update
576- Must restart Claude Code: exit and run `claude` again
577 
578**To test hook changes:**
5791. Edit hook configuration or scripts
5802. Exit Claude Code session
5813. Restart: `claude` or `cc`
5824. New hook configuration loads
5835. Test hooks with `claude --debug`
584 
585### Hook Validation at Startup
586 
587Hooks are validated when Claude Code starts:
588- Invalid JSON in hooks.json causes loading failure
589- Missing scripts cause warnings
590- Syntax errors reported in debug mode
591 
592Use `/hooks` command to review loaded hooks in current session.
593 
594## Debugging Hooks
595 
596### Enable Debug Mode
597 
598```bash
599claude --debug
600```
601 
602Look for hook registration, execution logs, input/output JSON, and timing information.
603 
604### Test Hook Scripts
605 
606Test command hooks directly:
607 
608```bash
609echo '{"tool_name": "Write", "tool_input": {"file_path": "/test"}}' | \
610 bash ${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh
611 
612echo "Exit code: $?"
613```
614 
615### Validate JSON Output
616 
617Ensure hooks output valid JSON:
618 
619```bash
620output=$(./your-hook.sh < test-input.json)
621echo "$output" | jq .
622```
623 
624## Quick Reference
625 
626### Hook Events Summary
627 
628| Event | When | Use For |
629|-------|------|---------|
630| PreToolUse | Before tool | Validation, modification |
631| PostToolUse | After tool | Feedback, logging |
632| UserPromptSubmit | User input | Context, validation |
633| Stop | Agent stopping | Completeness check |
634| SubagentStop | Subagent done | Task validation |
635| SessionStart | Session begins | Context loading |
636| SessionEnd | Session ends | Cleanup, logging |
637| PreCompact | Before compact | Preserve context |
638| Notification | User notified | Logging, reactions |
639 
640### Best Practices
641 
642**DO:**
643- ✅ Use prompt-based hooks for complex logic
644- ✅ Use ${CLAUDE_PLUGIN_ROOT} for portability
645- ✅ Validate all inputs in command hooks
646- ✅ Quote all bash variables
647- ✅ Set appropriate timeouts
648- ✅ Return structured JSON output
649- ✅ Test hooks thoroughly
650 
651**DON'T:**
652- ❌ Use hardcoded paths
653- ❌ Trust user input without validation
654- ❌ Create long-running hooks
655- ❌ Rely on hook execution order
656- ❌ Modify global state unpredictably
657- ❌ Log sensitive information
658 
659## Additional Resources
660 
661### Reference Files
662 
663For detailed patterns and advanced techniques, consult:
664 
665- **`references/patterns.md`** - Common hook patterns (8+ proven patterns)
666- **`references/migration.md`** - Migrating from basic to advanced hooks
667- **`references/advanced.md`** - Advanced use cases and techniques
668 
669### Example Hook Scripts
670 
671Working examples in `examples/`:
672 
673- **`validate-write.sh`** - File write validation example
674- **`validate-bash.sh`** - Bash command validation example
675- **`load-context.sh`** - SessionStart context loading example
676 
677### Utility Scripts
678 
679Development tools in `scripts/`:
680 
681- **`validate-hook-schema.sh`** - Validate hooks.json structure and syntax
682- **`test-hook.sh`** - Test hooks with sample input before deployment
683- **`hook-linter.sh`** - Check hook scripts for common issues and best practices
684 
685### External Resources
686 
687- **Official Docs**: https://docs.claude.com/en/docs/claude-code/hooks
688- **Examples**: See security-guidance plugin in marketplace
689- **Testing**: Use `claude --debug` for detailed logs
690- **Validation**: Use `jq` to validate hook JSON output
691 
692## Implementation Workflow
693 
694To implement hooks in a plugin:
695 
6961. Identify events to hook into (PreToolUse, Stop, SessionStart, etc.)
6972. Decide between prompt-based (flexible) or command (deterministic) hooks
6983. Write hook configuration in `hooks/hooks.json`
6994. For command hooks, create hook scripts
7005. Use ${CLAUDE_PLUGIN_ROOT} for all file references
7016. Validate configuration with `scripts/validate-hook-schema.sh hooks/hooks.json`
7027. Test hooks with `scripts/test-hook.sh` before deployment
7038. Test in Claude Code with `claude --debug`
7049. Document hooks in plugin README
705 
706Focus on prompt-based hooks for most use cases. Reserve command hooks for performance-critical or deterministic checks.

Security

Review

  • Gen Agent Trust Hubpass
  • Socketpass
  • Snykpass
  • Runlayerwarn
  • ZeroLeakspass

Preview

anthropics/claude-codeanthropics/claude-code

$ npx -y skills add anthropics/claude-code --skill hook-development

▸ installing to .claude/skills…

✓ hook-development ready

Repoanthropics/claude-code
TypeSkills
CategoryProductivity & Workflow
ForDeveloper
UpdatedJul 2026
License—
First seenJul 26, 2026

Tags

Skill

Related

6 picks
Type
  1. juliusbrussee avatarcavemanUltra-compressed communication mode. Cuts output tokens 65% (measured) by speaking like caveman while keeping full technical accuracy.SkillsJul 2026391k93k
  2. larksuite avatarlark-im飞书即时通讯:收发消息和管理群聊。发送和回复消息、搜索聊天记录、管理群聊成员、上传下载图片和文件(支持大文件分片下载)、管理表情回复、发送应用内/短信/电话加急、发送和处理交互卡片(Interactive…SkillsJul 2026390k16k
  3. larksuite avatarlark-calendar飞书日历:管理日历日程和会议室。查看/搜索日程、创建/更新日程、管理参会人、查询忙闲和推荐时段、预定会议室。当用户需要查看日程安排、创建/修改会议、查询/预定会议室时使用。不负责:查询过去的视频会议记录(走 lark-vc)、待办任务(走 lark-task)。SkillsJul 2026388k16k
  4. larksuite avatarlark-contact飞书 / Lark 通讯录:按姓名 / 邮箱解析成 open_id,或按 open_id 反查姓名 / 部门 / 邮箱 / 联系方式 / 个人状态 / 签名。当用户提到某人姓名要下一步发消息 / 排日程,或拿到 open_id 想查具体信息时使用。不负责部门树遍历、按部门列员工、组织架构图,这类需求走原生…SkillsJul 2026387k16k
  5. larksuite avatarlark-workflow-meeting-summary会议纪要整理工作流:汇总指定时间范围内的会议纪要并生成结构化报告。当用户需要整理会议纪要、生成会议周报、回顾一段时间内的会议内容时使用。SkillsJul 2026386k16k
  6. larksuite avatarlark-workflow-standup-report日程待办摘要:编排 calendar +agenda 和 task +get-my-tasks,生成指定日期的日程与未完成任务摘要。适用于了解今天/明天/本周的安排。SkillsJul 2026386k16k