Back to Skills

register-hook

verified

Create and register hook scripts with proper error handling and settings

View on GitHub

Marketplace

claude-code-cat

cowwoc/claude-code-cat

Plugin

cat

Repository

cowwoc/claude-code-cat
11stars

plugin/skills/register-hook/SKILL.md

Last Verified

January 21, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/cowwoc/claude-code-cat/blob/main/plugin/skills/register-hook/SKILL.md -a claude-code --skill register-hook

Installation paths:

Claude
.claude/skills/register-hook/
Powered by add-skill CLI

Instructions

# Register Hook Skill

**Purpose**: Create hook scripts with mandatory error handling patterns and register them in settings.json with proper matcher syntax.

**Performance**: Ensures hooks work correctly, prevents registration errors, enforces restart requirement

## When to Use This Skill

### ✅ Use register-hook When:

- Creating new hook script from scratch
- Need to register hook in settings.json
- Want to ensure proper error handling pattern
- Setting up hook with specific trigger event

### ❌ Do NOT Use When:

- Modifying existing hook (use Edit tool)
- Hook already registered (verify first)
- Testing hook behavior (use manual execution)

## What This Skill Does

### 1. Creates Hook Script

```bash
# Creates script with mandatory pattern:
#!/bin/bash
set -euo pipefail

# Error handler - output helpful message to stderr on failure
trap 'echo "ERROR in <script-name>.sh at line $LINENO: Command failed: $BASH_COMMAND" >&2; exit 1' ERR

# Hook logic...
```

### 2. Sets Permissions

```bash
chmod +x ~/.claude/hooks/{hook-name}.sh
```

### 3. Registers in settings.json

```json
{
  "hooks": {
    "{TriggerEvent}": [
      {
        "matcher": "{tool-pattern}",
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/{hook-name}.sh"
          }
        ]
      }
    ]
  }
}
```

### 4. Warns About Restart

```markdown
⚠️ Please restart Claude Code for hook changes to take effect
```

### 5. Provides Test Instructions

```markdown
After restart, test hook with:
[specific command to trigger hook]
```

## Trigger Events

### Available Events

**SessionStart**: Runs when session starts or resumes after compaction
```json
"SessionStart": [
  {
    "hooks": [{"type": "command", "command": "~/.claude/hooks/my-hook.sh"}]
  }
]
```

**UserPromptSubmit**: Runs when user submits a prompt
```json
"UserPromptSubmit": [
  {
    "hooks": [{"type": "command", "command": "~/.claude/hooks/my-hook.sh"}]
  }
]
```

**PreToolUse**: Runs before

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
9199 chars