Thanks for your interest in contributing to claude-code-hooks!
-
Create the hook script in the appropriate directory:
hook-scripts/pre-tool-use/— runs before tool executionhook-scripts/post-tool-use/— runs after tool executionhook-scripts/notification/— handles notification eventshook-scripts/session/— session start/end events
-
Follow the existing pattern:
#!/usr/bin/env node /** * Hook Name - Event Hook for Matcher * Brief description. * Logs to: ~/.claude/hooks-logs/ * * Setup in .claude/settings.json: * { ... } */ // Implementation if (require.main === module) { main(); } else { module.exports = { /* exported functions for testing */ }; }
-
Add tests in
hook-scripts/tests/<event-type>/<hook-name>.test.js:- Unit tests for exported functions
- Integration tests for stdin/stdout flow
- Config validation tests
-
Update README.md with your hook in the appropriate table.
- Keep it concise — no over-engineering
- Use Node.js built-in modules where possible
- Log to
~/.claude/hooks-logs/using JSONL format - Handle errors gracefully — always output
{}on failure - Export core functions for testability
# Run all tests
npm test
# Run specific test file
node --test hook-scripts/tests/pre-tool-use/your-hook.test.jsAll tests must pass before merging.
- Fork the repo
- Create a feature branch (
git checkout -b feat/my-hook) - Add your hook + tests
- Run
npm testto ensure all tests pass - Update README.md
- Submit PR with a clear description
Looking for inspiration? Here are some hooks that would be useful:
- Auto-format code after Write/Edit (prettier, eslint --fix)
- Notify Discord/Telegram on permission prompts
- Block writes to protected branches
- Log all commands to external service
- Rate limit tool calls
- Add context injection on SessionStart
Open an issue if you have questions or want to discuss a hook idea before implementing.