BeforeToolCallEvent
Defined in: src/hooks/events.ts:244
Event triggered just before a tool is executed. Fired after tool lookup but before execution begins.
Hook callbacks can:
- Set cancel to prevent the tool from executing.
- Set selectedTool to execute a different tool in place of the registry’s match.
- Mutate toolUse to rewrite the tool input, id, or name before execution.
If
nameis changed andselectedToolis not set, the tool is re-resolved from the registry under the new name.
Extends
Section titled “Extends”Implements
Section titled “Implements”Interruptible
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new BeforeToolCallEvent(data): BeforeToolCallEvent;Defined in: src/hooks/events.ts:269
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data | { agent: LocalAgent; toolUse: ToolUseData; tool: Tool; invocationState: InvocationState; } |
data.agent | LocalAgent |
data.toolUse | ToolUseData |
data.tool | Tool |
data.invocationState | InvocationState |
Returns
Section titled “Returns”BeforeToolCallEvent
Overrides
Section titled “Overrides”Properties
Section titled “Properties”readonly type: "beforeToolCallEvent";Defined in: src/hooks/events.ts:245
readonly agent: LocalAgent;Defined in: src/hooks/events.ts:246
toolUse
Section titled “toolUse”toolUse: ToolUseData;Defined in: src/hooks/events.ts:247
readonly tool: Tool;Defined in: src/hooks/events.ts:248
invocationState
Section titled “invocationState”readonly invocationState: InvocationState;Defined in: src/hooks/events.ts:249
cancel
Section titled “cancel”cancel: string | boolean = false;Defined in: src/hooks/events.ts:256
Set by hook callbacks to cancel this tool call.
When set to true, a default cancel message is used.
When set to a string, that string is used as the tool result error message.
selectedTool
Section titled “selectedTool”selectedTool: Tool = undefined;Defined in: src/hooks/events.ts:267
Set by hook callbacks to execute a replacement tool instead of tool.
When undefined, the tool looked up from the registry (or re-resolved from a
mutated toolUse.name) is used.
If multiple callbacks set selectedTool, the last callback to run wins.
Callbacks run in registration order for this event, so the last-registered
callback’s value is the one used.
Methods
Section titled “Methods”interrupt()
Section titled “interrupt()”interrupt<T>(params): T;Defined in: src/hooks/events.ts:290
Raises an interrupt for human-in-the-loop workflows. If a response is available (from a previous resume), returns it immediately. Otherwise, throws an InterruptError to halt agent execution.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
T | JSONValue |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
params | InterruptParams | Interrupt parameters including name and optional reason |
Returns
Section titled “Returns”T
The user’s response when resuming from an interrupt
Implementation of
Section titled “Implementation of”Interruptible.interrupttoJSON()
Section titled “toJSON()”toJSON(): Pick<BeforeToolCallEvent, "type" | "toolUse">;Defined in: src/hooks/events.ts:299
Serializes for wire transport, excluding the agent reference, tool instance, invocationState, and mutable cancel / selectedTool fields. Called automatically by JSON.stringify().
Returns
Section titled “Returns”Pick<BeforeToolCallEvent, "type" | "toolUse">