@@ -679,9 +679,10 @@ function promptToClaude(prompt: PromptRequest): SDKUserMessage {
679679}
680680
681681/**
682- * Return an ACP update for the tool use if both the structured output from the hook and the raw output have been received.
682+ * Return an ACP update for the tool use if both the structured output from the hook
683+ * and the raw output from `tool_result` have been received.
683684 */
684- function outputUpdateIfReady ( toolUse : CachedToolUse ) : SessionNotification [ "update" ] | undefined {
685+ function structuredOutputUpdate ( toolUse : CachedToolUse ) : SessionNotification [ "update" ] | undefined {
685686 if ( ! toolUse . toolResponse || ! toolUse . output ) {
686687 // Wait for both output formats to be available before broadcasting the update.
687688 return undefined ;
@@ -784,7 +785,7 @@ export function toAcpNotifications(
784785 const toolUse = toolUseCache [ toolUseId ] ;
785786 if ( toolUse ) {
786787 toolUse . toolResponse = toolResponse ;
787- const update = outputUpdateIfReady ( toolUse ) ;
788+ const update = structuredOutputUpdate ( toolUse ) ;
788789 if ( update ) {
789790 await client . sessionUpdate ( {
790791 sessionId,
@@ -836,10 +837,20 @@ export function toAcpNotifications(
836837 break ;
837838 }
838839 if ( toolUse . name !== "TodoWrite" ) {
840+ update = {
841+ toolCallId : chunk . tool_use_id ,
842+ sessionUpdate : "tool_call_update" ,
843+ status : "is_error" in chunk && chunk . is_error ? "failed" : "completed" ,
844+ ...toolUpdateFromToolResult ( chunk , toolUseCache [ chunk . tool_use_id ] ) ,
845+ } ;
846+ // We expect to receive `tool_result` before the post-tool hook is called based on empirical observation.
847+ // But there is no strong guarantee about this ordering.
848+ // So here we check if the post-tool hook has already been called, and also send the structured output update if it has.
839849 toolUse . output = chunk ;
840- const update = outputUpdateIfReady ( toolUse ) ;
841- if ( update ) {
850+ const additionalUpdate = structuredOutputUpdate ( toolUse ) ;
851+ if ( additionalUpdate ) {
842852 output . push ( { sessionId, update } ) ;
853+ update = additionalUpdate ;
843854 }
844855 }
845856 break ;
0 commit comments