claude-code-hooks

January 26, 2026 ยท View on GitHub

๐Ÿช Ready-to-use hooks for Claude Code โ€” safety, automation, notifications, and more.

GitHub stars License: MIT Tests

๐ŸŽฌ Quick Demo

Protecting Secrets Blocking Dangerous Commands
Hook blocking .env read Hook blocking dangerous commands

A growing collection of tested, documented hooks you can copy, paste, and customize.


๐Ÿ“‘ Table of Contents


๐Ÿช Hooks

Pre-Tool-Use

Runs before Claude executes a tool. Can block or modify the operation.

HookMatcherDescription
block-dangerous-commandsBashBlocks dangerous shell commands (rm -rf ~, fork bombs, curl|sh)
protect-secretsRead|Edit|Write|BashPrevents reading/modifying/exfiltrating sensitive files

Post-Tool-Use

Runs after Claude executes a tool. Can react to results.

HookMatcherDescription
auto-stageEdit|WriteAutomatically git stages files after Claude modifies them

Notification

Fires when Claude needs user attention.

HookMatcherDescription
notify-permissionpermission_prompt|idle_promptSends Slack alerts when Claude needs input

Utils

Tools to help you build and debug hooks.

ToolLanguageDescription
event-loggerPythonLogs all hook events to inspect payload structures

๐Ÿ’ก Building a new hook? Use event-logger.py to discover what data Claude Code provides for each event before writing your own hooks.


๐Ÿš€ Quick Start

1. Copy the hook script:

mkdir -p ~/.claude/hooks
cp hook-scripts/pre-tool-use/block-dangerous-commands.js ~/.claude/hooks/

2. Add to .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "node ~/.claude/hooks/block-dangerous-commands.js"
          }
        ]
      }
    ]
  }
}

3. Restart Claude Code โ€” the hook is now active.

๐Ÿ’ก Tip: Use multiple hooks together. Combine block-dangerous-commands + protect-secrets for comprehensive safety.


๐Ÿ›ก๏ธ Safety Levels

Security hooks support configurable safety levels:

LevelWhat's BlockedUse Case
criticalCatastrophic only (rm -rf ~, fork bombs, dd to disk)Maximum flexibility
high+ Risky (force push main, secrets exposure, git reset --hard)Recommended
strict+ Cautionary (any force push, sudo rm, docker prune)Maximum safety

To change: Edit the SAFETY_LEVEL constant at the top of each hook.

const SAFETY_LEVEL = 'strict'; // or 'critical', 'high'

๐Ÿงช Testing

All hooks include comprehensive tests:

# Run all tests
npm test

# Run specific hook tests
node --test hook-scripts/tests/pre-tool-use/block-dangerous-commands.test.js

Test coverage:

  • โœ… Unit tests for core functions
  • โœ… Integration tests for stdin/stdout flow
  • โœ… Config validation tests

๐Ÿ“– Configuration Reference

See the official Claude Code hooks documentation for:

  • All hook events and their lifecycles
  • Input/output JSON formats
  • Matcher patterns
  • Environment variables

๐Ÿค Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

Ideas for new hooks:

HookEventDescription
protect-testsPreToolUseBlock test deletion/disabling
auto-formatPostToolUseRun prettier/black/gofmt after edits
branch-guardPreToolUseBlock changes on main/master branch
context-snapshotPreCompactPreserve context before compaction
session-summaryStopGenerate summary on session end
ntfy-notifyNotificationFree mobile push via ntfy.sh
discord-notifyNotificationDiscord webhook alerts
cost-trackerPostToolUseTrack token usage and estimate costs
tts-alertsNotificationVoice notifications via say/espeak
rules-injectorUserPromptSubmitAuto-inject CLAUDE.md rules
rate-limiterPreToolUseLimit tool calls per minute
context-injectorSessionStartInject project context on session start

๐Ÿ“„ License

MIT ยฉ karanb192