claude-code-hooks

Automate Claude Code hook execution with bash or TypeScript scripts.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/hgeldenhuys/claude-hooks-sdk --skill claude-code-hooks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: claude-code-hooks
Source: https://github.com/hgeldenhuys/claude-hooks-sdk/tree/main/.claude-plugin/plugins/skill-claude-code-hooks
Command: npx skills add https://github.com/hgeldenhuys/claude-hooks-sdk --skill claude-code-hooks

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides comprehensive guidance for implementing automated scripts that execute at specific points in Claude Code's workflow. It solves the problem of needing custom logic, validation, or context injection that isn't natively supported, enabling you to automate repetitive tasks and enforce consistent behavior without manual intervention.

Core Features & Use Cases

  • Event-Driven Automation: Learn to trigger scripts at 9 key Claude Code events, such as PreToolUse (before a tool runs) or UserPromptSubmit (before Claude processes your input).
  • Custom Logic & Validation: Implement security checks to block dangerous commands, enforce coding standards, or dynamically inject session information into Claude's context.
  • Use Case: Automatically format code after Claude writes or edits a file, ensuring all generated code adheres to your project's style guidelines without you lifting a finger.

Quick Start

Ask me how to implement a PostToolUse hook to automatically format TypeScript files after Claude writes them.

Frequently Asked Questions about claude-code-hooks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I automate scripts at specific points in Claude Code's workflow?

Event-driven automation in Claude Code uses bash or TypeScript scripts that execute at nine key events—PreToolUse, PostToolUse, Notification, UserPromptSubmit, Stop, SubagentStop, PreCompact, SessionStart, and SessionEnd. Scripts receive stdin JSON input and output JSON with fields like continue, stopReason, or suppressOutput to control Claude's behavior.

Can I block dangerous commands or enforce validation rules automatically?

Yes. Implement a PreToolUse hook to inspect and block commands before execution, or use exit code 2 to signal blocking errors. This enables security checks, coding standard enforcement, and custom validation without manual intervention.

How do I format code automatically after Claude writes files?

Use a PostToolUse hook to detect file-write events and apply formatting. The hook receives tool execution details via stdin and can trigger style checks or reformatting based on your project's guidelines before returning control to Claude.

What input and output formats do Claude Code hooks expect?

Hooks receive stdin as JSON containing event context and details. They output JSON with hook-specific fields (continue, stopReason, suppressOutput, decision, hookSpecificOutput). Exit code 0 signals success; code 2 indicates blocking errors.

Do I need the claude-hooks-sdk to write TypeScript hooks?

The claude-hooks-sdk is recommended for TypeScript integration to streamline JSON parsing and event handling, but you can write hooks directly as bash or TypeScript scripts that follow the stdin/stdout JSON contract.

When should I use SessionStart versus UserPromptSubmit hooks?

SessionStart runs once at Claude Code startup for initialization or context injection; UserPromptSubmit runs before Claude processes each user input. Choose SessionStart for one-time setup and UserPromptSubmit for per-prompt validation or formatting.