π unclaimed β this page was auto-generated from GitHub. Are you the creator?
Claim this page β
claude-code-hooks
πͺ A growing collection of useful Claude Code hooks. Copy, paste, customize.
git clone https://github.com/karanb192/claude-code-hooks
claude-code-hooks
πͺ Ready-to-use hooks for Claude Code β safety, automation, notifications, and more.
π¬ Quick Demo
| Protecting Secrets | 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.
| Hook | Matcher | Description |
|---|---|---|
| block-dangerous-commands | Bash | Blocks dangerous shell commands (rm -rf ~, fork bombs, curl|sh) |
| protect-secrets | Read|Edit|Write|Bash | Prevents reading/modifying/exfiltrating sensitive files |
Post-Tool-Use
Runs after Claude executes a tool. Can react to results.
| Hook | Matcher | Description |
|---|---|---|
| auto-stage | Edit|Write | Automatically git stages files after Claude modifies them |
Notification
Fires when Claude needs user attention.
| Hook | Matcher | Description |
|---|---|---|
| notify-permission | permission_prompt|idle_prompt | Sends Slack alerts when Claude needs input |
Utils
Tools to help you build and debug hooks.
| Tool | Language | Description |
|---|---|---|
| event-logger | Python | Logs all hook events to inspect payload structures |
π‘ Building a new hook? Use
event-logger.pyto 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-secretsfor comprehensive safety.
π‘οΈ Safety Levels
Security hooks support configurable safety levels:
| Level | What's Blocked | Use Case |
|---|---|---|
critical | Catastrophic 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:
| Hook | Event | Description |
|---|---|---|
protect-tests | PreToolUse | Block test deletion/disabling |
auto-format | PostToolUse | Run prettier/black/gofmt after edits |
branch-guard | PreToolUse | Block changes on main/master branch |
context-snapshot | PreCompact | Preserve context before compaction |
session-summary | Stop | Generate summary on session end |
ntfy-notify | Notification | Free mobile push via ntfy.sh |
discord-notify | Notification | Discord webhook alerts |
cost-tracker | PostToolUse | Track token usage and estimate costs |
tts-alerts | Notification | Voice notifications via say/espeak |
rules-injector | UserPromptSubmit | Auto-inject CLAUDE.md rules |
rate-limiter | PreToolUse | Limit tool calls per minute |
context-injector | SessionStart | Inject project context on session start |
π License
MIT Β© karanb192
// compatibility
| Platforms | cli, api, web, mobile |
|---|---|
| Operating systems | β |
| AI compatibility | claude |
| License | MIT |
| Pricing | open-source |
| Language | JavaScript |
// faq
What is claude-code-hooks?
πͺ A growing collection of useful Claude Code hooks. Copy, paste, customize.. It is open-source on GitHub.
Is claude-code-hooks free to use?
claude-code-hooks is open-source under the MIT license, so it is free to use.
What category does claude-code-hooks belong to?
claude-code-hooks is listed under devtools in the Claudeers registry of Claude-compatible tools.
// embed badge
[](https://claudeers.com/claude-code-hooks-2)
// retro hit counter
[](https://claudeers.com/claude-code-hooks-2)
// reviews
// guestbook
// related in Developer Tools
The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursβ¦
Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
AI coding assistant skill (Claude Code, Codex, OpenCode, Cursor, Gemini CLI, and more). Turn any folder of code, SQL schemas, R scripts, shell scripts, docs,β¦
π OpenHands: AI-Driven Development

