mcpField
H
hooks

hooks

github.com/parcadeiDevelopment3.9k509 installsUpdated 39w ago
Repository

About hooks

A Claude Code skill describing a shell-to-TypeScript pattern, hook events, registration, and manual testing. It helps developers implement hooks in `.claude/hooks/`.

Key features

  1. 01Shell wrappers invoking TypeScript via `npx tsx`
  2. 02Hook event overview
  3. 03Registration through `.claude/settings.json`
  4. 04Manual hook testing

Use cases

  1. 01Creating a shell and TypeScript hook
  2. 02Registering a hook for an event
  3. 03Manually testing a session-start hook

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/parcadei/continuous-claude-v3 --skill hooks

After installing, type/hooksin Claude Code to confirm it loaded.

Details

From the project README

Hook Development Rules

When working with files in .claude/hooks/:

Pattern

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

Shell Wrapper Template

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

TypeScript Handler Pattern

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:

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

Registration

Add hooks to .claude/settings.json:

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

Comments

Markdown supported