Skip to content

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 name is changed and selectedTool is not set, the tool is re-resolved from the registry under the new name.
  • Interruptible
new BeforeToolCallEvent(data): BeforeToolCallEvent;

Defined in: src/hooks/events.ts:269

ParameterType
data{ agent: LocalAgent; toolUse: ToolUseData; tool: Tool; invocationState: InvocationState; }
data.agentLocalAgent
data.toolUseToolUseData
data.toolTool
data.invocationStateInvocationState

BeforeToolCallEvent

HookableEvent.constructor

readonly type: "beforeToolCallEvent";

Defined in: src/hooks/events.ts:245


readonly agent: LocalAgent;

Defined in: src/hooks/events.ts:246


toolUse: ToolUseData;

Defined in: src/hooks/events.ts:247


readonly tool: Tool;

Defined in: src/hooks/events.ts:248


readonly invocationState: InvocationState;

Defined in: src/hooks/events.ts:249


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: 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.

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 ParameterDefault type
TJSONValue
ParameterTypeDescription
paramsInterruptParamsInterrupt parameters including name and optional reason

T

The user’s response when resuming from an interrupt

Interruptible.interrupt

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().

Pick<BeforeToolCallEvent, "type" | "toolUse">