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)
A PreToolUse hook can block the corresponding tool call by returning a non-zero exit code.
Only by using MCP, Skills, SubAgent, and Hooks together with permission modes can Claude Code's capability as an orchestratable system be brought into play.
Prompts are essentially requests rather than guarantees, and the model may forget to carry out the requirements in them; Hooks provide a mandatory guarantee by automatically running scripts at the appointed point.
A notification event is triggered when Claude Code waits for user confirmation or input, and a command can be configured to send a desktop notification.
Configuring a check script on the "before tool call" event to block operations with exit code 2 when they hit a protected list enables gating of sensitive files, and the block applies only to the current operation rather than a permanent prohibition.
Configuring a hook that matches file-editing tools on the "after tool call" event enables automatic formatting after file modifications, and formatting error messages can be passed back to the model for self-correction.
Hooks script files need executable permission added, otherwise they will fail silently.
Hooks configuration is written in the hooks block of settings files and applies at all three levels—user, project and local; hooks from multiple layers are merged and each triggers independently without overriding one another.
Hooks scripts use exit code 0 to allow the action normally and exit code 2 to block the current operation, in which case the standard error output is passed back to the model as the reason for blocking; other non-zero exit codes are usually treated only as the script itself erroring and do not necessarily block.
Each Hooks event carries structured JSON input containing the session ID, tool name, tool parameters and other information, which the script reads via standard input.
23 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%UnverifiedA PreToolUse hook can block the corresponding tool call by returning a non-zero exit code.
50%UnverifiedOnly by using MCP, Skills, SubAgent, and Hooks together with permission modes can Claude Code's capability as an orchestratable system be brought into play.
50%