{"id":43214427,"url":"https://github.com/karanb192/claude-code-hooks","last_synced_at":"2026-02-21T07:51:29.210Z","repository":{"id":334440720,"uuid":"1141384261","full_name":"karanb192/claude-code-hooks","owner":"karanb192","description":"🪝 A growing collection of useful Claude Code hooks. Copy, paste, customize.","archived":false,"fork":false,"pushed_at":"2026-01-24T20:21:14.000Z","size":29,"stargazers_count":39,"open_issues_count":0,"forks_count":5,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-25T08:15:48.740Z","etag":null,"topics":["ai-tools","anthropic","automation","claude","claude-code","claude-code-hooks","cli","developer-tools","hooks","notifications","security"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karanb192.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-24T18:58:55.000Z","updated_at":"2026-01-25T07:43:42.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/karanb192/claude-code-hooks","commit_stats":null,"previous_names":["karanb192/claude-code-hooks"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/karanb192/claude-code-hooks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karanb192%2Fclaude-code-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karanb192%2Fclaude-code-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karanb192%2Fclaude-code-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karanb192%2Fclaude-code-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karanb192","download_url":"https://codeload.github.com/karanb192/claude-code-hooks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karanb192%2Fclaude-code-hooks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29676854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T06:23:40.028Z","status":"ssl_error","status_checked_at":"2026-02-21T06:23:39.222Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-tools","anthropic","automation","claude","claude-code","claude-code-hooks","cli","developer-tools","hooks","notifications","security"],"created_at":"2026-02-01T08:00:30.280Z","updated_at":"2026-02-21T07:51:29.202Z","avatar_url":"https://github.com/karanb192.png","language":"JavaScript","readme":"# claude-code-hooks\n\n🪝 Ready-to-use hooks for Claude Code — safety, automation, notifications, and more.\n\n[![GitHub stars](https://img.shields.io/github/stars/karanb192/claude-code-hooks?style=social)](https://github.com/karanb192/claude-code-hooks)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Tests](https://img.shields.io/badge/tests-262%20passing-brightgreen)](hook-scripts/tests)\n\n### 🎬 Quick Demo\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth align=\"center\"\u003eProtecting Secrets\u003c/th\u003e\n    \u003cth align=\"center\"\u003eBlocking Dangerous Commands\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd valign=\"bottom\" align=\"center\"\u003e\u003cimg src=\"assets/block-secrets.png\" alt=\"Hook blocking .env read\" width=\"400\"\u003e\u003c/td\u003e\n    \u003ctd valign=\"bottom\" align=\"center\"\u003e\u003cimg src=\"assets/block-dangerous-commands.png\" alt=\"Hook blocking dangerous commands\" width=\"400\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nA growing collection of tested, documented hooks you can copy, paste, and customize.\n\n---\n\n## 📑 Table of Contents\n\n- [Hooks](#-hooks)\n- [Quick Start](#-quick-start)\n- [Safety Levels](#-safety-levels)\n- [Testing](#-testing)\n- [Contributing](#-contributing)\n\n---\n\n## 🪝 Hooks\n\n### Pre-Tool-Use\n\nRuns **before** Claude executes a tool. Can block or modify the operation.\n\n| Hook | Matcher | Description |\n|------|---------|-------------|\n| [block-dangerous-commands](hook-scripts/pre-tool-use/block-dangerous-commands.js) | `Bash` | Blocks dangerous shell commands (rm -rf ~, fork bombs, curl\\|sh) |\n| [protect-secrets](hook-scripts/pre-tool-use/protect-secrets.js) | `Read\\|Edit\\|Write\\|Bash` | Prevents reading/modifying/exfiltrating sensitive files |\n\n### Post-Tool-Use\n\nRuns **after** Claude executes a tool. Can react to results.\n\n| Hook | Matcher | Description |\n|------|---------|-------------|\n| [auto-stage](hook-scripts/post-tool-use/auto-stage.js) | `Edit\\|Write` | Automatically git stages files after Claude modifies them |\n\n### Notification\n\nFires when Claude needs user attention.\n\n| Hook | Matcher | Description |\n|------|---------|-------------|\n| [notify-permission](hook-scripts/notification/notify-permission.js) | `permission_prompt\\|idle_prompt` | Sends Slack alerts when Claude needs input |\n\n### Utils\n\nTools to help you build and debug hooks.\n\n| Tool | Language | Description |\n|------|----------|-------------|\n| [event-logger](hook-scripts/utils/event-logger.py) | Python | Logs all hook events to inspect payload structures |\n\n\u003e 💡 **Building a new hook?** Use `event-logger.py` to discover what data Claude Code provides for each event before writing your own hooks.\n\n---\n\n## 🚀 Quick Start\n\n**1. Copy the hook script:**\n```bash\nmkdir -p ~/.claude/hooks\ncp hook-scripts/pre-tool-use/block-dangerous-commands.js ~/.claude/hooks/\n```\n\n**2. Add to `.claude/settings.json`:**\n```json\n{\n  \"hooks\": {\n    \"PreToolUse\": [\n      {\n        \"matcher\": \"Bash\",\n        \"hooks\": [\n          {\n            \"type\": \"command\",\n            \"command\": \"node ~/.claude/hooks/block-dangerous-commands.js\"\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n**3. Restart Claude Code** — the hook is now active.\n\n\u003e 💡 **Tip:** Use multiple hooks together. Combine `block-dangerous-commands` + `protect-secrets` for comprehensive safety.\n\n---\n\n## 🛡️ Safety Levels\n\nSecurity hooks support configurable safety levels:\n\n| Level | What's Blocked | Use Case |\n|-------|----------------|----------|\n| `critical` | Catastrophic only (rm -rf ~, fork bombs, dd to disk) | Maximum flexibility |\n| `high` | + Risky (force push main, secrets exposure, git reset --hard) | **Recommended** |\n| `strict` | + Cautionary (any force push, sudo rm, docker prune) | Maximum safety |\n\n**To change:** Edit the `SAFETY_LEVEL` constant at the top of each hook.\n\n```javascript\nconst SAFETY_LEVEL = 'strict'; // or 'critical', 'high'\n```\n\n---\n\n## 🧪 Testing\n\nAll hooks include comprehensive tests:\n\n```bash\n# Run all tests\nnpm test\n\n# Run specific hook tests\nnode --test hook-scripts/tests/pre-tool-use/block-dangerous-commands.test.js\n```\n\n**Test coverage:**\n- ✅ Unit tests for core functions\n- ✅ Integration tests for stdin/stdout flow\n- ✅ Config validation tests\n\n---\n\n## 📖 Configuration Reference\n\nSee the [official Claude Code hooks documentation](https://docs.anthropic.com/en/docs/claude-code/hooks) for:\n\n- All hook events and their lifecycles\n- Input/output JSON formats\n- Matcher patterns\n- Environment variables\n\n---\n\n## 🤝 Contributing\n\nContributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n\n**Ideas for new hooks:**\n\n| Hook | Event | Description |\n|------|-------|-------------|\n| `protect-tests` | PreToolUse | Block test deletion/disabling |\n| `auto-format` | PostToolUse | Run prettier/black/gofmt after edits |\n| `branch-guard` | PreToolUse | Block changes on main/master branch |\n| `context-snapshot` | PreCompact | Preserve context before compaction |\n| `session-summary` | Stop | Generate summary on session end |\n| `ntfy-notify` | Notification | Free mobile push via [ntfy.sh](https://ntfy.sh) |\n| `discord-notify` | Notification | Discord webhook alerts |\n| `cost-tracker` | PostToolUse | Track token usage and estimate costs |\n| `tts-alerts` | Notification | Voice notifications via say/espeak |\n| `rules-injector` | UserPromptSubmit | Auto-inject CLAUDE.md rules |\n| `rate-limiter` | PreToolUse | Limit tool calls per minute |\n| `context-injector` | SessionStart | Inject project context on session start |\n\n---\n\n## 📄 License\n\nMIT © [karanb192](https://github.com/karanb192)\n","funding_links":[],"categories":["🛠️ Tools \u0026 Utilities"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaranb192%2Fclaude-code-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaranb192%2Fclaude-code-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaranb192%2Fclaude-code-hooks/lists"}