hooks

Automate Claude Code tool execution with lifecycle hooks and regex matchers.

5|1|Updated Oct 30, 2025
One-click install
npx skills add https://github.com/reggiechan74/claude-plugins --skill hooks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hooks
Source: https://github.com/reggiechan74/claude-plugins/tree/main/plugins/claude-code-metaskill/skills/hooks
Command: npx skills add https://github.com/reggiechan74/claude-plugins --skill hooks

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Repetitive tasks like code formatting, validation, or logging often require manual intervention or external scripting. This Skill enables automated execution of scripts at specific lifecycle events, streamlining your development workflow and reducing manual effort.

Core Features & Use Cases

  • Event-Driven Automation: Trigger scripts PreToolUse, PostToolUse, UserPromptSubmit, SessionStart, and more, for comprehensive workflow control.
  • Granular Control: Use matchers (including regex) to target specific tools or events, ensuring precise automation.
  • Decision Control: Allow, deny, or modify tool execution based on hook script output, providing powerful conditional logic.
  • Use Case: Configure a PostToolUse hook to automatically run prettier on any .ts file after Claude edits it, ensuring consistent code formatting across your project without any manual steps.

Quick Start

Show me how to create a hook that runs a script before any Bash command is executed.

Frequently Asked Questions about hooks

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

FAQPage Schema
How do I automate code formatting after Claude edits files?

Event-driven hooks let you trigger scripts automatically at lifecycle events like PostToolUse. Configure a PostToolUse hook to run prettier or similar formatters on edited files, ensuring consistent formatting without manual steps.

Can I validate or block tool execution based on conditions?

Yes. Hooks support decision control through regex-based matchers and script output. Use PreToolUse hooks to validate prompts, enforce policies, or deny execution based on custom logic before Claude runs any tool.

What lifecycle events can I hook into for automation?

Hooks support PreToolUse, PostToolUse, UserPromptSubmit, Notification, SessionStart, SessionEnd, and PreCompact events. This covers comprehensive workflow control from session initialization through tool execution and state management.

How do I maintain environment state across Claude Code sessions?

Hooks persist environment variables via CLAUDE_ENV_FILE, allowing you to store and retrieve state between sessions. SessionStart and SessionEnd hooks can initialize or save context for reliable downstream handling.

Can hooks run scripts in parallel or with timeouts?

Yes. Hooks support parallel execution and per-command timeouts, with standardized exit codes for reliable downstream handling. This enables complex automation workflows without blocking or hanging operations.

Do I need coding knowledge to set up event-driven automation?

Hooks use configurable inputs and outputs with regex-based matchers, making them accessible without deep scripting knowledge. You write standard scripts and configure when they trigger; the hook system handles orchestration.