Building Hooks
Create event-driven automations that connect Claude Code to external systems — Slack notifications, pre-commit validation, CI triggers, and more.
Create event-driven automations that connect Claude Code to the world outside your editor. Hooks react to lifecycle events — pre-commit validation, post-build notifications, file-change triggers, or integration with any external service.
If Skills teach Claude what to do and Minds shape how Claude thinks, Hooks are the nervous system that connects Claude Code sessions to your workflow infrastructure. Slack alerts when a task completes. Validation before every commit. Automatic syncs with your project management tool. The bridge between Claude Code and everything else.
What is a Hook?
A Hook is a HOOKS.md instruction file plus an optional hooks.json configuration, installed into .claude/hooks/. Hooks respond to Claude Code events — they run automatically when specific things happen.
| Concept | What it means for you |
|---|---|
HOOKS.md | Instructions describing what the hook does and how to configure it |
hooks.json | Event-to-action mappings (which events trigger which scripts) |
vault.yaml | The manifest — name, price, metadata |
.claude/hooks/ | Where it lives on the buyer's machine |
| Event-driven | Runs automatically when triggered — no manual invocation |
Create your first Hook
Let's build a hook that validates commit messages follow conventional commits format before every commit.
Scaffold
$ myclaude init commit-guard --type hooks
$ cd commit-guardWrite HOOKS.md
# Commit Guard — Conventional Commits Enforcer
Validates that every commit message follows the Conventional
Commits specification before allowing the commit to proceed.
## What it checks
- Message starts with a valid type: feat, fix, refactor, docs,
test, chore, style, perf, ci, build, revert
- Optional scope in parentheses: feat(auth): ...
- Colon and space after type/scope
- Description starts lowercase
- No period at the end of the first line
- First line under 72 characters
## Configuration
No configuration needed. Install and forget.
## Examples
Valid:
- feat: add user authentication
- fix(api): resolve race condition in checkout
- docs: update quickstart guide
Invalid:
- Added new feature (no type prefix)
- feat:missing space after colon
- Fix: capitalized descriptionCreate hooks.json
{
"hooks": {
"PreCommit": [
{
"type": "command",
"command": "echo '$COMMIT_MESSAGE' | head -1 | grep -qE '^(feat|fix|refactor|docs|test|chore|style|perf|ci|build|revert)(\\(.+\\))?: [a-z]'"
}
]
}
}Wire vault.yaml
name: commit-guard
version: 1.0.0
type: hooks
title: "Commit Guard — Conventional Commits Enforcer"
description: "Pre-commit hook that validates conventional commit format. Install and forget — consistent commit history from day one."
price: 0
tags:
- git
- commits
- validation
- pre-commitPublish
$ myclaude validate
$ myclaude publishHook event types
Hooks can respond to these Claude Code lifecycle events:
| Event | When it fires | Use case |
|---|---|---|
PreCommit | Before a git commit is created | Validate messages, run linters, check for secrets |
PostCommit | After a commit succeeds | Notify team channels, update trackers |
PrePush | Before pushing to remote | Run tests, check branch naming |
OnFileChange | When Claude modifies a file | Trigger builds, sync state, log changes |
OnSessionStart | When a Claude Code session begins | Load context, check environment, pull updates |
OnSessionEnd | When a session closes | Generate summaries, sync progress, clean up |
Practical examples
Slack notification on task completion:
{
"hooks": {
"PostCommit": [
{
"type": "command",
"command": "curl -X POST $SLACK_WEBHOOK_URL -d '{\"text\": \"Committed: $COMMIT_MESSAGE\"}'"
}
]
}
}Security scan before push:
{
"hooks": {
"PrePush": [
{
"type": "command",
"command": "grep -rn 'API_KEY\\|SECRET\\|PASSWORD' --include='*.ts' --include='*.js' src/ && echo 'SECRETS FOUND' && exit 1 || exit 0"
}
]
}
}What makes a great Hook
| Weak | Strong |
|---|---|
| Complex setup with many config steps | Install and it works — zero configuration |
| Unclear about what events it responds to | Event mapping documented clearly in HOOKS.md |
| No error handling | Graceful failures with clear error messages |
| Runs slowly (blocks the user) | Fast execution — hooks should feel invisible |
The best hooks are invisible. Users install them and forget they exist — until the hook catches something that would have been a problem.
Common questions
Can hooks run external scripts?
Yes. Hooks can execute any shell command available in the user's environment. Keep in mind that buyers may be on macOS, Linux, or Windows — use portable commands or document platform requirements.
Can multiple hooks respond to the same event?
Yes. Multiple hooks can listen to the same event. They execute in order. If any hook in a Pre-* event exits with a non-zero code, the action is blocked.
What's the difference between a Hook and a Workflow?
A Workflow is a sequence of steps you invoke on demand. A Hook is an automated reaction to an event. Workflows are pull (you call them). Hooks are push (they trigger themselves).
Related pages
- Product Categories — all 12 categories compared
- What People Build — real examples of MyClaude products
- Publishing Guide — the basics of publishing
- Claude Code Hooks Docs — official Anthropic documentation on hooks
Building CLAUDE.md Configs
Create project configurations that shape how Claude Code behaves in any codebase or domain. The highest-leverage file in the Claude Code ecosystem.
Building Workflows Guide
Build a multi-step automation workflow for Claude Code. Chain skills, agents, and shell commands into a repeatable pipeline.