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.
Files changed (160) hide show
  1. package/.claude/agents/code-simplifier.md +52 -0
  2. package/.claude/agents/curator.md +189 -245
  3. package/.claude/agents/documentor.md +147 -0
  4. package/.claude/agents/planner.md +123 -166
  5. package/.claude/agents/researcher.md +58 -41
  6. package/.claude/agents/surveyor.md +81 -0
  7. package/.claude/agents/worker.md +74 -0
  8. package/.claude/commands/audit-docs.md +94 -0
  9. package/.claude/commands/continue.md +120 -0
  10. package/.claude/commands/create-docs.md +100 -0
  11. package/.claude/commands/create-skill.md +107 -0
  12. package/.claude/commands/create-specialist.md +111 -0
  13. package/.claude/commands/curator-audit.md +4 -0
  14. package/.claude/commands/debug.md +183 -0
  15. package/.claude/commands/plan.md +199 -102
  16. package/.claude/commands/validate.md +11 -0
  17. package/.claude/commands/whats-next.md +106 -134
  18. package/.claude/envoy/envoy +11 -14
  19. package/.claude/envoy/package-lock.json +1388 -0
  20. package/.claude/envoy/package.json +29 -0
  21. package/.claude/envoy/src/cli.ts +126 -0
  22. package/.claude/envoy/src/commands/base.ts +216 -0
  23. package/.claude/envoy/src/commands/gemini.ts +999 -0
  24. package/.claude/envoy/src/commands/git.ts +639 -0
  25. package/.claude/envoy/src/commands/index.ts +73 -0
  26. package/.claude/envoy/src/commands/knowledge.ts +187 -0
  27. package/.claude/envoy/src/commands/perplexity.ts +129 -0
  28. package/.claude/envoy/src/commands/plan/core.ts +134 -0
  29. package/.claude/envoy/src/commands/plan/findings.ts +446 -0
  30. package/.claude/envoy/src/commands/plan/gates.ts +672 -0
  31. package/.claude/envoy/src/commands/plan/index.ts +135 -0
  32. package/.claude/envoy/src/commands/plan/lifecycle.ts +648 -0
  33. package/.claude/envoy/src/commands/plan/plan-file.ts +138 -0
  34. package/.claude/envoy/src/commands/plan/prompts.ts +285 -0
  35. package/.claude/envoy/src/commands/plan/protocols.ts +166 -0
  36. package/.claude/envoy/src/commands/repomix.ts +99 -0
  37. package/.claude/envoy/src/commands/tavily.ts +220 -0
  38. package/.claude/envoy/src/commands/xai.ts +168 -0
  39. package/.claude/envoy/src/lib/design.ts +41 -0
  40. package/.claude/envoy/src/lib/feedback-schemas.ts +154 -0
  41. package/.claude/envoy/src/lib/findings.ts +215 -0
  42. package/.claude/envoy/src/lib/gates.ts +572 -0
  43. package/.claude/envoy/src/lib/git.ts +132 -0
  44. package/.claude/envoy/src/lib/index.ts +188 -0
  45. package/.claude/envoy/src/lib/knowledge.ts +594 -0
  46. package/.claude/envoy/src/lib/markdown.ts +75 -0
  47. package/.claude/envoy/src/lib/observability.ts +262 -0
  48. package/.claude/envoy/src/lib/paths.ts +130 -0
  49. package/.claude/envoy/src/lib/plan-io.ts +117 -0
  50. package/.claude/envoy/src/lib/prompts.ts +231 -0
  51. package/.claude/envoy/src/lib/protocols.ts +314 -0
  52. package/.claude/envoy/src/lib/repomix.ts +133 -0
  53. package/.claude/envoy/src/lib/retry.ts +138 -0
  54. package/.claude/envoy/src/lib/watcher.ts +167 -0
  55. package/.claude/envoy/tsconfig.json +21 -0
  56. package/.claude/hooks/scripts/scan_agents.py +62 -0
  57. package/.claude/hooks/scripts/scan_commands.py +50 -0
  58. package/.claude/hooks/scripts/scan_skills.py +46 -70
  59. package/.claude/hooks/scripts/validate_artifacts.py +128 -0
  60. package/.claude/hooks/startup.sh +26 -24
  61. package/.claude/protocols/bug-discovery.yaml +55 -0
  62. package/.claude/protocols/debugging.yaml +51 -0
  63. package/.claude/protocols/discovery.yaml +53 -0
  64. package/.claude/protocols/implementation.yaml +84 -0
  65. package/.claude/settings.json +37 -97
  66. package/.claude/skills/brainstorming/SKILL.md +54 -0
  67. package/.claude/skills/commands-development/SKILL.md +630 -0
  68. package/.claude/skills/commands-development/references/arguments.md +252 -0
  69. package/.claude/skills/commands-development/references/patterns.md +796 -0
  70. package/.claude/skills/commands-development/references/tool-restrictions.md +376 -0
  71. package/.claude/skills/discovery-mode/SKILL.md +108 -0
  72. package/.claude/skills/hooks-development/SKILL.md +332 -0
  73. package/.claude/skills/hooks-development/references/command-vs-prompt.md +269 -0
  74. package/.claude/skills/hooks-development/references/examples.md +658 -0
  75. package/.claude/skills/hooks-development/references/hook-types.md +463 -0
  76. package/.claude/skills/hooks-development/references/input-output-schemas.md +469 -0
  77. package/.claude/skills/hooks-development/references/matchers.md +470 -0
  78. package/.claude/skills/hooks-development/references/troubleshooting.md +587 -0
  79. package/.claude/skills/implementation-mode/SKILL.md +171 -0
  80. package/.claude/skills/research-tools/SKILL.md +35 -33
  81. package/.claude/skills/skills-development/SKILL.md +192 -0
  82. package/.claude/skills/skills-development/references/api-security.md +226 -0
  83. package/.claude/skills/skills-development/references/be-clear-and-direct.md +531 -0
  84. package/.claude/skills/skills-development/references/common-patterns.md +595 -0
  85. package/.claude/skills/skills-development/references/core-principles.md +437 -0
  86. package/.claude/skills/skills-development/references/executable-code.md +175 -0
  87. package/.claude/skills/skills-development/references/iteration-and-testing.md +474 -0
  88. package/.claude/skills/skills-development/references/recommended-structure.md +168 -0
  89. package/.claude/skills/skills-development/references/skill-structure.md +372 -0
  90. package/.claude/skills/skills-development/references/use-xml-tags.md +466 -0
  91. package/.claude/skills/skills-development/references/using-scripts.md +113 -0
  92. package/.claude/skills/skills-development/references/using-templates.md +112 -0
  93. package/.claude/skills/skills-development/references/workflows-and-validation.md +510 -0
  94. package/.claude/skills/skills-development/templates/router-skill.md +73 -0
  95. package/.claude/skills/skills-development/templates/simple-skill.md +33 -0
  96. package/.claude/skills/skills-development/workflows/add-reference.md +96 -0
  97. package/.claude/skills/skills-development/workflows/add-script.md +93 -0
  98. package/.claude/skills/skills-development/workflows/add-template.md +74 -0
  99. package/.claude/skills/skills-development/workflows/add-workflow.md +120 -0
  100. package/.claude/skills/skills-development/workflows/audit-skill.md +138 -0
  101. package/.claude/skills/skills-development/workflows/create-domain-expertise-skill.md +605 -0
  102. package/.claude/skills/skills-development/workflows/create-new-skill.md +191 -0
  103. package/.claude/skills/skills-development/workflows/get-guidance.md +121 -0
  104. package/.claude/skills/skills-development/workflows/upgrade-to-router.md +161 -0
  105. package/.claude/skills/skills-development/workflows/verify-skill.md +204 -0
  106. package/.claude/skills/subagents-development/SKILL.md +325 -0
  107. package/.claude/skills/subagents-development/references/context-management.md +567 -0
  108. package/.claude/skills/subagents-development/references/debugging-agents.md +714 -0
  109. package/.claude/skills/subagents-development/references/error-handling-and-recovery.md +502 -0
  110. package/.claude/skills/subagents-development/references/evaluation-and-testing.md +374 -0
  111. package/.claude/skills/subagents-development/references/orchestration-patterns.md +591 -0
  112. package/.claude/skills/subagents-development/references/subagents.md +508 -0
  113. package/.claude/skills/subagents-development/references/writing-subagent-prompts.md +517 -0
  114. package/.claude/statusline.sh +24 -0
  115. package/bin/cli.js +110 -72
  116. package/package.json +1 -1
  117. package/.claude/agents/explorer.md +0 -62
  118. package/.claude/agents/parallel-worker.md +0 -121
  119. package/.claude/commands/curation-fix.md +0 -92
  120. package/.claude/commands/new-branch.md +0 -36
  121. package/.claude/commands/parallel-discovery.md +0 -69
  122. package/.claude/commands/parallel-orchestration.md +0 -99
  123. package/.claude/commands/plan-checkpoint.md +0 -37
  124. package/.claude/envoy/commands/__init__.py +0 -1
  125. package/.claude/envoy/commands/base.py +0 -95
  126. package/.claude/envoy/commands/parallel.py +0 -439
  127. package/.claude/envoy/commands/perplexity.py +0 -86
  128. package/.claude/envoy/commands/plans.py +0 -451
  129. package/.claude/envoy/commands/tavily.py +0 -156
  130. package/.claude/envoy/commands/vertex.py +0 -358
  131. package/.claude/envoy/commands/xai.py +0 -124
  132. package/.claude/envoy/envoy.py +0 -122
  133. package/.claude/envoy/pyrightconfig.json +0 -4
  134. package/.claude/envoy/requirements.txt +0 -2
  135. package/.claude/hooks/capture-queries.sh +0 -3
  136. package/.claude/hooks/scripts/enforce_planning.py +0 -118
  137. package/.claude/hooks/scripts/enforce_rg.py +0 -34
  138. package/.claude/hooks/scripts/validate_skill.py +0 -81
  139. package/.claude/skills/claude-envoy-curation/SKILL.md +0 -162
  140. package/.claude/skills/claude-envoy-usage/SKILL.md +0 -46
  141. package/.claude/skills/command-development/SKILL.md +0 -206
  142. package/.claude/skills/command-development/examples/simple-commands.md +0 -212
  143. package/.claude/skills/command-development/references/frontmatter-reference.md +0 -221
  144. package/.claude/skills/hook-development/SKILL.md +0 -127
  145. package/.claude/skills/hook-development/examples/command-hooks.md +0 -301
  146. package/.claude/skills/hook-development/examples/prompt-hooks.md +0 -114
  147. package/.claude/skills/hook-development/references/event-reference.md +0 -226
  148. package/.claude/skills/repomix-extraction/SKILL.md +0 -91
  149. package/.claude/skills/skill-development/SKILL.md +0 -168
  150. package/.claude/skills/skill-development/examples/complete-skill-examples.md +0 -281
  151. package/.claude/skills/skill-development/references/progressive-disclosure.md +0 -141
  152. package/.claude/skills/skill-development/references/writing-style.md +0 -180
  153. package/.claude/skills/skill-development/scripts/validate-skill.sh +0 -144
  154. package/.claude/skills/specialist-builder/SKILL.md +0 -327
  155. package/.claude/skills/specialist-builder/docs/agent-catalog.md +0 -28
  156. package/.claude/skills/specialist-builder/examples/complete-agent-examples.md +0 -206
  157. package/.claude/skills/specialist-builder/references/system-prompt-patterns.md +0 -281
  158. package/.claude/skills/specialist-builder/references/triggering-examples.md +0 -162
  159. package/.claude/skills/specialist-builder/scripts/validate-agent.sh +0 -137
  160. /package/.claude/{envoy/claude-envoy.py → skills/claude-envoy-patterns/SKILL.md} +0 -0
@@ -0,0 +1,658 @@
1
+ # Working Examples
2
+
3
+ Real-world hook configurations ready to use.
4
+
5
+ ## Desktop Notifications
6
+
7
+ ### macOS notification when input needed
8
+ ```json
9
+ {
10
+ "hooks": {
11
+ "Notification": [
12
+ {
13
+ "hooks": [
14
+ {
15
+ "type": "command",
16
+ "command": "osascript -e 'display notification \"Claude needs your input\" with title \"Claude Code\" sound name \"Glass\"'"
17
+ }
18
+ ]
19
+ }
20
+ ]
21
+ }
22
+ }
23
+ ```
24
+
25
+ ### Linux notification (notify-send)
26
+ ```json
27
+ {
28
+ "hooks": {
29
+ "Notification": [
30
+ {
31
+ "hooks": [
32
+ {
33
+ "type": "command",
34
+ "command": "notify-send 'Claude Code' 'Awaiting your input' --urgency=normal"
35
+ }
36
+ ]
37
+ }
38
+ ]
39
+ }
40
+ }
41
+ ```
42
+
43
+ ### Play sound on notification
44
+ ```json
45
+ {
46
+ "hooks": {
47
+ "Notification": [
48
+ {
49
+ "hooks": [
50
+ {
51
+ "type": "command",
52
+ "command": "afplay /System/Library/Sounds/Glass.aiff"
53
+ }
54
+ ]
55
+ }
56
+ ]
57
+ }
58
+ }
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Logging
64
+
65
+ ### Log all bash commands
66
+ ```json
67
+ {
68
+ "hooks": {
69
+ "PreToolUse": [
70
+ {
71
+ "matcher": "Bash",
72
+ "hooks": [
73
+ {
74
+ "type": "command",
75
+ "command": "jq -r '\"[\" + (.timestamp // now | todate) + \"] \" + .tool_input.command + \" - \" + (.tool_input.description // \"No description\")' >> ~/.claude/bash-log.txt"
76
+ }
77
+ ]
78
+ }
79
+ ]
80
+ }
81
+ }
82
+ ```
83
+
84
+ ### Log file operations
85
+ ```json
86
+ {
87
+ "hooks": {
88
+ "PostToolUse": [
89
+ {
90
+ "matcher": "Write|Edit",
91
+ "hooks": [
92
+ {
93
+ "type": "command",
94
+ "command": "jq -r '\"[\" + (now | todate) + \"] \" + .tool_name + \": \" + .tool_input.file_path' >> ~/.claude/file-operations.log"
95
+ }
96
+ ]
97
+ }
98
+ ]
99
+ }
100
+ }
101
+ ```
102
+
103
+ ### Audit trail for MCP operations
104
+ ```json
105
+ {
106
+ "hooks": {
107
+ "PreToolUse": [
108
+ {
109
+ "matcher": "mcp__.*",
110
+ "hooks": [
111
+ {
112
+ "type": "command",
113
+ "command": "jq '. + {timestamp: now}' >> ~/.claude/mcp-audit.jsonl"
114
+ }
115
+ ]
116
+ }
117
+ ]
118
+ }
119
+ }
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Code Quality
125
+
126
+ ### Auto-format after edits
127
+ ```json
128
+ {
129
+ "hooks": {
130
+ "PostToolUse": [
131
+ {
132
+ "matcher": "Write|Edit",
133
+ "hooks": [
134
+ {
135
+ "type": "command",
136
+ "command": "prettier --write \"$(echo {} | jq -r '.tool_input.file_path')\" 2>/dev/null || true",
137
+ "timeout": 10000
138
+ }
139
+ ]
140
+ }
141
+ ]
142
+ }
143
+ }
144
+ ```
145
+
146
+ ### Run linter after code changes
147
+ ```json
148
+ {
149
+ "hooks": {
150
+ "PostToolUse": [
151
+ {
152
+ "matcher": "Write|Edit",
153
+ "hooks": [
154
+ {
155
+ "type": "command",
156
+ "command": "eslint \"$(echo {} | jq -r '.tool_input.file_path')\" --fix 2>/dev/null || true"
157
+ }
158
+ ]
159
+ }
160
+ ]
161
+ }
162
+ }
163
+ ```
164
+
165
+ ### Run tests before stopping
166
+ ```json
167
+ {
168
+ "hooks": {
169
+ "Stop": [
170
+ {
171
+ "hooks": [
172
+ {
173
+ "type": "command",
174
+ "command": "/path/to/check-tests.sh"
175
+ }
176
+ ]
177
+ }
178
+ ]
179
+ }
180
+ }
181
+ ```
182
+
183
+ `check-tests.sh`:
184
+ ```bash
185
+ #!/bin/bash
186
+ cd "$cwd" || exit 1
187
+
188
+ # Run tests
189
+ npm test > /dev/null 2>&1
190
+
191
+ if [ $? -eq 0 ]; then
192
+ echo '{"decision": "approve", "reason": "All tests passing"}'
193
+ else
194
+ echo '{"decision": "block", "reason": "Tests are failing. Please fix before stopping.", "systemMessage": "Run npm test to see failures"}'
195
+ fi
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Safety and Validation
201
+
202
+ ### Block destructive commands
203
+ ```json
204
+ {
205
+ "hooks": {
206
+ "PreToolUse": [
207
+ {
208
+ "matcher": "Bash",
209
+ "hooks": [
210
+ {
211
+ "type": "command",
212
+ "command": "/path/to/check-command-safety.sh"
213
+ }
214
+ ]
215
+ }
216
+ ]
217
+ }
218
+ }
219
+ ```
220
+
221
+ `check-command-safety.sh`:
222
+ ```bash
223
+ #!/bin/bash
224
+ input=$(cat)
225
+ command=$(echo "$input" | jq -r '.tool_input.command')
226
+
227
+ # Check for dangerous patterns
228
+ if [[ "$command" == *"rm -rf /"* ]] || \
229
+ [[ "$command" == *"mkfs"* ]] || \
230
+ [[ "$command" == *"> /dev/sda"* ]]; then
231
+ echo '{"decision": "block", "reason": "Destructive command detected", "systemMessage": "This command could cause data loss"}'
232
+ exit 0
233
+ fi
234
+
235
+ # Check for force push to main
236
+ if [[ "$command" == *"git push"*"--force"* ]] && \
237
+ [[ "$command" == *"main"* || "$command" == *"master"* ]]; then
238
+ echo '{"decision": "block", "reason": "Force push to main branch blocked", "systemMessage": "Use a feature branch instead"}'
239
+ exit 0
240
+ fi
241
+
242
+ echo '{"decision": "approve", "reason": "Command is safe"}'
243
+ ```
244
+
245
+ ### Validate commit messages
246
+ ```json
247
+ {
248
+ "hooks": {
249
+ "PreToolUse": [
250
+ {
251
+ "matcher": "Bash",
252
+ "hooks": [
253
+ {
254
+ "type": "prompt",
255
+ "prompt": "Check if this is a git commit command: $ARGUMENTS\n\nIf it's a git commit, validate the message follows conventional commits format (feat|fix|docs|refactor|test|chore): description\n\nIf invalid format: {\"decision\": \"block\", \"reason\": \"Commit message must follow conventional commits\"}\nIf valid or not a commit: {\"decision\": \"approve\", \"reason\": \"ok\"}"
256
+ }
257
+ ]
258
+ }
259
+ ]
260
+ }
261
+ }
262
+ ```
263
+
264
+ ### Block writes to critical files
265
+ ```json
266
+ {
267
+ "hooks": {
268
+ "PreToolUse": [
269
+ {
270
+ "matcher": "Write|Edit",
271
+ "hooks": [
272
+ {
273
+ "type": "command",
274
+ "command": "/path/to/check-protected-files.sh"
275
+ }
276
+ ]
277
+ }
278
+ ]
279
+ }
280
+ }
281
+ ```
282
+
283
+ `check-protected-files.sh`:
284
+ ```bash
285
+ #!/bin/bash
286
+ input=$(cat)
287
+ file_path=$(echo "$input" | jq -r '.tool_input.file_path')
288
+
289
+ # Protected files
290
+ protected_files=(
291
+ "package-lock.json"
292
+ ".env.production"
293
+ "credentials.json"
294
+ )
295
+
296
+ for protected in "${protected_files[@]}"; do
297
+ if [[ "$file_path" == *"$protected"* ]]; then
298
+ echo "{\"decision\": \"block\", \"reason\": \"Cannot modify $protected\", \"systemMessage\": \"This file is protected from automated changes\"}"
299
+ exit 0
300
+ fi
301
+ done
302
+
303
+ echo '{"decision": "approve", "reason": "File is not protected"}'
304
+ ```
305
+
306
+ ---
307
+
308
+ ## Context Injection
309
+
310
+ ### Load sprint context at session start
311
+ ```json
312
+ {
313
+ "hooks": {
314
+ "SessionStart": [
315
+ {
316
+ "hooks": [
317
+ {
318
+ "type": "command",
319
+ "command": "/path/to/load-sprint-context.sh"
320
+ }
321
+ ]
322
+ }
323
+ ]
324
+ }
325
+ }
326
+ ```
327
+
328
+ `load-sprint-context.sh`:
329
+ ```bash
330
+ #!/bin/bash
331
+
332
+ # Read sprint info from file
333
+ sprint_info=$(cat "$CLAUDE_PROJECT_DIR/.sprint-context.txt" 2>/dev/null || echo "No sprint context available")
334
+
335
+ # Return as SessionStart context
336
+ jq -n \
337
+ --arg context "$sprint_info" \
338
+ '{
339
+ "hookSpecificOutput": {
340
+ "hookEventName": "SessionStart",
341
+ "additionalContext": $context
342
+ }
343
+ }'
344
+ ```
345
+
346
+ ### Load git branch context
347
+ ```json
348
+ {
349
+ "hooks": {
350
+ "SessionStart": [
351
+ {
352
+ "hooks": [
353
+ {
354
+ "type": "command",
355
+ "command": "cd \"$cwd\" && git branch --show-current | jq -Rs '{\"hookSpecificOutput\": {\"hookEventName\": \"SessionStart\", \"additionalContext\": (\"Current branch: \" + .)}}'"
356
+ }
357
+ ]
358
+ }
359
+ ]
360
+ }
361
+ }
362
+ ```
363
+
364
+ ### Load environment info
365
+ ```json
366
+ {
367
+ "hooks": {
368
+ "SessionStart": [
369
+ {
370
+ "hooks": [
371
+ {
372
+ "type": "command",
373
+ "command": "echo '{\"hookSpecificOutput\": {\"hookEventName\": \"SessionStart\", \"additionalContext\": \"Environment: '$(hostname)'\\nNode version: '$(node --version 2>/dev/null || echo 'not installed')'\\nPython version: '$(python3 --version 2>/dev/null || echo 'not installed)'\"}}'"
374
+ }
375
+ ]
376
+ }
377
+ ]
378
+ }
379
+ }
380
+ ```
381
+
382
+ ---
383
+
384
+ ## Workflow Automation
385
+
386
+ ### Auto-commit after major changes
387
+ ```json
388
+ {
389
+ "hooks": {
390
+ "PostToolUse": [
391
+ {
392
+ "matcher": "Write|Edit",
393
+ "hooks": [
394
+ {
395
+ "type": "command",
396
+ "command": "/path/to/auto-commit.sh"
397
+ }
398
+ ]
399
+ }
400
+ ]
401
+ }
402
+ }
403
+ ```
404
+
405
+ `auto-commit.sh`:
406
+ ```bash
407
+ #!/bin/bash
408
+ cd "$cwd" || exit 1
409
+
410
+ # Check if there are changes
411
+ if ! git diff --quiet; then
412
+ git add -A
413
+ git commit -m "chore: auto-commit from claude session" --no-verify
414
+ echo '{"systemMessage": "Changes auto-committed"}'
415
+ fi
416
+ ```
417
+
418
+ ### Update documentation after code changes
419
+ ```json
420
+ {
421
+ "hooks": {
422
+ "PostToolUse": [
423
+ {
424
+ "matcher": "Write|Edit",
425
+ "hooks": [
426
+ {
427
+ "type": "command",
428
+ "command": "/path/to/update-docs.sh",
429
+ "timeout": 30000
430
+ }
431
+ ]
432
+ }
433
+ ]
434
+ }
435
+ }
436
+ ```
437
+
438
+ ### Run pre-commit hooks
439
+ ```json
440
+ {
441
+ "hooks": {
442
+ "PreToolUse": [
443
+ {
444
+ "matcher": "Bash",
445
+ "hooks": [
446
+ {
447
+ "type": "command",
448
+ "command": "/path/to/check-pre-commit.sh"
449
+ }
450
+ ]
451
+ }
452
+ ]
453
+ }
454
+ }
455
+ ```
456
+
457
+ `check-pre-commit.sh`:
458
+ ```bash
459
+ #!/bin/bash
460
+ input=$(cat)
461
+ command=$(echo "$input" | jq -r '.tool_input.command')
462
+
463
+ # If git commit, run pre-commit hooks first
464
+ if [[ "$command" == *"git commit"* ]]; then
465
+ pre-commit run --all-files > /dev/null 2>&1
466
+
467
+ if [ $? -ne 0 ]; then
468
+ echo '{"decision": "block", "reason": "Pre-commit hooks failed", "systemMessage": "Fix formatting/linting issues first"}'
469
+ exit 0
470
+ fi
471
+ fi
472
+
473
+ echo '{"decision": "approve", "reason": "ok"}'
474
+ ```
475
+
476
+ ---
477
+
478
+ ## Session Management
479
+
480
+ ### Archive transcript on session end
481
+ ```json
482
+ {
483
+ "hooks": {
484
+ "SessionEnd": [
485
+ {
486
+ "hooks": [
487
+ {
488
+ "type": "command",
489
+ "command": "/path/to/archive-session.sh"
490
+ }
491
+ ]
492
+ }
493
+ ]
494
+ }
495
+ }
496
+ ```
497
+
498
+ `archive-session.sh`:
499
+ ```bash
500
+ #!/bin/bash
501
+ input=$(cat)
502
+ transcript_path=$(echo "$input" | jq -r '.transcript_path')
503
+ session_id=$(echo "$input" | jq -r '.session_id')
504
+
505
+ # Create archive directory
506
+ archive_dir="$HOME/.claude/archives"
507
+ mkdir -p "$archive_dir"
508
+
509
+ # Copy transcript with timestamp
510
+ timestamp=$(date +%Y%m%d-%H%M%S)
511
+ cp "$transcript_path" "$archive_dir/${timestamp}-${session_id}.jsonl"
512
+
513
+ echo "Session archived to $archive_dir"
514
+ ```
515
+
516
+ ### Save session stats
517
+ ```json
518
+ {
519
+ "hooks": {
520
+ "SessionEnd": [
521
+ {
522
+ "hooks": [
523
+ {
524
+ "type": "command",
525
+ "command": "jq '. + {ended_at: now}' >> ~/.claude/session-stats.jsonl"
526
+ }
527
+ ]
528
+ }
529
+ ]
530
+ }
531
+ }
532
+ ```
533
+
534
+ ---
535
+
536
+ ## Advanced Patterns
537
+
538
+ ### Intelligent stop logic
539
+ ```json
540
+ {
541
+ "hooks": {
542
+ "Stop": [
543
+ {
544
+ "hooks": [
545
+ {
546
+ "type": "prompt",
547
+ "prompt": "Review the conversation: $ARGUMENTS\n\nCheck if:\n1. All user-requested tasks are complete\n2. Tests are passing (if code changes made)\n3. No errors that need fixing\n4. Documentation updated (if applicable)\n\nIf incomplete: {\"decision\": \"block\", \"reason\": \"specific issue\", \"systemMessage\": \"what needs to be done\"}\n\nIf complete: {\"decision\": \"approve\", \"reason\": \"all tasks done\"}\n\nIMPORTANT: If stop_hook_active is true, return {\"decision\": undefined} to avoid infinite loop",
548
+ "timeout": 30000
549
+ }
550
+ ]
551
+ }
552
+ ]
553
+ }
554
+ }
555
+ ```
556
+
557
+ ### Chain multiple hooks
558
+ ```json
559
+ {
560
+ "hooks": {
561
+ "PreToolUse": [
562
+ {
563
+ "matcher": "Bash",
564
+ "hooks": [
565
+ {
566
+ "type": "command",
567
+ "command": "echo 'First hook' >> /tmp/hook-chain.log"
568
+ },
569
+ {
570
+ "type": "command",
571
+ "command": "echo 'Second hook' >> /tmp/hook-chain.log"
572
+ },
573
+ {
574
+ "type": "prompt",
575
+ "prompt": "Final validation: $ARGUMENTS"
576
+ }
577
+ ]
578
+ }
579
+ ]
580
+ }
581
+ }
582
+ ```
583
+
584
+ Hooks execute in order. First block stops the chain.
585
+
586
+ ### Conditional execution based on file type
587
+ ```json
588
+ {
589
+ "hooks": {
590
+ "PostToolUse": [
591
+ {
592
+ "matcher": "Write|Edit",
593
+ "hooks": [
594
+ {
595
+ "type": "command",
596
+ "command": "/path/to/format-by-type.sh"
597
+ }
598
+ ]
599
+ }
600
+ ]
601
+ }
602
+ }
603
+ ```
604
+
605
+ `format-by-type.sh`:
606
+ ```bash
607
+ #!/bin/bash
608
+ input=$(cat)
609
+ file_path=$(echo "$input" | jq -r '.tool_input.file_path')
610
+
611
+ case "$file_path" in
612
+ *.js|*.jsx|*.ts|*.tsx)
613
+ prettier --write "$file_path"
614
+ ;;
615
+ *.py)
616
+ black "$file_path"
617
+ ;;
618
+ *.go)
619
+ gofmt -w "$file_path"
620
+ ;;
621
+ esac
622
+ ```
623
+
624
+ ---
625
+
626
+ ## Project-Specific Hooks
627
+
628
+ Use `$CLAUDE_PROJECT_DIR` for project-specific hooks:
629
+
630
+ ```json
631
+ {
632
+ "hooks": {
633
+ "SessionStart": [
634
+ {
635
+ "hooks": [
636
+ {
637
+ "type": "command",
638
+ "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/init-session.sh"
639
+ }
640
+ ]
641
+ }
642
+ ],
643
+ "PostToolUse": [
644
+ {
645
+ "matcher": "Write|Edit",
646
+ "hooks": [
647
+ {
648
+ "type": "command",
649
+ "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/validate-changes.sh"
650
+ }
651
+ ]
652
+ }
653
+ ]
654
+ }
655
+ }
656
+ ```
657
+
658
+ This keeps hook scripts versioned with the project.