Skip to content

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

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

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


readonly agent: LocalAgent;

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


toolUse: ToolUseData;

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


readonly tool: Tool;

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


readonly invocationState: InvocationState;

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


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

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

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