Hooks

by parcadeid07ff4b06b62No license3.9K starsListed Oct 8, 2026Updated Oct 8, 2026Repository updated 8 months ago

Hook Development Rules

Instructions onlyAI & Agents
AI-generated overview

Reference rules for building Claude Code hooks: shell wrappers, TypeScript handlers, events, testing and registration.

What it does
This skill provides development rules for files under .claude/hooks/. It documents a shell-wrapper-to-TypeScript pattern run through npx tsx, a TypeScript handler template that reads JSON from stdin and prints a JSON result, the available hook events, manual testing commands, and how to register hooks in .claude/settings.json. It produces guidance and code templates rather than runnable artifacts.
When to use it
Use it when creating or modifying Claude Code hooks in a project's .claude/hooks directory. It is also relevant when wiring hook events into .claude/settings.json or testing a hook from the command line.
Requirements
No scripts ship with the skill; it is instructions only. Following it assumes a Claude Code project with a .claude/hooks directory, Node.js with npx and the tsx package available, and a shell such as bash.

Hook Development Rules

When working with files in .claude/hooks/:

Pattern

Shell wrapper (.sh) → TypeScript (.ts) via npx tsx

Shell Wrapper Template

bash
#!/bin/bashset -ecd "$CLAUDE_PROJECT_DIR/.claude/hooks"cat | npx tsx <handler>.ts

TypeScript Handler Pattern

typescript
interface HookInput {  // Event-specific fields}
async function main() {  const input: HookInput = JSON.parse(await readStdin());
  // Process input
  const output = {    result: 'continue',  // or 'block'    message: 'Optional system reminder'  };
  console.log(JSON.stringify(output));}

Hook Events

  • PreToolUse - Before tool execution (can block)
  • PostToolUse - After tool execution
  • UserPromptSubmit - Before processing user prompt
  • PreCompact - Before context compaction
  • SessionStart - On session start/resume/compact
  • Stop - When agent finishes

Testing

Test hooks manually:

bash
echo '{"type": "resume"}' | .claude/hooks/session-start-continuity.sh

Registration

Add hooks to .claude/settings.json:

json
{  "hooks": {    "EventName": [{      "matcher": ["pattern"],  // Optional      "hooks": [{        "type": "command",        "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/hook.sh"      }]    }]  }}

Source and attribution

Source:parcadei/continuous-claude-v3in.claude/skills/hooksat commitd07ff4b

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal