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. Confirm 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.
- Confirm event names in the reference. The set has grown past the original five-event blog posts.
Comments
No comments yet. Be the first to comment!
Related Tools
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.

Anthropic Subagent: The Multi-Agent Architecture Revolution
Deep dive into Anthropic multi-agent architecture design. Learn how Subagents break through context window limitations, achieve 90% performance improvements, and real-world applications in Claude Code.