claude-code-hooks

Run custom Bash hook scripts for Claude Code tool events.

29|6|Updated Nov 27, 2025
One-click install
npx skills add https://github.com/0xDarkMatter/claude-mods --skill claude-code-hooks-0xdarkmatter
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: claude-code-hooks
Source: https://github.com/0xDarkMatter/claude-mods/tree/main/skills/claude-code-hooks
Command: npx skills add https://github.com/0xDarkMatter/claude-mods --skill claude-code-hooks-0xdarkmatter

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill enables pre/post tool execution hooks, letting you validate inputs, audit usage, or enforce policies around tool calls.

Core Features & Use Cases

  • PreToolUse hooks for input validation and permission gating
  • PostToolUse hooks for auditing and metrics
  • Matcher patterns to selectively apply hooks per tool
  • Security best practices and timeout handling for hooks

Quick Start

Configure a PreToolUse hook to run a validator script before any Bash tool execution.

Frequently Asked Questions about claude-code-hooks

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

FAQPage Schema
How do I validate tool inputs before Claude Code executes them?

PreToolUse hooks run custom Bash scripts that validate inputs before tool execution. Exit code 0 allows the tool to proceed, while exit code 2 blocks execution. You define matcher patterns to apply hooks selectively per tool, receiving JSON input via stdin with full context about the tool call.

Can I automatically block unsafe operations in Claude Code workflows?

Yes. PreToolUse hooks enforce permission workflows by inspecting tool calls and blocking them with exit code 2 if they violate your policies. Hooks receive environment variables with project, session, and tool context, letting you make informed block/allow decisions before execution.

What's the best way to audit tool usage and track what Claude Code executes?

PostToolUse hooks run after tool execution completes, enabling audit logging and metrics collection. They receive tool results via JSON stdin and can emit notifications or write audit records. This approach captures what executed, when, and with what outcome without blocking workflows.

How do I set up hooks that only apply to specific tools?

Matcher-based event selection lets you target hooks to particular tools by name. Configure PreToolUse or PostToolUse hooks with matcher patterns so they run only for relevant tools like Bash or file operations, reducing noise and overhead.

Do hook scripts timeout, and how should I handle long-running validations?

Hooks support timeout handling to prevent validators from stalling Claude Code workflows. Define appropriate timeouts for your Bash hook scripts; timeouts are treated as non-blocking failures, allowing execution to proceed while you log the issue.

Can I send notifications when specific tool operations occur?

PostToolUse hooks enable notification emission by running scripts that detect tool patterns and trigger alerts. Combined with environment variables providing context, hooks can route notifications to logging systems, chat platforms, or monitoring tools after operations complete.