All tools
HarnessCommunity1k

claude-code-hooks Collection

Updated Jul 7, 2026

A tested library of Claude Code hook scripts covering safety, automation, and notifications. Current hooks: block-dangerous-commands (blocks rm -rf ~, fork bombs, curl|sh), protect-secrets (prevents reading/exfiltrating .env and key files), git-safety (branch-aware git guardrails), auto-stage (git-adds files after edits), format-code (runs ruff/Prettier after writes), and notify-permission (Slack alerts).

View on GitHub

What it does

  • block-dangerous-commands (PreToolUse)

    Blocks catastrophic Bash commands — rm -rf ~, fork bombs, curl|sh pipes — before Claude executes them. Configurable safety level: critical, high, or strict.

  • protect-secrets (PreToolUse)

    Intercepts Read, Edit, Write, and Bash tool calls targeting .env files, private keys, and credential files to prevent accidental exfiltration.

  • git-safety (PreToolUse)

    Branch-aware git guardrails that block destructive git and gh CLI operations based on the current branch.

  • auto-stage (PostToolUse)

    Automatically runs git add on files Claude has written or edited, keeping the staging area in sync without manual intervention.

  • format-code (PostToolUse)

    Runs ruff on Python files and Prettier on JS/TS/JSON/YAML/Markdown automatically after every Write or Edit.

  • notify-permission (Notification)

    Sends a Slack webhook alert when Claude Code is idle waiting for permission or user input.

Files (1)

OVERVIEW.mdprimary · markdown · 2.0 KB
## What it does

claude-code-hooks is a collection of drop-in hook scripts for the Claude Code hook system (262 tests, MIT licensed). Each script handles one safety or automation concern and can be adopted independently by copying it to ~/.claude/hooks/ and wiring it in .claude/settings.json.

## Implemented hooks

PreToolUse:
- block-dangerous-commands — blocks catastrophic shell commands: rm -rf ~ and variants, fork bombs, curl|sh pipes, disk-wiping dd. Configurable safety levels: critical (catastrophic only), high (recommended, adds force push to main, secrets exposure), strict (maximum).
- protect-secrets — prevents reading, modifying, or exfiltrating sensitive files: .env, private keys, credential files.
- git-safety — branch-aware git guardrails plus protection against destructive gh CLI operations.

PostToolUse:
- auto-stage — automatically git stages files after Claude writes or edits them.
- format-code — auto-formats Python files with ruff and JS/TS/JSON/YAML/Markdown with Prettier after edits.

Notification:
- notify-permission — sends Slack webhook alerts when Claude Code is idle waiting for user input.

Utils:
- event-logger.py — logs all hook events to inspect payload structures; useful when building new hooks.

## Install

Copy a hook script to your hooks directory:
cp hook-scripts/pre-tool-use/block-dangerous-commands.js ~/.claude/hooks/

Add it to .claude/settings.json:
hooks > PreToolUse > matcher: Bash > hooks > type: command, command: node ~/.claude/hooks/block-dangerous-commands.js

Restart Claude Code.

## Configuring safety levels

Each safety hook exposes a SAFETY_LEVEL constant at the top of the file. Set to "critical", "high" (recommended), or "strict" to control how aggressively the hook blocks operations.

## When to use

Install block-dangerous-commands and protect-secrets on any project where Claude has Bash access — they are low-friction safety nets with zero false positives at the recommended "high" level. Combine with auto-stage to keep the working tree clean after Claude edits.