Open source library of 30 Claude Code hooks. Install any hook with a single command.
# Interactive mode - browse and select hooks
npx @hasna/hooks
# Install specific hooks
npx @hasna/hooks install gitguard branchprotect checkpoint
# List all available hooks
npx @hasna/hooks list# Global install
bun install -g @hasna/hooks
# Or use npx (no install needed)
npx @hasna/hooksIf you need a scoped registry token (publish or private installs), copy an example file and set NPM_TOKEN:
cp .npmrc.example .npmrcSee CONTRIBUTING.md for publishing and secrets guidance.
Run without arguments to browse hooks by category:
hooks# Install one or more hooks
hooks install gitguard branchprotect checkpoint
# Hooks are installed to .hooks/ and registered in ~/.claude/settings.json# Search by name, description, or tags
hooks search security
hooks search githooks list --category "Git Safety"
hooks list --category "Code Quality"hooks info gitguardhooks list --registeredhooks remove gitguard| Hook | Event | Description |
|---|---|---|
| gitguard | PreToolUse | Blocks destructive git operations like reset --hard, push --force, clean -f |
| branchprotect | PreToolUse | Prevents editing files directly on main/master branch |
| checkpoint | PreToolUse | Creates shadow git snapshots before file modifications for easy rollback |
| Hook | Event | Description |
|---|---|---|
| checktests | PostToolUse | Checks for missing tests after file edits |
| checklint | PostToolUse | Runs linting after file edits and creates tasks for errors |
| checkfiles | PostToolUse | Runs headless agent to review files and create tasks |
| checkbugs | PostToolUse | Checks for bugs via headless agent |
| checkdocs | PostToolUse | Checks for missing documentation and creates tasks |
| checktasks | PostToolUse | Validates task completion and tracks progress |
| Hook | Event | Description |
|---|---|---|
| checksecurity | PostToolUse | Runs security checks via headless agents |
| packageage | PreToolUse | Checks package age before install to prevent typosquatting |
| Hook | Event | Description |
|---|---|---|
| phonenotify | Stop | Sends push notifications to phone via ntfy.sh |
| agentmessages | Stop | Inter-agent messaging integration for service-message |
| desktopnotify | Stop | Sends native desktop notifications via osascript (macOS) or notify-send (Linux) |
| slacknotify | Stop | Sends Slack webhook notifications when Claude finishes |
| soundnotify | Stop | Plays a system sound when Claude finishes (macOS/Linux) |
| Hook | Event | Description |
|---|---|---|
| contextrefresh | Notification | Re-injects important context every N prompts to prevent drift |
| precompact | Notification | Saves session state before context compaction |
| Hook | Event | Description |
|---|---|---|
| autoformat | PostToolUse | Runs project formatter (Prettier, Biome, Ruff, Black, gofmt) after file edits |
| autostage | PostToolUse | Automatically git-stages files after Claude edits them |
| tddguard | PreToolUse | Blocks implementation edits unless corresponding test files exist |
| Hook | Event | Description |
|---|---|---|
| envsetup | PreToolUse | Warns when nvm, virtualenv, asdf, or rbenv may need activation before commands |
| Hook | Event | Description |
|---|---|---|
| permissionguard | PreToolUse | Auto-approves safe read-only commands and blocks dangerous operations |
| protectfiles | PreToolUse | Blocks access to .env, secrets, SSH keys, and lock files |
| promptguard | PreToolUse | Blocks prompt injection attempts and credential access requests |
| Hook | Event | Description |
|---|---|---|
| sessionlog | PostToolUse | Logs every tool call to .claude/session-log-<date>.jsonl |
| commandlog | PostToolUse | Logs every bash command Claude runs to .claude/commands.log |
| costwatch | Stop | Estimates session token usage and warns when budget threshold is exceeded |
| errornotify | PostToolUse | Detects tool failures and logs errors to .claude/errors.log |
| Hook | Event | Description |
|---|---|---|
| taskgate | PostToolUse | Validates task completion criteria before allowing tasks to be marked done |
Claude Code hooks are lifecycle interceptors that run during agent sessions:
- PreToolUse: Runs before a tool executes. Can block the operation.
- PostToolUse: Runs after a tool executes. Async, non-blocking.
- Stop: Runs when a session ends. Async, non-blocking.
- Notification: Runs on notification events. Async, non-blocking.
Each hook receives JSON on stdin and outputs JSON on stdout:
// PreToolUse input
{
"session_id": "abc123",
"cwd": "/path/to/project",
"tool_name": "Bash",
"tool_input": { "command": "git push --force" }
}
// PreToolUse output (block)
{ "decision": "block", "reason": "Destructive git operation blocked" }
// PreToolUse output (approve)
{ "decision": "approve" }Each hook follows a consistent structure:
hook-{name}/
├── src/
│ ├── hook.ts # Main hook logic (stdin → stdout)
│ ├── cli.ts # CLI for install/uninstall/status
│ └── index.ts # Library exports
├── package.json
├── CLAUDE.md
├── README.md
└── tsconfig.json
You can also install hooks individually as npm packages:
bun install -g @hasna/hook-gitguard
bun install -g @hasna/hook-branchprotect
bun install -g @hasna/hook-checkpointThen use their built-in CLI:
hook-gitguard install # Register in Claude settings
hook-gitguard status # Check if registered
hook-gitguard uninstall # UnregisterHooks are registered in ~/.claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{ "type": "command", "command": "hook-gitguard" }
]
}
]
}
}# Install dependencies
bun install
# Run CLI in development
bun run dev
# Build
bun run build
# Type check
bun run typecheck- Fork the repository
- Create a new hook in
hooks/hook-{name}/ - Follow the existing hook patterns
- Submit a pull request
Apache-2.0