$npx -y skills add parcadei/Continuous-Claude-v3 --skill hooksHook Development Rules
| 1 | # Hook Development Rules |
| 2 | |
| 3 | When working with files in `.claude/hooks/`: |
| 4 | |
| 5 | ## Pattern |
| 6 | Shell wrapper (.sh) → TypeScript (.ts) via `npx tsx` |
| 7 | |
| 8 | ## Shell Wrapper Template |
| 9 | ```bash |
| 10 | #!/bin/bash |
| 11 | set -e |
| 12 | cd "$CLAUDE_PROJECT_DIR/.claude/hooks" |
| 13 | cat | npx tsx <handler>.ts |
| 14 | ``` |
| 15 | |
| 16 | ## TypeScript Handler Pattern |
| 17 | ```typescript |
| 18 | interface HookInput { |
| 19 | // Event-specific fields |
| 20 | } |
| 21 | |
| 22 | async function main() { |
| 23 | const input: HookInput = JSON.parse(await readStdin()); |
| 24 | |
| 25 | // Process input |
| 26 | |
| 27 | const output = { |
| 28 | result: 'continue', // or 'block' |
| 29 | message: 'Optional system reminder' |
| 30 | }; |
| 31 | |
| 32 | console.log(JSON.stringify(output)); |
| 33 | } |
| 34 | ``` |
| 35 | |
| 36 | ## Hook Events |
| 37 | - **PreToolUse** - Before tool execution (can block) |
| 38 | - **PostToolUse** - After tool execution |
| 39 | - **UserPromptSubmit** - Before processing user prompt |
| 40 | - **PreCompact** - Before context compaction |
| 41 | - **SessionStart** - On session start/resume/compact |
| 42 | - **Stop** - When agent finishes |
| 43 | |
| 44 | ## Testing |
| 45 | Test hooks manually: |
| 46 | ```bash |
| 47 | echo '{"type": "resume"}' | .claude/hooks/session-start-continuity.sh |
| 48 | ``` |
| 49 | |
| 50 | ## Registration |
| 51 | Add hooks to `.claude/settings.json`: |
| 52 | ```json |
| 53 | { |
| 54 | "hooks": { |
| 55 | "EventName": [{ |
| 56 | "matcher": ["pattern"], // Optional |
| 57 | "hooks": [{ |
| 58 | "type": "command", |
| 59 | "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/hook.sh" |
| 60 | }] |
| 61 | }] |
| 62 | } |
| 63 | } |
| 64 | ``` |