claude-all-hands 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/code-simplifier.md +52 -0
- package/.claude/agents/curator.md +189 -245
- package/.claude/agents/documentor.md +147 -0
- package/.claude/agents/planner.md +123 -166
- package/.claude/agents/researcher.md +58 -41
- package/.claude/agents/surveyor.md +81 -0
- package/.claude/agents/worker.md +74 -0
- package/.claude/commands/audit-docs.md +94 -0
- package/.claude/commands/continue.md +120 -0
- package/.claude/commands/create-docs.md +100 -0
- package/.claude/commands/create-skill.md +107 -0
- package/.claude/commands/create-specialist.md +111 -0
- package/.claude/commands/curator-audit.md +4 -0
- package/.claude/commands/debug.md +183 -0
- package/.claude/commands/plan.md +199 -102
- package/.claude/commands/validate.md +11 -0
- package/.claude/commands/whats-next.md +106 -134
- package/.claude/envoy/envoy +11 -14
- package/.claude/envoy/package-lock.json +1388 -0
- package/.claude/envoy/package.json +29 -0
- package/.claude/envoy/src/cli.ts +126 -0
- package/.claude/envoy/src/commands/base.ts +216 -0
- package/.claude/envoy/src/commands/gemini.ts +999 -0
- package/.claude/envoy/src/commands/git.ts +639 -0
- package/.claude/envoy/src/commands/index.ts +73 -0
- package/.claude/envoy/src/commands/knowledge.ts +187 -0
- package/.claude/envoy/src/commands/perplexity.ts +129 -0
- package/.claude/envoy/src/commands/plan/core.ts +134 -0
- package/.claude/envoy/src/commands/plan/findings.ts +446 -0
- package/.claude/envoy/src/commands/plan/gates.ts +672 -0
- package/.claude/envoy/src/commands/plan/index.ts +135 -0
- package/.claude/envoy/src/commands/plan/lifecycle.ts +648 -0
- package/.claude/envoy/src/commands/plan/plan-file.ts +138 -0
- package/.claude/envoy/src/commands/plan/prompts.ts +285 -0
- package/.claude/envoy/src/commands/plan/protocols.ts +166 -0
- package/.claude/envoy/src/commands/repomix.ts +99 -0
- package/.claude/envoy/src/commands/tavily.ts +220 -0
- package/.claude/envoy/src/commands/xai.ts +168 -0
- package/.claude/envoy/src/lib/design.ts +41 -0
- package/.claude/envoy/src/lib/feedback-schemas.ts +154 -0
- package/.claude/envoy/src/lib/findings.ts +215 -0
- package/.claude/envoy/src/lib/gates.ts +572 -0
- package/.claude/envoy/src/lib/git.ts +132 -0
- package/.claude/envoy/src/lib/index.ts +188 -0
- package/.claude/envoy/src/lib/knowledge.ts +594 -0
- package/.claude/envoy/src/lib/markdown.ts +75 -0
- package/.claude/envoy/src/lib/observability.ts +262 -0
- package/.claude/envoy/src/lib/paths.ts +130 -0
- package/.claude/envoy/src/lib/plan-io.ts +117 -0
- package/.claude/envoy/src/lib/prompts.ts +231 -0
- package/.claude/envoy/src/lib/protocols.ts +314 -0
- package/.claude/envoy/src/lib/repomix.ts +133 -0
- package/.claude/envoy/src/lib/retry.ts +138 -0
- package/.claude/envoy/src/lib/watcher.ts +167 -0
- package/.claude/envoy/tsconfig.json +21 -0
- package/.claude/hooks/scripts/scan_agents.py +62 -0
- package/.claude/hooks/scripts/scan_commands.py +50 -0
- package/.claude/hooks/scripts/scan_skills.py +46 -70
- package/.claude/hooks/scripts/validate_artifacts.py +128 -0
- package/.claude/hooks/startup.sh +26 -24
- package/.claude/protocols/bug-discovery.yaml +55 -0
- package/.claude/protocols/debugging.yaml +51 -0
- package/.claude/protocols/discovery.yaml +53 -0
- package/.claude/protocols/implementation.yaml +84 -0
- package/.claude/settings.json +37 -97
- package/.claude/skills/brainstorming/SKILL.md +54 -0
- package/.claude/skills/commands-development/SKILL.md +630 -0
- package/.claude/skills/commands-development/references/arguments.md +252 -0
- package/.claude/skills/commands-development/references/patterns.md +796 -0
- package/.claude/skills/commands-development/references/tool-restrictions.md +376 -0
- package/.claude/skills/discovery-mode/SKILL.md +108 -0
- package/.claude/skills/hooks-development/SKILL.md +332 -0
- package/.claude/skills/hooks-development/references/command-vs-prompt.md +269 -0
- package/.claude/skills/hooks-development/references/examples.md +658 -0
- package/.claude/skills/hooks-development/references/hook-types.md +463 -0
- package/.claude/skills/hooks-development/references/input-output-schemas.md +469 -0
- package/.claude/skills/hooks-development/references/matchers.md +470 -0
- package/.claude/skills/hooks-development/references/troubleshooting.md +587 -0
- package/.claude/skills/implementation-mode/SKILL.md +171 -0
- package/.claude/skills/research-tools/SKILL.md +35 -33
- package/.claude/skills/skills-development/SKILL.md +192 -0
- package/.claude/skills/skills-development/references/api-security.md +226 -0
- package/.claude/skills/skills-development/references/be-clear-and-direct.md +531 -0
- package/.claude/skills/skills-development/references/common-patterns.md +595 -0
- package/.claude/skills/skills-development/references/core-principles.md +437 -0
- package/.claude/skills/skills-development/references/executable-code.md +175 -0
- package/.claude/skills/skills-development/references/iteration-and-testing.md +474 -0
- package/.claude/skills/skills-development/references/recommended-structure.md +168 -0
- package/.claude/skills/skills-development/references/skill-structure.md +372 -0
- package/.claude/skills/skills-development/references/use-xml-tags.md +466 -0
- package/.claude/skills/skills-development/references/using-scripts.md +113 -0
- package/.claude/skills/skills-development/references/using-templates.md +112 -0
- package/.claude/skills/skills-development/references/workflows-and-validation.md +510 -0
- package/.claude/skills/skills-development/templates/router-skill.md +73 -0
- package/.claude/skills/skills-development/templates/simple-skill.md +33 -0
- package/.claude/skills/skills-development/workflows/add-reference.md +96 -0
- package/.claude/skills/skills-development/workflows/add-script.md +93 -0
- package/.claude/skills/skills-development/workflows/add-template.md +74 -0
- package/.claude/skills/skills-development/workflows/add-workflow.md +120 -0
- package/.claude/skills/skills-development/workflows/audit-skill.md +138 -0
- package/.claude/skills/skills-development/workflows/create-domain-expertise-skill.md +605 -0
- package/.claude/skills/skills-development/workflows/create-new-skill.md +191 -0
- package/.claude/skills/skills-development/workflows/get-guidance.md +121 -0
- package/.claude/skills/skills-development/workflows/upgrade-to-router.md +161 -0
- package/.claude/skills/skills-development/workflows/verify-skill.md +204 -0
- package/.claude/skills/subagents-development/SKILL.md +325 -0
- package/.claude/skills/subagents-development/references/context-management.md +567 -0
- package/.claude/skills/subagents-development/references/debugging-agents.md +714 -0
- package/.claude/skills/subagents-development/references/error-handling-and-recovery.md +502 -0
- package/.claude/skills/subagents-development/references/evaluation-and-testing.md +374 -0
- package/.claude/skills/subagents-development/references/orchestration-patterns.md +591 -0
- package/.claude/skills/subagents-development/references/subagents.md +508 -0
- package/.claude/skills/subagents-development/references/writing-subagent-prompts.md +517 -0
- package/.claude/statusline.sh +24 -0
- package/bin/cli.js +110 -72
- package/package.json +1 -1
- package/.claude/agents/explorer.md +0 -62
- package/.claude/agents/parallel-worker.md +0 -121
- package/.claude/commands/curation-fix.md +0 -92
- package/.claude/commands/new-branch.md +0 -36
- package/.claude/commands/parallel-discovery.md +0 -69
- package/.claude/commands/parallel-orchestration.md +0 -99
- package/.claude/commands/plan-checkpoint.md +0 -37
- package/.claude/envoy/commands/__init__.py +0 -1
- package/.claude/envoy/commands/base.py +0 -95
- package/.claude/envoy/commands/parallel.py +0 -439
- package/.claude/envoy/commands/perplexity.py +0 -86
- package/.claude/envoy/commands/plans.py +0 -451
- package/.claude/envoy/commands/tavily.py +0 -156
- package/.claude/envoy/commands/vertex.py +0 -358
- package/.claude/envoy/commands/xai.py +0 -124
- package/.claude/envoy/envoy.py +0 -122
- package/.claude/envoy/pyrightconfig.json +0 -4
- package/.claude/envoy/requirements.txt +0 -2
- package/.claude/hooks/capture-queries.sh +0 -3
- package/.claude/hooks/scripts/enforce_planning.py +0 -118
- package/.claude/hooks/scripts/enforce_rg.py +0 -34
- package/.claude/hooks/scripts/validate_skill.py +0 -81
- package/.claude/skills/claude-envoy-curation/SKILL.md +0 -162
- package/.claude/skills/claude-envoy-usage/SKILL.md +0 -46
- package/.claude/skills/command-development/SKILL.md +0 -206
- package/.claude/skills/command-development/examples/simple-commands.md +0 -212
- package/.claude/skills/command-development/references/frontmatter-reference.md +0 -221
- package/.claude/skills/hook-development/SKILL.md +0 -127
- package/.claude/skills/hook-development/examples/command-hooks.md +0 -301
- package/.claude/skills/hook-development/examples/prompt-hooks.md +0 -114
- package/.claude/skills/hook-development/references/event-reference.md +0 -226
- package/.claude/skills/repomix-extraction/SKILL.md +0 -91
- package/.claude/skills/skill-development/SKILL.md +0 -168
- package/.claude/skills/skill-development/examples/complete-skill-examples.md +0 -281
- package/.claude/skills/skill-development/references/progressive-disclosure.md +0 -141
- package/.claude/skills/skill-development/references/writing-style.md +0 -180
- package/.claude/skills/skill-development/scripts/validate-skill.sh +0 -144
- package/.claude/skills/specialist-builder/SKILL.md +0 -327
- package/.claude/skills/specialist-builder/docs/agent-catalog.md +0 -28
- package/.claude/skills/specialist-builder/examples/complete-agent-examples.md +0 -206
- package/.claude/skills/specialist-builder/references/system-prompt-patterns.md +0 -281
- package/.claude/skills/specialist-builder/references/triggering-examples.md +0 -162
- package/.claude/skills/specialist-builder/scripts/validate-agent.sh +0 -137
- /package/.claude/{envoy/claude-envoy.py → skills/claude-envoy-patterns/SKILL.md} +0 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hooks-development
|
|
3
|
+
description: Expert guidance for creating, refining, and auditing Claude Code hooks. Use when working with hooks, setting up event listeners, validating commands, automating workflows, adding notifications, or understanding hook types (PreToolUse, PostToolUse, Stop, SessionStart, UserPromptSubmit, etc).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<objective>
|
|
7
|
+
Hooks are event-driven automation for Claude Code that execute shell commands or LLM prompts in response to tool usage, session events, and user interactions. This skill teaches you how to create, configure, and debug hooks for validating commands, automating workflows, injecting context, and implementing custom completion criteria.
|
|
8
|
+
|
|
9
|
+
Hooks provide programmatic control over Claude's behavior without modifying core code, enabling project-specific automation, safety checks, and workflow customization.
|
|
10
|
+
</objective>
|
|
11
|
+
|
|
12
|
+
<context>
|
|
13
|
+
Hooks are shell commands or LLM-evaluated prompts that execute in response to Claude Code events. They operate within an event hierarchy: events (PreToolUse, PostToolUse, Stop, etc.) trigger matchers (tool patterns) which fire hooks (commands or prompts). Hooks can block actions, modify tool inputs, inject context, or simply observe and log Claude's operations.
|
|
14
|
+
</context>
|
|
15
|
+
|
|
16
|
+
<quick_start>
|
|
17
|
+
<workflow>
|
|
18
|
+
1. Create hooks config file:
|
|
19
|
+
- Project: `.claude/hooks.json`
|
|
20
|
+
- User: `~/.claude/hooks.json`
|
|
21
|
+
2. Choose hook event (when it fires)
|
|
22
|
+
3. Choose hook type (command or prompt)
|
|
23
|
+
4. Configure matcher (which tools trigger it)
|
|
24
|
+
5. Test with `claude --debug`
|
|
25
|
+
</workflow>
|
|
26
|
+
|
|
27
|
+
<example>
|
|
28
|
+
**Log all bash commands**:
|
|
29
|
+
|
|
30
|
+
`.claude/hooks.json`:
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"hooks": {
|
|
34
|
+
"PreToolUse": [
|
|
35
|
+
{
|
|
36
|
+
"matcher": "Bash",
|
|
37
|
+
"hooks": [
|
|
38
|
+
{
|
|
39
|
+
"type": "command",
|
|
40
|
+
"command": "jq -r '\"\\(.tool_input.command) - \\(.tool_input.description // \\\"No description\\\")\"' >> ~/.claude/bash-log.txt"
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This hook:
|
|
50
|
+
- Fires before (`PreToolUse`) every `Bash` tool use
|
|
51
|
+
- Executes a `command` (not an LLM prompt)
|
|
52
|
+
- Logs command + description to a file
|
|
53
|
+
</example>
|
|
54
|
+
</quick_start>
|
|
55
|
+
|
|
56
|
+
<hook_types>
|
|
57
|
+
| Event | When it fires | Can block? |
|
|
58
|
+
|-------|---------------|------------|
|
|
59
|
+
| **PreToolUse** | Before tool execution | Yes |
|
|
60
|
+
| **PostToolUse** | After tool execution | No |
|
|
61
|
+
| **UserPromptSubmit** | User submits a prompt | Yes |
|
|
62
|
+
| **Stop** | Claude attempts to stop | Yes |
|
|
63
|
+
| **SubagentStop** | Subagent attempts to stop | Yes |
|
|
64
|
+
| **SessionStart** | Session begins | No |
|
|
65
|
+
| **SessionEnd** | Session ends | No |
|
|
66
|
+
| **PreCompact** | Before context compaction | Yes |
|
|
67
|
+
| **Notification** | Claude needs input | No |
|
|
68
|
+
|
|
69
|
+
Blocking hooks can return `"decision": "block"` to prevent the action. See [references/hook-types.md](references/hook-types.md) for detailed use cases.
|
|
70
|
+
</hook_types>
|
|
71
|
+
|
|
72
|
+
<hook_anatomy>
|
|
73
|
+
<hook_type name="command">
|
|
74
|
+
**Type**: Executes a shell command
|
|
75
|
+
|
|
76
|
+
**Use when**:
|
|
77
|
+
- Simple validation (check file exists)
|
|
78
|
+
- Logging (append to file)
|
|
79
|
+
- External tools (formatters, linters)
|
|
80
|
+
- Desktop notifications
|
|
81
|
+
|
|
82
|
+
**Input**: JSON via stdin
|
|
83
|
+
**Output**: JSON via stdout (optional)
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"type": "command",
|
|
88
|
+
"command": "/path/to/script.sh",
|
|
89
|
+
"timeout": 30000
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
</hook_type>
|
|
93
|
+
|
|
94
|
+
<hook_type name="prompt">
|
|
95
|
+
**Type**: LLM evaluates a prompt
|
|
96
|
+
|
|
97
|
+
**Use when**:
|
|
98
|
+
- Complex decision logic
|
|
99
|
+
- Natural language validation
|
|
100
|
+
- Context-aware checks
|
|
101
|
+
- Reasoning required
|
|
102
|
+
|
|
103
|
+
**Input**: Prompt with `$ARGUMENTS` placeholder
|
|
104
|
+
**Output**: JSON with `decision` and `reason`
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"type": "prompt",
|
|
109
|
+
"prompt": "Evaluate if this command is safe: $ARGUMENTS\n\nReturn JSON: {\"decision\": \"approve\" or \"block\", \"reason\": \"explanation\"}"
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
</hook_type>
|
|
113
|
+
</hook_anatomy>
|
|
114
|
+
|
|
115
|
+
<matchers>
|
|
116
|
+
Matchers filter which tools trigger the hook:
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"matcher": "Bash", // Exact match
|
|
121
|
+
"matcher": "Write|Edit", // Multiple tools (regex OR)
|
|
122
|
+
"matcher": "mcp__.*", // All MCP tools
|
|
123
|
+
"matcher": "mcp__memory__.*" // Specific MCP server
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**No matcher**: Hook fires for all tools
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"hooks": {
|
|
131
|
+
"UserPromptSubmit": [
|
|
132
|
+
{
|
|
133
|
+
"hooks": [...] // No matcher - fires on every user prompt
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
</matchers>
|
|
140
|
+
|
|
141
|
+
<input_output>
|
|
142
|
+
Hooks receive JSON via stdin with session info, current directory, and event-specific data. Blocking hooks can return JSON to approve/block actions or modify inputs.
|
|
143
|
+
|
|
144
|
+
**Example output** (blocking hooks):
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"decision": "approve" | "block",
|
|
148
|
+
"reason": "Why this decision was made"
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
See [references/input-output-schemas.md](references/input-output-schemas.md) for complete schemas for each hook type.
|
|
153
|
+
</input_output>
|
|
154
|
+
|
|
155
|
+
<environment_variables>
|
|
156
|
+
Available in hook commands:
|
|
157
|
+
|
|
158
|
+
| Variable | Value |
|
|
159
|
+
|----------|-------|
|
|
160
|
+
| `$CLAUDE_PROJECT_DIR` | Project root directory |
|
|
161
|
+
| `${CLAUDE_PLUGIN_ROOT}` | Plugin directory (plugin hooks only) |
|
|
162
|
+
| `$ARGUMENTS` | Hook input JSON (prompt hooks only) |
|
|
163
|
+
|
|
164
|
+
**Example**:
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/validate.sh"
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
</environment_variables>
|
|
171
|
+
|
|
172
|
+
<common_patterns>
|
|
173
|
+
**Desktop notification when input needed**:
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"hooks": {
|
|
177
|
+
"Notification": [
|
|
178
|
+
{
|
|
179
|
+
"hooks": [
|
|
180
|
+
{
|
|
181
|
+
"type": "command",
|
|
182
|
+
"command": "osascript -e 'display notification \"Claude needs input\" with title \"Claude Code\"'"
|
|
183
|
+
}
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Block destructive git commands**:
|
|
192
|
+
```json
|
|
193
|
+
{
|
|
194
|
+
"hooks": {
|
|
195
|
+
"PreToolUse": [
|
|
196
|
+
{
|
|
197
|
+
"matcher": "Bash",
|
|
198
|
+
"hooks": [
|
|
199
|
+
{
|
|
200
|
+
"type": "prompt",
|
|
201
|
+
"prompt": "Check if this command is destructive: $ARGUMENTS\n\nBlock if it contains: 'git push --force', 'rm -rf', 'git reset --hard'\n\nReturn: {\"decision\": \"approve\" or \"block\", \"reason\": \"explanation\"}"
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Auto-format code after edits**:
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"hooks": {
|
|
214
|
+
"PostToolUse": [
|
|
215
|
+
{
|
|
216
|
+
"matcher": "Write|Edit",
|
|
217
|
+
"hooks": [
|
|
218
|
+
{
|
|
219
|
+
"type": "command",
|
|
220
|
+
"command": "prettier --write $CLAUDE_PROJECT_DIR",
|
|
221
|
+
"timeout": 10000
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
**Add context at session start**:
|
|
231
|
+
```json
|
|
232
|
+
{
|
|
233
|
+
"hooks": {
|
|
234
|
+
"SessionStart": [
|
|
235
|
+
{
|
|
236
|
+
"hooks": [
|
|
237
|
+
{
|
|
238
|
+
"type": "command",
|
|
239
|
+
"command": "echo '{\"hookSpecificOutput\": {\"hookEventName\": \"SessionStart\", \"additionalContext\": \"Current sprint: Sprint 23. Focus: User authentication\"}}'"
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
</common_patterns>
|
|
248
|
+
|
|
249
|
+
<debugging>
|
|
250
|
+
Always test hooks with the debug flag:
|
|
251
|
+
```bash
|
|
252
|
+
claude --debug
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
This shows which hooks matched, command execution, and output. See [references/troubleshooting.md](references/troubleshooting.md) for common issues and solutions.
|
|
256
|
+
</debugging>
|
|
257
|
+
|
|
258
|
+
<reference_guides>
|
|
259
|
+
**Hook types and events**: [references/hook-types.md](references/hook-types.md)
|
|
260
|
+
- Complete list of hook events
|
|
261
|
+
- When each event fires
|
|
262
|
+
- Input/output schemas for each
|
|
263
|
+
- Blocking vs non-blocking hooks
|
|
264
|
+
|
|
265
|
+
**Command vs Prompt hooks**: [references/command-vs-prompt.md](references/command-vs-prompt.md)
|
|
266
|
+
- Decision tree: which type to use
|
|
267
|
+
- Command hook patterns and examples
|
|
268
|
+
- Prompt hook patterns and examples
|
|
269
|
+
- Performance considerations
|
|
270
|
+
|
|
271
|
+
**Matchers and patterns**: [references/matchers.md](references/matchers.md)
|
|
272
|
+
- Regex patterns for tool matching
|
|
273
|
+
- MCP tool matching patterns
|
|
274
|
+
- Multiple tool matching
|
|
275
|
+
- Debugging matcher issues
|
|
276
|
+
|
|
277
|
+
**Input/Output schemas**: [references/input-output-schemas.md](references/input-output-schemas.md)
|
|
278
|
+
- Complete schema for each hook type
|
|
279
|
+
- Field descriptions and types
|
|
280
|
+
- Hook-specific output fields
|
|
281
|
+
- Example JSON for each event
|
|
282
|
+
|
|
283
|
+
**Working examples**: [references/examples.md](references/examples.md)
|
|
284
|
+
- Desktop notifications
|
|
285
|
+
- Command validation
|
|
286
|
+
- Auto-formatting workflows
|
|
287
|
+
- Logging and audit trails
|
|
288
|
+
- Stop logic patterns
|
|
289
|
+
- Session context injection
|
|
290
|
+
|
|
291
|
+
**Troubleshooting**: [references/troubleshooting.md](references/troubleshooting.md)
|
|
292
|
+
- Hooks not triggering
|
|
293
|
+
- Command execution failures
|
|
294
|
+
- Prompt hook issues
|
|
295
|
+
- Permission problems
|
|
296
|
+
- Timeout handling
|
|
297
|
+
- Debug workflow
|
|
298
|
+
</reference_guides>
|
|
299
|
+
|
|
300
|
+
<security_checklist>
|
|
301
|
+
**Critical safety requirements**:
|
|
302
|
+
|
|
303
|
+
- **Infinite loop prevention**: Check `stop_hook_active` flag in Stop hooks to prevent recursive triggering
|
|
304
|
+
- **Timeout configuration**: Set reasonable timeouts (default: 60s) to prevent hanging
|
|
305
|
+
- **Permission validation**: Ensure hook scripts have executable permissions (`chmod +x`)
|
|
306
|
+
- **Path safety**: Use absolute paths with `$CLAUDE_PROJECT_DIR` to avoid path injection
|
|
307
|
+
- **JSON validation**: Validate hook config with `jq` before use to catch syntax errors
|
|
308
|
+
- **Selective blocking**: Be conservative with blocking hooks to avoid workflow disruption
|
|
309
|
+
|
|
310
|
+
**Testing protocol**:
|
|
311
|
+
```bash
|
|
312
|
+
# Always test with debug flag first
|
|
313
|
+
claude --debug
|
|
314
|
+
|
|
315
|
+
# Validate JSON config
|
|
316
|
+
jq . .claude/hooks.json
|
|
317
|
+
```
|
|
318
|
+
</security_checklist>
|
|
319
|
+
|
|
320
|
+
<success_criteria>
|
|
321
|
+
A working hook configuration has:
|
|
322
|
+
|
|
323
|
+
- Valid JSON in `.claude/hooks.json` (validated with `jq`)
|
|
324
|
+
- Appropriate hook event selected for the use case
|
|
325
|
+
- Correct matcher pattern that matches target tools
|
|
326
|
+
- Command or prompt that executes without errors
|
|
327
|
+
- Proper output schema (decision/reason for blocking hooks)
|
|
328
|
+
- Tested with `--debug` flag showing expected behavior
|
|
329
|
+
- No infinite loops in Stop hooks (checks `stop_hook_active` flag)
|
|
330
|
+
- Reasonable timeout set (especially for external commands)
|
|
331
|
+
- Executable permissions on script files if using file paths
|
|
332
|
+
</success_criteria>
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# Command vs Prompt Hooks
|
|
2
|
+
|
|
3
|
+
Decision guide for choosing between command-based and prompt-based hooks.
|
|
4
|
+
|
|
5
|
+
## Decision Tree
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Need to execute a hook?
|
|
9
|
+
│
|
|
10
|
+
├─ Simple yes/no validation?
|
|
11
|
+
│ └─ Use COMMAND (faster, cheaper)
|
|
12
|
+
│
|
|
13
|
+
├─ Need natural language understanding?
|
|
14
|
+
│ └─ Use PROMPT (LLM evaluation)
|
|
15
|
+
│
|
|
16
|
+
├─ External tool interaction?
|
|
17
|
+
│ └─ Use COMMAND (formatters, linters, git)
|
|
18
|
+
│
|
|
19
|
+
├─ Complex decision logic?
|
|
20
|
+
│ └─ Use PROMPT (reasoning required)
|
|
21
|
+
│
|
|
22
|
+
└─ Logging/notification only?
|
|
23
|
+
└─ Use COMMAND (no decision needed)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Command Hooks
|
|
29
|
+
|
|
30
|
+
### Characteristics
|
|
31
|
+
|
|
32
|
+
- **Execution**: Shell command
|
|
33
|
+
- **Input**: JSON via stdin
|
|
34
|
+
- **Output**: JSON via stdout (optional)
|
|
35
|
+
- **Speed**: Fast (no LLM call)
|
|
36
|
+
- **Cost**: Free (no API usage)
|
|
37
|
+
- **Complexity**: Limited to shell scripting logic
|
|
38
|
+
|
|
39
|
+
### When to use
|
|
40
|
+
|
|
41
|
+
✅ **Use command hooks for**:
|
|
42
|
+
- File operations (read, write, check existence)
|
|
43
|
+
- Running tools (prettier, eslint, git)
|
|
44
|
+
- Simple pattern matching (grep, regex)
|
|
45
|
+
- Logging to files
|
|
46
|
+
- Desktop notifications
|
|
47
|
+
- Fast validation (file size, permissions)
|
|
48
|
+
|
|
49
|
+
❌ **Don't use command hooks for**:
|
|
50
|
+
- Natural language analysis
|
|
51
|
+
- Complex decision logic
|
|
52
|
+
- Context-aware validation
|
|
53
|
+
- Semantic understanding
|
|
54
|
+
|
|
55
|
+
### Examples
|
|
56
|
+
|
|
57
|
+
**1. Log bash commands**
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"type": "command",
|
|
61
|
+
"command": "jq -r '\"\\(.tool_input.command) - \\(.tool_input.description // \\\"No description\\\")\"' >> ~/.claude/bash-log.txt"
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**2. Block if file doesn't exist**
|
|
66
|
+
```bash
|
|
67
|
+
#!/bin/bash
|
|
68
|
+
# check-file-exists.sh
|
|
69
|
+
|
|
70
|
+
input=$(cat)
|
|
71
|
+
file=$(echo "$input" | jq -r '.tool_input.file_path')
|
|
72
|
+
|
|
73
|
+
if [ ! -f "$file" ]; then
|
|
74
|
+
echo '{"decision": "block", "reason": "File does not exist"}'
|
|
75
|
+
exit 0
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
echo '{"decision": "approve", "reason": "File exists"}'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**3. Run prettier after edits**
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"type": "command",
|
|
85
|
+
"command": "prettier --write \"$(echo {} | jq -r '.tool_input.file_path')\"",
|
|
86
|
+
"timeout": 10000
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**4. Desktop notification**
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"type": "command",
|
|
94
|
+
"command": "osascript -e 'display notification \"Claude needs input\" with title \"Claude Code\"'"
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Parsing input in commands
|
|
99
|
+
|
|
100
|
+
Command hooks receive JSON via stdin. Use `jq` to parse:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
#!/bin/bash
|
|
104
|
+
input=$(cat) # Read stdin
|
|
105
|
+
|
|
106
|
+
# Extract fields
|
|
107
|
+
tool_name=$(echo "$input" | jq -r '.tool_name')
|
|
108
|
+
command=$(echo "$input" | jq -r '.tool_input.command')
|
|
109
|
+
session_id=$(echo "$input" | jq -r '.session_id')
|
|
110
|
+
|
|
111
|
+
# Your logic here
|
|
112
|
+
if [[ "$command" == *"rm -rf"* ]]; then
|
|
113
|
+
echo '{"decision": "block", "reason": "Dangerous command"}'
|
|
114
|
+
else
|
|
115
|
+
echo '{"decision": "approve", "reason": "Safe"}'
|
|
116
|
+
fi
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Prompt Hooks
|
|
122
|
+
|
|
123
|
+
### Characteristics
|
|
124
|
+
|
|
125
|
+
- **Execution**: LLM evaluates prompt
|
|
126
|
+
- **Input**: Prompt string with `$ARGUMENTS` placeholder
|
|
127
|
+
- **Output**: LLM generates JSON response
|
|
128
|
+
- **Speed**: Slower (~1-3s per evaluation)
|
|
129
|
+
- **Cost**: Uses API credits
|
|
130
|
+
- **Complexity**: Can reason, understand context, analyze semantics
|
|
131
|
+
|
|
132
|
+
### When to use
|
|
133
|
+
|
|
134
|
+
✅ **Use prompt hooks for**:
|
|
135
|
+
- Natural language validation
|
|
136
|
+
- Semantic analysis (intent, safety, appropriateness)
|
|
137
|
+
- Complex decision trees
|
|
138
|
+
- Context-aware checks
|
|
139
|
+
- Reasoning about code quality
|
|
140
|
+
- Understanding user intent
|
|
141
|
+
|
|
142
|
+
❌ **Don't use prompt hooks for**:
|
|
143
|
+
- Simple pattern matching (use regex/grep)
|
|
144
|
+
- File operations (use command hooks)
|
|
145
|
+
- High-frequency events (too slow/expensive)
|
|
146
|
+
- Non-decision tasks (logging, notifications)
|
|
147
|
+
|
|
148
|
+
### Examples
|
|
149
|
+
|
|
150
|
+
**1. Validate commit messages**
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"type": "prompt",
|
|
154
|
+
"prompt": "Evaluate this git commit message: $ARGUMENTS\n\nCheck if it:\n1. Starts with conventional commit type (feat|fix|docs|refactor|test|chore)\n2. Is descriptive and clear\n3. Under 72 characters\n\nReturn: {\"decision\": \"approve\" or \"block\", \"reason\": \"specific feedback\"}"
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**2. Check if Stop is appropriate**
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"type": "prompt",
|
|
162
|
+
"prompt": "Review the conversation transcript: $ARGUMENTS\n\nDetermine if Claude should stop:\n1. All user tasks completed?\n2. Any errors that need fixing?\n3. Tests passing?\n4. Documentation updated?\n\nIf incomplete: {\"decision\": \"block\", \"reason\": \"what's missing\"}\nIf complete: {\"decision\": \"approve\", \"reason\": \"all done\"}"
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**3. Validate code changes for security**
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"type": "prompt",
|
|
170
|
+
"prompt": "Analyze this code change for security issues: $ARGUMENTS\n\nCheck for:\n- SQL injection vulnerabilities\n- XSS attack vectors\n- Authentication bypasses\n- Sensitive data exposure\n\nIf issues found: {\"decision\": \"block\", \"reason\": \"specific vulnerabilities\"}\nIf safe: {\"decision\": \"approve\", \"reason\": \"no issues found\"}"
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**4. Semantic prompt validation**
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"type": "prompt",
|
|
178
|
+
"prompt": "Evaluate user prompt: $ARGUMENTS\n\nIs this:\n1. Related to coding/development?\n2. Appropriate and professional?\n3. Clear and actionable?\n\nIf inappropriate: {\"decision\": \"block\", \"reason\": \"why\"}\nIf good: {\"decision\": \"approve\", \"reason\": \"ok\"}"
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Writing effective prompts
|
|
183
|
+
|
|
184
|
+
**Be specific about output format**:
|
|
185
|
+
```
|
|
186
|
+
Return JSON: {"decision": "approve" or "block", "reason": "explanation"}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Provide clear criteria**:
|
|
190
|
+
```
|
|
191
|
+
Block if:
|
|
192
|
+
1. Command contains 'rm -rf /'
|
|
193
|
+
2. Force push to main branch
|
|
194
|
+
3. Credentials in plain text
|
|
195
|
+
|
|
196
|
+
Otherwise approve.
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Use $ARGUMENTS placeholder**:
|
|
200
|
+
```
|
|
201
|
+
Analyze this input: $ARGUMENTS
|
|
202
|
+
|
|
203
|
+
Check for...
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The `$ARGUMENTS` placeholder is replaced with the actual hook input JSON.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Performance Comparison
|
|
211
|
+
|
|
212
|
+
| Aspect | Command Hook | Prompt Hook |
|
|
213
|
+
|--------|--------------|-------------|
|
|
214
|
+
| **Speed** | <100ms | 1-3s |
|
|
215
|
+
| **Cost** | Free | ~$0.001-0.01 per call |
|
|
216
|
+
| **Complexity** | Shell scripting | Natural language |
|
|
217
|
+
| **Context awareness** | Limited | High |
|
|
218
|
+
| **Reasoning** | No | Yes |
|
|
219
|
+
| **Best for** | Operations, logging | Validation, analysis |
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Combining Both
|
|
224
|
+
|
|
225
|
+
You can use multiple hooks for the same event:
|
|
226
|
+
|
|
227
|
+
```json
|
|
228
|
+
{
|
|
229
|
+
"hooks": {
|
|
230
|
+
"PreToolUse": [
|
|
231
|
+
{
|
|
232
|
+
"matcher": "Bash",
|
|
233
|
+
"hooks": [
|
|
234
|
+
{
|
|
235
|
+
"type": "command",
|
|
236
|
+
"command": "echo \"$input\" >> ~/bash-log.txt",
|
|
237
|
+
"comment": "Log every command (fast)"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
"type": "prompt",
|
|
241
|
+
"prompt": "Analyze this bash command for safety: $ARGUMENTS",
|
|
242
|
+
"comment": "Validate with LLM (slower, smarter)"
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Hooks execute in order. If any hook blocks, execution stops.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Recommendations
|
|
256
|
+
|
|
257
|
+
**High-frequency events** (PreToolUse, PostToolUse):
|
|
258
|
+
- Prefer command hooks
|
|
259
|
+
- Use prompt hooks sparingly
|
|
260
|
+
- Cache LLM decisions when possible
|
|
261
|
+
|
|
262
|
+
**Low-frequency events** (Stop, UserPromptSubmit):
|
|
263
|
+
- Prompt hooks are fine
|
|
264
|
+
- Cost/latency less critical
|
|
265
|
+
|
|
266
|
+
**Balance**:
|
|
267
|
+
- Command hooks for simple checks
|
|
268
|
+
- Prompt hooks for complex validation
|
|
269
|
+
- Combine when appropriate
|