Hook Development

Create Claude Code plugin hooks that validate tool execution across workflow events.

Updated Mar 27, 2026
One-click install
npx skills add https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI --skill hook-development-quanngynx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Hook Development
Source: https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI/tree/main/servexa-warranty-ai/.cursor/skills/hook-development
Command: npx skills add https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI --skill hook-development-quanngynx

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires jq, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps you create and implement Claude Code plugin hooks that safely validate and control tool usage across important workflow events, reducing errors and preventing unsafe operations.

Core Features & Use Cases

  • Prompt-based hook design: Create context-aware validations that can approve, deny, ask, or block tool actions based on event inputs.
  • Command hook guidance: Implement deterministic checks (e.g., schema validation, filesystem checks) using portable paths via ${CLAUDE_PLUGIN_ROOT}.
  • Correct configuration & output contracts: Use the right hooks.json vs settings.json formats, and produce the expected structured JSON responses and exit-code behavior.
  • Lifecycle coverage: Apply hooks to events like PreToolUse, PostToolUse, Stop, SessionStart, PreCompact, Notification, and more.
  • Testing and hardening workflow: Use the provided utility scripts (schema validation, hook testing, and linting) to reduce deployment risk.

Core Features & Use Cases

Use case example: You want to prevent dangerous file writes and require completion checks before stopping—use PreToolUse to validate Write/Edit operations, and use Stop to verify tests/build steps from the transcript.

Quick Start

Ask your AI assistant to “create a PreToolUse prompt-based hook that validates Write|Edit tool calls for path traversal and secret-file writes, then provide the exact hooks.json configuration format and the required hook output JSON contract.”

Frequently Asked Questions about Hook Development

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

FAQPage Schema
How do I create Claude Code hooks for PreToolUse and PostToolUse events?

To create Claude Code hooks, you configure event-aware settings in hooks.json or .claude/settings.json to validate and control tool execution. You can implement prompt-based validations or deterministic command checks using portable environment variables like ${CLAUDE_PLUGIN_ROOT} for safe, event-driven automation.

What is the difference between hooks.json and .claude/settings.json for plugin hooks?

The difference between hooks.json and .claude/settings.json lies in their deployment scope for plugin hooks. hooks.json is used for plugin-specific configurations, while .claude/settings.json manages broader project-level event-driven automation and policy enforcement settings.

How do I prevent unsafe file writes using Claude Code tool gating?

You prevent unsafe file writes by implementing a PreToolUse prompt-based hook to validate Write and Edit tool calls for path traversal and secret-file access. This tool gating approach blocks dangerous operations before execution by returning the correct structured JSON output.

Can I use jq for command hook validation in Claude Code?

Yes, you can use jq for command hook validation in Claude Code. It enables deterministic checks by parsing JSON event inputs and applying schema validation, which supports filesystem checks and policy enforcement through portable paths via ${CLAUDE_PLUGIN_ROOT}.

How do I validate completion checks before stopping a Claude Code agent workflow?

You validate completion checks by applying a Stop hook to verify tests and build steps from the transcript. This event-driven automation ensures all required completion verification steps pass before the agent workflow is allowed to terminate.

What are the limitations of prompt-based hooks compared to command hooks in Claude Code?

Prompt-based hooks provide context-aware validations but lack the deterministic reliability of command hooks. Command hooks execute strict schema validation and filesystem checks using portable paths, whereas prompt-based approaches rely on the model interpreting event inputs to approve, deny, or block tool actions.