[KongchangAI]
Conceptprompt hook / agent hook / 事件钩子

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)

Nov 7

Hook commands receive a JSON description of the event via standard input, can control flow via exit codes, and exit code 2 means blocking the operation and feeding stderr back to Claude.

Unverified50%
Nov 7

Hooks execute in the local shell, have the user's permissions, and do not consume model tokens.

Unverified50%
Nov 7

Claude Code's Hook mechanism allows user-defined scripts to run automatically at specific lifecycle points (such as before a tool call, after a tool call, or at session start); configuration goes in the hooks field of settings.json, and scripts go in the agreed directory.

Unverified50%
Nov 5

Among the components Harness covers, orchestration logic, hooks, and middleware are the most easily underestimated parts, as they determine when the model is called, what context it receives, and how its output is intercepted and corrected.

Unverified50%
Oct 23

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.

Unverified50%
Oct 23

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.

Unverified60%
Oct 18

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.

Unverified50%
Oct 12

Policy hooks are an extension mechanism provided by coding agents: developers attach custom scripts or functions before and after the agent executes a tool call, to audit, modify, or even veto the operation.

Unverified60%
Oct 8

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.

Unverified50%
Oct 8

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.

Unverified70%

8 more timeline events

All Facts (20)

Unverified

Hooks配置在.claude/settings.json中,可提交到代码仓库实现团队共享

90%
Unverified

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.

70%
Unverified

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.

60%
Unverified

Policy hooks are an extension mechanism provided by coding agents: developers attach custom scripts or functions before and after the agent executes a tool call, to audit, modify, or even veto the operation.

60%
Unverified

Hook event types include PreToolUse, PostToolUse, and Notification; if a PreToolUse script returns exit code 2, the tool call is blocked.

60%
Unverified

Hooks are a deterministic mechanism enforced by the Claude Code software, do not rely on model judgment, and can guarantee 100% execution.

60%
Unverified

Claude Code内置了Hook机制,允许开发者在请求发送到模型之前拦截并处理输入内容

60%
Unverified

Hook commands receive a JSON description of the event via standard input, can control flow via exit codes, and exit code 2 means blocking the operation and feeding stderr back to Claude.

50%
Unverified

Hooks execute in the local shell, have the user's permissions, and do not consume model tokens.

50%
Unverified

Claude Code's Hook mechanism allows user-defined scripts to run automatically at specific lifecycle points (such as before a tool call, after a tool call, or at session start); configuration goes in the hooks field of settings.json, and scripts go in the agreed directory.

50%
Unverified

Among the components Harness covers, orchestration logic, hooks, and middleware are the most easily underestimated parts, as they determine when the model is called, what context it receives, and how its output is intercepted and corrected.

50%
Unverified

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.

50%
Unverified

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.

50%
Unverified

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.

50%
Unverified

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.

50%
Unverified

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.

50%
Unverified

Without hook injection, even if the Skill files are in place, the Agent will not actively call them.

50%
Unverified

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.

50%
Unverified

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.

50%
Unverified

The 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%

Source Articles