hooks-automation
Hooks Automation
Overview
Hooks are user-defined shell commands, LLM prompts, or subagents that execute automatically at specific points in Claude Code's lifecycle. They provide deterministic control over Claude Code's behavior, ensuring certain actions always happen rather than relying on the LLM to choose to run them. Use hooks to enforce project rules, automate repetitive tasks, and integrate Claude Code with your existing tools.
There are three types of hook handlers. Command hooks (type: "command") run a shell command
that receives JSON on stdin and communicates results through exit codes and stdout. Prompt hooks
(type: "prompt") send a prompt to a Claude model for single-turn yes/no evaluation. Agent hooks
(type: "agent") spawn a subagent that can use tools like Read, Grep, and Glob to verify conditions
before returning a decision.
Hooks are defined in JSON settings files or in skill/agent YAML frontmatter. The configuration has three levels: choose a hook event (the lifecycle point), add a matcher group (a regex filter for when it fires), and define one or more hook handlers (the command, prompt, or agent that runs).