[KongchangAI]
ConceptHooks机制 / 事件触发机制

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

Timeline (last 90 days)

Oct 11

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.

Unverified50%
Oct 10

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.

Unverified50%
Oct 9

Hooks run outside the model and do not consume any tokens.

Unverified50%
Oct 9

Hooks are out-of-band controls whose execution path is independent of the LLM inference chain and whose behavior is unaffected by input content.

Unverified50%
Oct 9

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.

Unverified50%
Oct 7

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.

Unverified50%
Oct 7

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.

Unverified50%
Oct 7

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.

Unverified50%
Oct 7

There are currently five types of Handlers: Command, HTTP, MCP Tool, Prompt, and Agent.

Unverified50%
Oct 7

Each Event supports different Handler types; some can use Prompt and Agent, while others can only use Command or HTTP.

Unverified50%

8 more timeline events

All Facts (20)

Verified

Hooks are an event-driven automated trigger mechanism that automatically triggers preset subsequent actions when a specific operation is completed.

65%
Verified

Hooks adopt a lazy-loading design, loading into the context only when triggered and not occupying context space at other times.

65%
Verified

Gemini CLI's secret-scanning hook can automatically intercept file write operations that contain hardcoded API keys.

65%
Unverified

Plugin将Skills、Hooks和MCP配置打包成单个可安装包,新工程师安装后可立即拥有与资深同事相同的上下文和能力

90%
Unverified

Hooks的stop hook可以在会话结束时反思发生了什么并提出CLAUDE.md更新建议,start hook可以动态加载团队特定的上下文

90%
Unverified

Kiro提供Hooks开发钩子机制,将Git Hooks和CI/CD流水线的自动化能力与AI能力结合,在本地开发阶段触发

90%
Unverified

Claude Code的Hooks机制是确定性的,每次都会执行,而Claude.md中的提示词指令是概率性的,可能被遗漏

85%
Unverified

Hooks和Skills的核心区别在于:Skill是模型主动调用的拉模式(Pull),Hook是外部系统被动触发的推模式(Push)

85%
Unverified

Claude Code的Hooks机制包括停止钩子(会话结束时自动提议更新CLAUDE.md)和启动钩子(自动加载最新上下文信息)

85%
Unverified

Claude Code的Hooks系统提供29个事件钩子,借鉴了Git Hooks的事件驱动架构设计

80%
Unverified

Claude Code的Hooks机制是AI完全无法绕过的硬性约束,可在AI行动链中设置强制检查点,防止因模型幻觉或误判导致的越权操作

80%
Unverified

Making good use of Hooks can reduce a large amount of unnecessary rework, improving development efficiency by at least double.

60%
Unverified

Hooks 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%
Unverified

In 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%
Unverified

Claude Code的工具链(harness)由五个扩展点构建而成:CLAUDE.md文件、Hooks、Skills、Plugins、LSP集成与MCP服务器

60%
Unverified

Kiro的两大核心功能是Specs(规范)和Hooks(开发钩子)

60%
Unverified

Gemini CLI's hook mechanism can intercept AI-generated content before it is written to disk, which constitutes a Shift-Left Security practice.

60%
Unverified

Gemini CLI addresses AI coding control issues through three key features: Hooks, Skills, and Plan Mode.

60%
Unverified

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.

50%
Unverified

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.

50%

Source Articles