https://github.com/karanb192/claude-code-hooks
๐ช A growing collection of useful Claude Code hooks. Copy, paste, customize.
https://github.com/karanb192/claude-code-hooks
ai-tools anthropic automation claude claude-code claude-code-hooks cli developer-tools hooks notifications security
Last synced: 11 days ago
JSON representation
๐ช A growing collection of useful Claude Code hooks. Copy, paste, customize.
- Host: GitHub
- URL: https://github.com/karanb192/claude-code-hooks
- Owner: karanb192
- License: mit
- Created: 2026-01-24T18:58:55.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-01-24T20:21:14.000Z (about 1 month ago)
- Last Synced: 2026-01-25T08:15:48.740Z (about 1 month ago)
- Topics: ai-tools, anthropic, automation, claude, claude-code, claude-code-hooks, cli, developer-tools, hooks, notifications, security
- Language: JavaScript
- Homepage:
- Size: 28.3 KB
- Stars: 39
- Watchers: 0
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-claude-code - **claude-code-hooks** - A growing collection of useful Claude Code hooks. Copy, paste, customize.. (๐ ๏ธ Tools & Utilities)
README
# claude-code-hooks
๐ช Ready-to-use hooks for Claude Code โ safety, automation, notifications, and more.
[](https://github.com/karanb192/claude-code-hooks)
[](https://opensource.org/licenses/MIT)
[](hook-scripts/tests)
### ๐ฌ Quick Demo
Protecting Secrets
Blocking Dangerous Commands
A growing collection of tested, documented hooks you can copy, paste, and customize.
---
## ๐ Table of Contents
- [Hooks](#-hooks)
- [Quick Start](#-quick-start)
- [Safety Levels](#-safety-levels)
- [Testing](#-testing)
- [Contributing](#-contributing)
---
## ๐ช Hooks
### Pre-Tool-Use
Runs **before** Claude executes a tool. Can block or modify the operation.
| Hook | Matcher | Description |
|------|---------|-------------|
| [block-dangerous-commands](hook-scripts/pre-tool-use/block-dangerous-commands.js) | `Bash` | Blocks dangerous shell commands (rm -rf ~, fork bombs, curl\|sh) |
| [protect-secrets](hook-scripts/pre-tool-use/protect-secrets.js) | `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](hook-scripts/post-tool-use/auto-stage.js) | `Edit\|Write` | Automatically git stages files after Claude modifies them |
### Notification
Fires when Claude needs user attention.
| Hook | Matcher | Description |
|------|---------|-------------|
| [notify-permission](hook-scripts/notification/notify-permission.js) | `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](hook-scripts/utils/event-logger.py) | Python | Logs 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:**
```bash
mkdir -p ~/.claude/hooks
cp hook-scripts/pre-tool-use/block-dangerous-commands.js ~/.claude/hooks/
```
**2. Add to `.claude/settings.json`:**
```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:
| 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.
```javascript
const SAFETY_LEVEL = 'strict'; // or 'critical', 'high'
```
---
## ๐งช Testing
All hooks include comprehensive tests:
```bash
# 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](https://docs.anthropic.com/en/docs/claude-code/hooks) for:
- All hook events and their lifecycles
- Input/output JSON formats
- Matcher patterns
- Environment variables
---
## ๐ค Contributing
Contributions welcome! See [CONTRIBUTING.md](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](https://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](https://github.com/karanb192)