writing-hooks

Design and validate Claude Code hooks with event types and matcher patterns.

111|29|Updated Mar 25, 2026
One-click install
npx skills add https://github.com/xiaolai/nlpm-for-claude --skill writing-hooks-xiaolai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-hooks
Source: https://github.com/xiaolai/nlpm-for-claude/tree/main/skills/nlpm/writing-hooks
Command: npx skills add https://github.com/xiaolai/nlpm-for-claude --skill writing-hooks-xiaolai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps teams design, validate, and enforce Claude Code hooks to automate policy checks, improve consistency, and reduce manual configuration.

Core Features & Use Cases

  • Three hook types: command, prompt, and agent, with guidance on when to use each.
  • Event selection, matcher patterns, and portable path practices for reliable hook orchestration.
  • Blocking vs advisory behavior, fail-open vs fail-closed patterns, and script requirements.

Quick Start

Create a sample hooks.json that defines a PreToolUse command hook and verify its behavior.

Frequently Asked Questions about writing-hooks

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

FAQPage Schema
How do I design Claude Code hooks for policy enforcement?

Design Claude Code hooks by specifying event types, hook script structures, and matcher patterns to automate policy checks. Use a hooks.json file to define command, prompt, or agent hooks that enforce quality gates across Claude workflows reliably.

What is the difference between command, prompt, and agent hooks in Claude Code?

Command, prompt, and agent hooks serve distinct automation purposes in Claude Code. Command hooks execute scripts for policy checks, while prompt and agent hooks handle different workflow stages, guiding when to use each for reliable hook orchestration and quality gates.

How do I validate a PreToolUse command hook in a hooks.json file?

Validate a PreToolUse command hook by creating a sample hooks.json that defines the hook structure and matcher patterns, then verifying its behavior. Ensure scripts use the ${CLAUDE_PLUGIN_ROOT} path variable for portable and reliable execution across environments.

When should I use blocking versus advisory behavior for Claude Code hooks?

Use blocking behavior for Claude Code hooks when strict policy enforcement is required, and advisory behavior for non-critical warnings. Choose fail-open patterns to allow workflows to proceed on errors, or fail-closed patterns to halt execution when strict quality gates are necessary.

Do I need regex matchers to automate checks with Claude Code hooks?

Regex matchers are used in Claude Code hooks to target specific tool events for automation. By configuring matcher patterns in your hooks.json, you can precisely filter which tool calls trigger your command hook scripts for policy enforcement and quality validation.

Why should I use the CLAUDE_PLUGIN_ROOT variable in my hook scripts?

Use the ${CLAUDE_PLUGIN_ROOT} variable in hook scripts to ensure portable path practices for reliable hook orchestration. It specifies script locations consistently, allowing plugin authors to automate checks and enforce policies across different Claude workflow environments without path errors.