BeforeToolCallEvent
Defined in: src/hooks/events.ts:242
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”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new BeforeToolCallEvent(data): BeforeToolCallEvent;Defined in: src/hooks/events.ts:267
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:243
readonly agent: LocalAgent;Defined in: src/hooks/events.ts:244
toolUse
Section titled “toolUse”toolUse: ToolUseData;Defined in: src/hooks/events.ts:245
readonly tool: Tool;Defined in: src/hooks/events.ts:246
invocationState
Section titled “invocationState”readonly invocationState: InvocationState;Defined in: src/hooks/events.ts:247
cancel
Section titled “cancel”cancel: string | boolean = false;Defined in: src/hooks/events.ts:254
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:265
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”toJSON()
Section titled “toJSON()”toJSON(): Pick<BeforeToolCallEvent, "type" | "toolUse">;Defined in: src/hooks/events.ts:285
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">