# Install & Configure: Claude Code Hooks: Safety, Automation & Notification Scripts
## What This Is
This open-source repository provides ready-to-drop-in JavaScript hooks for Claude Code that run before or after AI tool executions — blocking dangerous shell commands, protecting secret files, auto-staging git changes, and sending Slack alerts when Claude needs input. Each hook is tested (262 passing tests), MIT-licensed, and designed to be copied, pasted, and customized in minutes. It solves a real gap: giving developers guardrails and automation on top of Claude Code's agentic actions without building from scratch.
Source: https://github.com/karanb192/claude-code-hooks
## Before You Start
Scan my workspace and analyze:
- The project language, framework, and directory structure
- Existing agent configuration (check for .claude/, .codex/, CLAUDE.md, settings.json, commands/, skills/ directories)
- Whether this repository or a similar tool is already cloned or installed
Then ask me before proceeding:
1. Which lifecycle event should this hook fire on? (PreToolUse, PostToolUse, Notification, etc.)
2. Are there any files, patterns, or tools this should be scoped to?
## Fetch the Source
Clone or inspect the repository to understand what needs to be installed:
```bash
gh repo clone karanb192/claude-code-hooks
```
Review the README, directory structure, and any install instructions before proceeding.
## What to Implement
This is an **Agent Hook** — a shell/HTTP command that fires at lifecycle events.
- Add the hook configuration to `.claude/settings.json` under the lifecycle event I specified
- If the hook needs a shell script, create it and make it executable (`chmod +x`)
- If the hook calls an external API, configure it using credentials from my .env files
- Validate the JSON config is syntactically correct before saving
## Additional Context
- Clone the repo and copy block-dangerous-commands.js and protect-secrets.js into ~/.claude/hooks/ using the two-line bash commands from the Quick Start section.
- Add the PreToolUse configuration block to your .claude/settings.json, setting SAFETY_LEVEL to 'high' for the recommended balance of flexibility and protection.
- Run event-logger.py against your own project to inspect the exact payload Claude Code sends for each hook event, then use that data to write a custom hook tailored to your codebase within 30 minutes.
## Reference Implementation
```
// .claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "node ~/.claude/hooks/block-dangerous-commands.js"
}
]
}
]
}
}
// In hook script:
const SAFETY_LEVEL = 'strict'; // or 'critical', 'high'
```
## Guidelines
- Adapt everything to my existing project — do not assume a specific stack or directory layout
- Review any fetched code for safety before installing or executing it
- After setup, run a quick verification and show me a summary of exactly what was installed, where, and how to use it