Events

tool_start

{ type: "tool_start", id, tool, category, args }

A tool is about to run, with the arguments it will run with. It arrives after any permission was granted — so seeing it means the call is happening.

after the permissionargs are finalpaired with tool_end
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Fields

idstring

The call's identifier. tool_end carries the same one.

toolstring

The tool's name.

categorystring

Its category — computed from the arguments for six of them.

argsobject

Exactly what it will run with.

Pairing it

const started = new Map();

onEvent: (e) => {
  if (e.type === "tool_start") started.set(e.id, { tool: e.tool, at: Date.now(), args: e.args });
  if (e.type === "tool_end")   {
    const call = started.get(e.id);
    console.log(call.tool, e.ok ? "ok" : "failed", e.durationMs, "ms");
    started.delete(e.id);
  }
};
import time

started = {}

def on_event(event):
    if event["type"] == "tool_start":
        started[event["id"]] = {"tool": event["tool"], "at": time.monotonic(), "args": event["args"]}
    if event["type"] == "tool_end":
        call = started.pop(event["id"])
        print(call["tool"], "ok" if event["ok"] else "failed", round((time.monotonic() - call["at"]) * 1000), "ms")
Not every tool_end has a tool_start

A refused call and a call to an unknown tool emit only tool_end. Pair by id and tolerate an end with no start, or a dangling entry will sit in your map forever.

Several can be open at once

In a turn where every call is a read or a task, the engine runs them together — so you may see several tool_start before the first tool_end, and the ends arrive in completion order, not call order. Keying on id is what makes that harmless.

The arguments are the display

args.path, args.command, args.query, args.pattern, args.key — the one meaningful string is what an interface shows beside the tool's name. The session record keeps the same idea as a short target.

A subagent's events arrive here too

They carry parentId — the identifier of the task call that started them — and agent, its name. Their own id is prefixed with the task's, so two runs never collide. Test parentId before treating an event as the main run's.