Hooks Directory

February 9, 2026 ยท View on GitHub

Event-driven automation hooks that trigger on Claude Code lifecycle events to enforce quality, security, and workflow standards.

What are Hooks?

Hooks are automation scripts that execute in response to Claude Code events. They enable:

  • Pre-tool validation (prevent unsafe operations)
  • Post-tool verification (auto-format, auto-test)
  • Session lifecycle management (context loading, cleanup)
  • Notification integration (Slack, Discord, email)

Hook Events

EventWhen It FiresUse Cases
PreToolUseBefore a tool executesBlock dangerous commands, validate file paths
PostToolUseAfter a tool completesAuto-format code, run linters, update indexes
SessionStartWhen session beginsLoad context, check prerequisites

Hook Format

Each hook is a markdown file with YAML frontmatter:

---
name: hook-name
description: When and why this hook fires
event: PreToolUse  # Hook event type
tools: ["Bash", "Write"]  # Tools this hook monitors (for PreToolUse/PostToolUse)
---

Hook instructions and logic here.

Available Hooks

Security Hooks

HookEventDescription
secrets-scannerPreToolUsePrevents committing files containing secrets/credentials
file-protectionPreToolUseBlocks modifications to protected files (.env, credentials)
dependency-auditPostToolUseScans new dependencies for known vulnerabilities

Quality Hooks

HookEventDescription
auto-formatPostToolUseRuns formatter after code edits (Prettier, Black, gofmt)
lint-on-savePostToolUseRuns linter after file writes
test-on-changePostToolUseRuns related tests after code changes

Git Hooks

HookEventDescription
commit-message-validatorPreToolUseEnforces conventional commit format
branch-protectionPreToolUsePrevents direct commits to main/master
pr-templatePreToolUseEnriches PR creation with consistent template and test plan

Workflow Hooks

HookEventDescription
session-contextSessionStartLoads project context and recent changes

Installation

Hooks are installed to .claude/hooks/ (project) or ~/.claude/hooks/ (global):

# Install specific hook
cp hooks/secrets-scanner.md ~/.claude/hooks/

# Install all hooks
for hook in hooks/*.md; do
  cp "$hook" ~/.claude/hooks/
done

Creating New Hooks

  1. Create markdown file in hooks/ directory
  2. Add YAML frontmatter with name, description, event, and tools
  3. Write hook logic in the body
  4. Test with sample scenarios
  5. Document in this README

Hook Precedence

Project hooks (.claude/hooks/) override global hooks (~/.claude/hooks/) with the same name.