Hook
An event-driven interception mechanism in Claude Code that allows developers to insert custom inspection logic at specific execution points, such as before tool calls or when a task stops. Rules can be described in natural language, which the model interprets and enforces at runtime.
Timeline (last 90 days)
For things that absolutely must not happen (such as pushing to the main branch), writing them in Markdown is merely a request; a hook or permission setting should be used to enforce it.
Hooks are scripts automatically executed at specific lifecycle events that can intercept, modify or reject an operation; permission settings declare which commands, paths or tools can run without asking, which must be manually confirmed, and which are completely forbidden; both are enforced by the runtime and do not rely on the model voluntarily complying.
DSupport's guardrails are deterministic code running at three fixed points in the agent loop, exposing three aspects—beforeTool, afterTool, and beforeFinal—through the Hook interface, and each aspect can allow, reject, or modify.
Claude Code v2.1.295 introduces the onFailure: "block" option for command-type and HTTP-type Hooks, which allows a failed Hook to directly block the corresponding operation.
v2.1.295 fixes the issue where a mod's Hook received truncated deeply nested tool input without any error, as well as the vulnerability where a guard Hook with .catch was bypassed during plugin worker restarts.
Previously, a Hook failure was a soft failure (the operation continued to proceed); onFailure: "block" allows a Hook to declare a hard failure, defaulting to a fail-closed rather than fail-open strategy when infrastructure failures occur.
Without hook injection, even if the Skill files are in place, the Agent will not actively call them.
For hook injection, the recommended first choice is automatic Hook injection; if the IDE does not support hooks, writing to a rules file (such as agents.md) serves as the fallback solution.
Root or hook solutions are the fastest and most stable, but require flashing the device, carry the risk of account bans, and hook implementations often break after WeChat upgrades.
For high-risk operations such as deleting data, charging fees, and mass messaging, lifecycle hooks should be designed to automatically pause and return control to a human when triggered.
6 more timeline events
All Facts (17)
Claude Code内置了Hook机制,允许开发者在请求发送到模型之前拦截并处理输入内容
60%UnverifiedFor things that absolutely must not happen (such as pushing to the main branch), writing them in Markdown is merely a request; a hook or permission setting should be used to enforce it.
50%UnverifiedHooks are scripts automatically executed at specific lifecycle events that can intercept, modify or reject an operation; permission settings declare which commands, paths or tools can run without asking, which must be manually confirmed, and which are completely forbidden; both are enforced by the runtime and do not rely on the model voluntarily complying.
50%UnverifiedDSupport's guardrails are deterministic code running at three fixed points in the agent loop, exposing three aspects—beforeTool, afterTool, and beforeFinal—through the Hook interface, and each aspect can allow, reject, or modify.
50%Unverifiedv2.1.295 fixes the issue where a mod's Hook received truncated deeply nested tool input without any error, as well as the vulnerability where a guard Hook with .catch was bypassed during plugin worker restarts.
50%UnverifiedClaude Code v2.1.295 introduces the onFailure: "block" option for command-type and HTTP-type Hooks, which allows a failed Hook to directly block the corresponding operation.
50%UnverifiedPreviously, a Hook failure was a soft failure (the operation continued to proceed); onFailure: "block" allows a Hook to declare a hard failure, defaulting to a fail-closed rather than fail-open strategy when infrastructure failures occur.
50%UnverifiedFor hook injection, the recommended first choice is automatic Hook injection; if the IDE does not support hooks, writing to a rules file (such as agents.md) serves as the fallback solution.
50%UnverifiedWithout hook injection, even if the Skill files are in place, the Agent will not actively call them.
50%UnverifiedRoot or hook solutions are the fastest and most stable, but require flashing the device, carry the risk of account bans, and hook implementations often break after WeChat upgrades.
50%UnverifiedFor high-risk operations such as deleting data, charging fees, and mass messaging, lifecycle hooks should be designed to automatically pause and return control to a human when triggered.
50%UnverifiedThe cross-framework portability of the Ledger depends on the Agent framework providing Hook capabilities, with the remaining functionality implemented through contracts and tools, decoupled from the specific orchestration engine.
50%UnverifiedThe two pathways for data to enter the Ledger are: automatic capture of tool errors via a Hook mechanism, and manual retrospectives initiated by user commands.
50%UnverifiedHook技术在JavaScript逆向中的常用方式包括重写document.cookie的setter/getter、重写XMLHttpRequest或fetch方法、使用Object.defineProperty劫持特定对象的属性访问
50%UnverifiedHook 设定档使用 JSON 格式,通常放在专案资料夹的 .claude/settings.json 中
50%UnverifiedHook 是确定性的机制,由 Claude Code 软件强制执行,不依赖模型判断,能保证100%执行
50%UnverifiedHook 的三层架构为 Event(决定何时触发)、Matcher(决定拦截哪个操作)、Handler(决定执行什么动作)
50%