Claude Hooks
Claude Hooks are user-defined shell commands that Claude Code runs at fixed points in its lifecycle. Official docs stress the difference from skills: hooks are deterministic. Formatters, notifications, protected-file blocks, and permission auto-approves always run, instead of waiting for the model to remember. For judgment calls you can also attach prompt-based or agent-based hooks. HTTP hooks exist for remote listeners.
The current guide's examples include desktop notifications when Claude needs input, auto-format after edits, blocking edits to protected files, re-injecting context after compaction, auditing config changes, and reloading env when the directory changes. Matchers can filter by tool name and arguments. Configure hooks in a settings file (user or project), not in chat.
Key Features
- Lifecycle shell: Docs mention events such as UserPromptSubmit, PreToolUse, PostToolUse, and Stop, plus notification-style hooks.
- Input/output contract: Hooks read JSON on stdin and can return structured JSON or an exit code.
- Matchers: Limit a hook to one tool or argument pattern.
- Prompt- and agent-based hooks: Use a model when the rule is not a regex.
- Not a skill: Skills teach. Hooks enforce.
Use Cases
- Format and lint after every edit.
- Block writes to secrets or generated files.
- Notify when the agent is waiting, so you can leave the terminal.
Pricing
Hooks ship with Claude Code. No separate SKU. You still pay the Claude plan or API that runs the session. Recheck claude.com/pricing.
Getting Started
- Read Automate actions with hooks.
- Add a
hooksblock to a settings file as the first-hook walkthrough shows. - Start with a notification hook, then a PostToolUse formatter.
- For schemas, use the hooks reference linked from that guide.
Frequently Asked Questions
Can a hook stop Claude?
Yes. Official examples include blocking edits and auto-approving specific permission prompts. Read the exit-code and JSON output rules before you rely on a block.
Hooks vs skills?
Skills are instructions loaded on demand. Hooks always fire at an event. Use both: a skill for the procedure, a hook for the gate.
Where do they live?
In settings files, and they can be packaged inside a plugin.
Alternatives
- Claude Skills: Procedures, not enforcement.
- Claude Plugins: How you distribute hooks.
- Claude Code: The host.
Tips
- Keep hooks short and boring. Long LLM hooks become a second agent.
- Log hook failures. Silent formatters waste a session.
- Recheck event names in the reference. The set has grown past the original five-event blog posts.
Conclusion
Hooks are how you make Claude Code obey the repo. Start from the hooks guide, add one notification and one formatter, then package the rest.
Comments
No comments yet. Be the first to comment!
Related Tools
Claude Skills
code.claude.com/docs/en/skills
Claude Code skills are SKILL.md packages that extend the agent on demand. Custom slash commands merged into skills; follows the Agent Skills standard.
Claude Plugins
code.claude.com/docs/en/discover-plugins
Versioned Claude Code bundles of skills, agents, hooks, and MCP. Install from the official marketplace with /plugin or enabledPlugins.
Claude Code
code.claude.com/docs/en/overview
Anthropic's agentic coding tool for terminal, IDE, desktop, and browser. Reads the repo, edits files, runs commands, and connects MCP, skills, and hooks.
Related Insights
Skills + Hooks + Plugins: How Anthropic Redefined AI Coding Tool Extensibility
An in-depth analysis of Claude Code's trinity architecture of Skills, Hooks, and Plugins. Explore why this design is more advanced than GitHub Copilot and Cursor, and how it redefines AI coding tool extensibility through open standards.
Claudesidian: Transform Obsidian into an AI-Powered Second Brain
Discover Claudesidian, an open-source project that perfectly integrates Obsidian with Claude Code. Built-in PARA method, custom commands, and automated workflows for a complete idea-to-implementation solution.
Seven AI Coding CLIs, Six Months: No Matter How Strong the Model, Work Needs Supervision
Claude Code, Codex, opencode, pi, omp and DeepSeek Harness all have personalities. After six months of deep use I run a division of labor: pi for the fastest cheapest reviews, omp for complex PRs, DeepSeek Harness on V4 Flash for high-frequency low-cost review, and Claude Code, Qoder and Cursor for writing. No matter how strong the model, work needs supervision — ideally from an independent third party.