Hooks
Hooks are an event-driven automation mechanism that executes predefined operations or workflows automatically in response to specific trigger events, such as file saves or code commits. Core characteristics include deep integration with the development workflow, support for custom trigger conditions and response actions, and the ability to complete tasks such as testing, formatting, and building without manual intervention. Hooks are widely used in development tools and IDEs to increase automation and development efficiency.
Core Facts
Hooks are an event-driven automated trigger mechanism that automatically triggers preset subsequent actions when a specific operation is completed.
Hooks adopt a lazy-loading design, loading into the context only when triggered and not occupying context space at other times.
Gemini CLI's secret-scanning hook can automatically intercept file write operations that contain hardcoded API keys.
Timeline (last 90 days)
For any operation involving money, identity, or security, it is not sufficient to rely solely on prompts to constrain the model — enforcement must be mandatory at the code level through hooks, because hooks are guarantees while prompts are merely suggestions.
The Hooks mechanism allows developers to insert custom logic at lifecycle nodes of tool calls, and is the key means of intercepting and transforming raw output.
Hooks run outside the model and do not consume any tokens.
Hooks are out-of-band controls whose execution path is independent of the LLM inference chain and whose behavior is unaffected by input content.
Using code hooks for hard interception is more reliable than placing safety rules in prompts and relying on the model to self-enforce them, because the model can be bypassed or produce hallucinations.
The most critical difference between Hooks and CLAUDE.md is that CLAUDE.md relies on the model's own judgment, while Hooks are forcibly triggered in the background by the Claude Code software.
Hooks are a set of deterministic mechanisms controlled at the software level within Claude Code, where the software directly intervenes and enforces actions at configured trigger points without relying on the model's own judgment.
Hook configurations are divided into project-level and user-level; settings in the project folder only affect that project, while global settings under the user's home directory apply to all projects.
There are currently five types of Handlers: Command, HTTP, MCP Tool, Prompt, and Agent.
Each Event supports different Handler types; some can use Prompt and Agent, while others can only use Command or HTTP.
8 more timeline events
All Facts (20)
Hooks are an event-driven automated trigger mechanism that automatically triggers preset subsequent actions when a specific operation is completed.
65%VerifiedHooks adopt a lazy-loading design, loading into the context only when triggered and not occupying context space at other times.
65%VerifiedGemini CLI's secret-scanning hook can automatically intercept file write operations that contain hardcoded API keys.
65%UnverifiedPlugin将Skills、Hooks和MCP配置打包成单个可安装包,新工程师安装后可立即拥有与资深同事相同的上下文和能力
90%UnverifiedHooks的stop hook可以在会话结束时反思发生了什么并提出CLAUDE.md更新建议,start hook可以动态加载团队特定的上下文
90%UnverifiedKiro提供Hooks开发钩子机制,将Git Hooks和CI/CD流水线的自动化能力与AI能力结合,在本地开发阶段触发
90%UnverifiedClaude Code的Hooks机制是确定性的,每次都会执行,而Claude.md中的提示词指令是概率性的,可能被遗漏
85%UnverifiedHooks和Skills的核心区别在于:Skill是模型主动调用的拉模式(Pull),Hook是外部系统被动触发的推模式(Push)
85%UnverifiedClaude Code的Hooks机制包括停止钩子(会话结束时自动提议更新CLAUDE.md)和启动钩子(自动加载最新上下文信息)
85%UnverifiedClaude Code的Hooks系统提供29个事件钩子,借鉴了Git Hooks的事件驱动架构设计
80%UnverifiedClaude Code的Hooks机制是AI完全无法绕过的硬性约束,可在AI行动链中设置强制检查点,防止因模型幻觉或误判导致的越权操作
80%UnverifiedMaking good use of Hooks can reduce a large amount of unnecessary rework, improving development efficiency by at least double.
60%UnverifiedHooks are programmatic hard constraints enforced through an event-driven mechanism that does not rely on the model's self-discipline, making them more reliable than the soft constraint approach of CLAUDE.md.
60%UnverifiedIn Claude Code Hooks, exit code 0 means pass-through, exit code 2 means hard block (the AI will not retry), and other non-zero exit codes mean soft warnings.
60%UnverifiedClaude Code的工具链(harness)由五个扩展点构建而成:CLAUDE.md文件、Hooks、Skills、Plugins、LSP集成与MCP服务器
60%UnverifiedKiro的两大核心功能是Specs(规范)和Hooks(开发钩子)
60%UnverifiedGemini CLI's hook mechanism can intercept AI-generated content before it is written to disk, which constitutes a Shift-Left Security practice.
60%UnverifiedGemini CLI addresses AI coding control issues through three key features: Hooks, Skills, and Plan Mode.
60%UnverifiedFor any operation involving money, identity, or security, it is not sufficient to rely solely on prompts to constrain the model — enforcement must be mandatory at the code level through hooks, because hooks are guarantees while prompts are merely suggestions.
50%UnverifiedThe Hooks mechanism allows developers to insert custom logic at lifecycle nodes of tool calls, and is the key means of intercepting and transforming raw output.
50%