claude-code-hooks

July 19, 2026 ยท View on GitHub

๐Ÿช Ready-to-use hooks for Claude Code โ€” plus a 7-plugin installable marketplace: safety, automation, notifications, and more.

GitHub stars License: MIT CI Tests

๐ŸŒ Live site & catalog

๐ŸŽฌ 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.

๐Ÿ”Œ New: these hooks also install as one-command Claude Code plugins. Run /plugin marketplace add karanb192/claude-code-hooks, then /plugin install <name>@claude-code-hooks โ€” see Install as a plugin for the 7-plugin catalog.


๐Ÿ“‘ Table of Contents


๐Ÿช Hooks

Session Lifecycle

Runs at session boundaries โ€” inject context at SessionStart and capture outcomes at Stop / SessionEnd.

HookMatcherDescription
session-loggerSessionStart + PostToolUse + SessionEndWrites a durable markdown log of every session (cwd, git repo, files touched, bash commands). PostToolUse registers with "async": true so logging never blocks Claude; concurrent writes are serialized with a file lock. Bash commands get best-effort secret redaction. Drop-in for Obsidian vaults via CC_SESSION_LOG_DIR.

๐Ÿ”Œ bounty-board (repo TODO/FIXME/HACK debt priced as aging XP bounties) now ships as an installable plugin โ€” see Install as a plugin.

๐Ÿ”Œ nerf-receipts (personal model-quality flight recorder) and standup-autopilot (writes your daily standup from what your agents actually did; re-injects open blockers) now ship as installable plugins โ€” see Install as a plugin.

User-Prompt-Submit

Runs when the user submits a prompt, before Claude processes it. Can inject context or block the prompt.

๐Ÿ”Œ dead-end-registry (remembers approaches you tried and reverted, then warns before you retry them) now ships as an installable plugin โ€” see Install as a plugin.

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
git-safetyBashBranch-aware git guardrails + destructive gh CLI protection
protect-testsBash|Edit|MultiEdit|WriteStops "fake green": blocks deleting, renaming-away, or skip/xfail-disabling tests

Post-Tool-Use

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

HookMatcherDescription
auto-stageEdit|WriteAutomatically git stages files after Claude modifies them
format-codeWrite|EditAuto-formats Python (ruff) and JS/TS/HTML/JSON/MD/YAML (prettier) after edits

๐Ÿ”Œ context-hogs (per-file context-cost leaderboard) and pr-provenance-stamp (PR-body provenance receipt) now ship as installable plugins โ€” see Install as a plugin.

๐Ÿ”Œ dead-rules-audit (CLAUDE.md compliance scorecard) now ships as an installable plugin โ€” see Install as a plugin.

Notification

Fires when Claude needs user attention.

HookMatcherDescription
notify-permissionpermission_prompt|idle_prompt|elicitation_dialogSends 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.


๐Ÿ”Œ Install as a plugin

This repo is also a Claude Code plugin marketplace, so you can install a single hook โ€” no copying scripts, no editing settings.json by hand.

1. Add the marketplace (once):

/plugin marketplace add karanb192/claude-code-hooks

2. Install just the hook you want:

/plugin install context-hogs@claude-code-hooks

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

PluginWhat it doesCommand
context-hogsPer-file context-cost leaderboard โ€” attributes each tool result's tokens to the files it loaded, so you see which files cost you the most/context-hogs:leaderboard renders the board on demand
nerf-receiptsPersonal flight recorder โ€” records your own failure rate, edit churn & tokens/task by model version, and flags real shifts when a model changes/nerf-receipts:receipts renders the trend card on demand
dead-rules-auditCLAUDE.md compliance scorecard โ€” tallies which rules Claude follows vs ignores as you edit (SessionStart + PostToolUse + SessionEnd), and flags chronically-ignored rules to promote into a deterministic hook/dead-rules-audit:scorecard renders the scorecard on demand
pr-provenance-stampStamps a provenance receipt (prompts, est. spend, tests run, agent-authored lines) into your PR body when Claude runs gh pr create/pr-provenance-stamp:provenance renders the receipt on demand
standup-autopilotWrites your daily standup from what your agents actually did across repos โ€” captures tasks, tests, PRs, and blockers from session transcripts and re-injects yesterday's open blockers next session/standup-autopilot:standup renders today's card on demand
dead-end-registryRemembers approaches you tried and reverted (reason + estimated token cost) and warns before you retry them โ€” a prompt-submit card plus an ask-before-edit guard/dead-end-registry:dead-ends renders the registry on demand
bounty-boardPrices your repo's TODO/FIXME/HACK/skip debt as aging XP bounties, injects the top 3 as opportunistic side quests, and verifies + pays out bounties you genuinely clear/bounty-board:board renders the board on demand

โšก The PostToolUse recorders in these plugins run async โ€” they record in the background and add ~zero latency to a tool call. Each plugin renders on demand via its own command (e.g. /context-hogs:leaderboard) and at SessionEnd.

The hooks listed above under ๐Ÿช Hooks install the classic way (copy the script + add to settings.json); more are being packaged as plugins.


๐Ÿš€ 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'

๐Ÿ™‹ Ask mode (prompt instead of block)

block-dangerous-commands and protect-secrets can ask instead of denying outright. When ask mode is on for a level, matching operations return permissionDecision: "ask" โ€” Claude Code shows the reason and lets you approve or reject, instead of hard-blocking.

Enable per level via environment variables (the literal string true; anything else means deny):

VariableAffects
HOOK_ASK_CRITICALcritical-level patterns (rm -rf ~, .env, โ€ฆ)
HOOK_ASK_HIGHhigh-level patterns (git reset --hard, โ€ฆ)
HOOK_ASK_STRICTstrict-level patterns (any force push, โ€ฆ)

Set them inline in your hook command in settings.json:

{
  "type": "command",
  "command": "HOOK_ASK_STRICT=true node ~/.claude/hooks/block-dangerous-commands.js"
}

Everything defaults to deny โ€” ask mode is strictly opt-in. A common setup: keep critical on deny, set HOOK_ASK_STRICT=true so cautionary patterns prompt instead of blocking.


๐Ÿงช Testing

Requires Node โ‰ฅ 18 (no npm dependencies). The format-code tests exercise the real formatters, so have prettier, ruff, and uv on your PATH โ€” CI installs them โ€” or expect those few tests to fail. All hooks include comprehensive tests, run in CI on Node 18, 20, and 22:

# 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
context-snapshotPreCompactPreserve context before compaction
ntfy-notifyNotificationFree mobile push via ntfy.sh
discord-notifyNotificationDiscord webhook alerts
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

๐Ÿ‘ค Author

Built by Karan Bansal, Head of AI at ArmorCode. These hooks are the basis of my OWASP GenAI Summit talk, Hardening AI Coding Agents with Hooks (slides and recording there).

I write about Claude Code, MCP, and production agentic AI at karanbansal.in/blog.


๐Ÿ“„ License

MIT ยฉ karanb192