hook-development

Create and validate event-driven hooks for Claude Code plugin automation.

Updated Oct 7, 2022
One-click install
npx skills add https://github.com/tamagusko/linux-cfg --skill hook-development-tamagusko
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hook-development
Source: https://github.com/tamagusko/linux-cfg/tree/main/dotfiles/claude/skills/hook-development
Command: npx skills add https://github.com/tamagusko/linux-cfg --skill hook-development-tamagusko

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Building Claude Code hooks requires knowing the correct hooks.json schema, event types, output formats, and security practices, and mistakes silently break workflows or create injection vulnerabilities. ## Core Features & Use Cases - Hook Implementation Guidance: Covers all hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification) with both prompt-based and command hook patterns. - Validation and Testing Tooling: Ships scripts to validate hooks.json schema, test hook scripts with sample JSON input, and lint hook scripts for quoting, exit codes, and hardcoded paths. - Use Case: When adding a PreToolUse hook that blocks dangerous bash commands in a plugin, use this Skill to write the hooks.json entry, lint the validation script, and test it with sample tool input before restarting Claude Code. ## Quick Start Create a PreToolUse prompt-based hook that validates Write operations for path traversal and sensitive files, then validate my hooks.json configuration.

Frequently Asked Questions about hook-development

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

FAQPage Schema
How do I create a PreToolUse hook in Claude Code?

Add a PreToolUse entry in your plugin's hooks/hooks.json with a matcher for the tool name and a hooks array containing either a command hook running a bash script or a prompt hook with natural language validation criteria. Use ${CLAUDE_PLUGIN_ROOT} for script paths.

What is the difference between prompt hooks and command hooks?

Prompt hooks use LLM reasoning for context-aware validation on Stop, SubagentStop, UserPromptSubmit, and PreToolUse events. Command hooks execute bash scripts for fast deterministic checks, file operations, and external tool integration.

Why are my hook changes not taking effect in Claude Code?

Hooks load only at session start, so editing hooks.json or hook scripts does not affect the current session. Exit Claude Code and restart it, then verify loaded hooks with the /hooks command or claude --debug.

How do I test a hook script before deploying it?

Pipe sample JSON input matching the event structure into the script via stdin and check the exit code and output. The included test-hook.sh script generates sample inputs, sets environment variables, and validates JSON output.

What exit codes should a Claude Code hook return?

Exit code 0 means success with stdout shown in the transcript, exit code 2 means a blocking error with stderr fed back to Claude, and any other code is treated as a non-blocking error.