diff --git a/EVENTS.md b/EVENTS.md index 1a73b10..40d5435 100644 --- a/EVENTS.md +++ b/EVENTS.md @@ -92,7 +92,7 @@ Emitted when extended thinking content is complete (requires `--thinking` flag). ### `tool_use` -Emitted when a tool call completes (success or error). +Emitted when a tool call completes (success or error). This includes tools executed within subagent sessions. ```json { @@ -100,6 +100,7 @@ Emitted when a tool call completes (success or error). "part": { "type": "tool", "tool": "bash", + "sessionID": "session_01abc...", "state": { "status": "completed", "input": { "command": "ls" }, @@ -111,6 +112,8 @@ Emitted when a tool call completes (success or error). `state.status` is `"completed"` or `"error"`. On error, `state.error` contains the error message. +For tools executed inside a subagent, `part.sessionID` will differ from the top-level `sessionID` — compare the two to identify subagent tool calls. + ### `step_start` / `step_finish` Emitted at step boundaries during multi-step tool use. diff --git a/packages/cli/src/cli/cmd/run.ts b/packages/cli/src/cli/cmd/run.ts index ddf1fe7..8679e6b 100644 --- a/packages/cli/src/cli/cmd/run.ts +++ b/packages/cli/src/cli/cmd/run.ts @@ -475,7 +475,19 @@ export const RunCommand = cmd({ if (event.type === "message.part.updated") { const part = event.properties.part - if (part.sessionID !== sessionID) continue + + // Skip non-primary session events, but emit tool_use for subagent sessions in JSON mode + if (part.sessionID !== sessionID) { + if ( + args.format === "json" && + childSessions.has(part.sessionID) && + part.type === "tool" && + (part.state.status === "completed" || part.state.status === "error") + ) { + emit("tool_use", { part }) + } + continue + } if (part.type === "tool" && (part.state.status === "completed" || part.state.status === "error")) { if (emit("tool_use", { part })) continue