# Claude Code Hooks — Automate Your AI Workflow > Built-in automation system for Claude Code. Run shell commands on events like file edits, tool calls, and notifications. Lint on save, auto-test, and more. ## Install Save the content below to `.claude/skills/` or append to your `CLAUDE.md`: ## Quick Use Add hooks to `.claude/settings.json`: ```json { "hooks": { "PostToolUse": [ { "matcher": "Edit|Write", "command": "eslint --fix $CLAUDE_FILE_PATH" } ] } } ``` Now every file edit by Claude Code auto-runs ESLint. ## What are Claude Code Hooks? Claude Code Hooks are automation triggers that run shell commands in response to Claude Code events. They let you enforce coding standards, run tests, validate changes, and integrate with external tools — all automatically, without Claude needing to remember to do it. **Answer-Ready**: Claude Code Hooks are built-in automation triggers that run shell commands on events like file edits, tool calls, and notifications. Enforce linting, auto-testing, and custom validation in your Claude Code workflow. **Best for**: Developers who want automated quality checks in their Claude Code workflow. **Works with**: Claude Code CLI and IDE extensions. **Setup time**: Under 2 minutes. ## Core Features ### 1. Event Types | Event | Fires When | |-------|-----------| | `PreToolUse` | Before a tool executes | | `PostToolUse` | After a tool completes | | `Notification` | When Claude sends a notification | | `Stop` | When Claude finishes a turn | | `SubagentStop` | When a subagent completes | ### 2. Tool Matchers Target specific tools: ```json { "hooks": { "PostToolUse": [ { "matcher": "Edit|Write", "command": "prettier --write $CLAUDE_FILE_PATH" }, { "matcher": "Bash", "command": "echo 'Command executed: $CLAUDE_TOOL_INPUT'" } ] } } ``` ### 3. Common Hook Patterns **Auto-lint on file changes:** ```json { "matcher": "Edit|Write", "command": "eslint --fix $CLAUDE_FILE_PATH 2>/dev/null || true" } ``` **Run tests after code changes:** ```json { "matcher": "Edit", "command": "npm test -- --related $CLAUDE_FILE_PATH 2>&1 | tail -5" } ``` **Type-check TypeScript files:** ```json { "matcher": "Edit|Write", "command": "[[ $CLAUDE_FILE_PATH == *.ts ]] && npx tsc --noEmit 2>&1 | head -20 || true" } ``` **Block commits without tests:** ```json { "matcher": "Bash", "command": "if echo $CLAUDE_TOOL_INPUT | grep -q 'git commit'; then npm test || exit 1; fi" } ``` ### 4. Environment Variables | Variable | Content | |----------|---------| | `CLAUDE_FILE_PATH` | Path of the affected file | | `CLAUDE_TOOL_INPUT` | JSON input to the tool | | `CLAUDE_TOOL_OUTPUT` | JSON output from the tool | ### 5. Hook Output Hook stdout is fed back to Claude as context: ```json { "matcher": "Edit", "command": "python check_style.py $CLAUDE_FILE_PATH" } ``` If the style checker reports issues, Claude sees the output and can fix them. ## Advanced: PreToolUse Blocking ```json { "hooks": { "PreToolUse": [ { "matcher": "Edit", "command": "python validate_edit.py", "blocking": true } ] } } ``` If the command exits non-zero, the tool call is blocked. ## FAQ **Q: Do hooks slow down Claude Code?** A: Hooks run synchronously, so heavy commands add latency. Keep hooks fast (< 2s) or make them async. **Q: Can hooks modify Claude's behavior?** A: Yes, hook stdout is fed back as context. You can guide Claude's next action. **Q: Where do I put the settings file?** A: `.claude/settings.json` in your project root (project-level) or `~/.claude/settings.json` (global). ## Source & Thanks > Built into [Claude Code](https://docs.anthropic.com/en/docs/claude-code) by Anthropic. > > Documentation: [docs.anthropic.com/en/docs/claude-code/hooks](https://docs.anthropic.com/en/docs/claude-code/hooks) ## Quick Start Add hooks configuration to `.claude/settings.json` — Claude Code will automatically run ESLint and other tools after file edits. ## What are Claude Code Hooks? Claude Code Hooks are built-in automation triggers that run shell commands on events like file edits and tool calls. Automatically execute code linting, tests, and validation. **In one sentence**: Claude Code's built-in automation system runs lint, tests, and custom validation automatically on file edits and tool calls. **For**: Developers who want to automate quality checks in their Claude Code workflow. ## Core Features ### 1. Event Types PreToolUse, PostToolUse, Notification, Stop, SubagentStop. ### 2. Tool Matchers Match specific tools with regex (Edit, Write, Bash, etc.). ### 3. Common Patterns Auto-lint, run tests, type-check, block commits without tests. ### 4. Output Feedback Hook output is fed back as context to guide Claude's next steps. ## FAQ **Q: Will it slow down Claude Code?** A: Runs synchronously — keep commands under 2 seconds. **Q: Where does the config file go?** A: Project-level `.claude/settings.json` or global `~/.claude/settings.json`. ## Source & Thanks > Built into [Claude Code](https://docs.anthropic.com/en/docs/claude-code) by Anthropic --- Source: https://tokrepo.com/en/workflows/claude-code-hooks-automate-your-ai-workflow-587e4918 Author: Skill Factory