From 499ee22b3b85cba952a8e2fac6dce09fec10cf54 Mon Sep 17 00:00:00 2001 From: Bee <68532117+abeatrix@users.noreply.github.com> Date: Wed, 19 Nov 2025 02:54:31 -0800 Subject: [PATCH] fix(task): update UI with final usage after stream completion (#7552) Ensure the UI displays accurate token usage and costs by updating the API request message when the stream completes. This commit adds a call to updateApiReqMsg followed by saving messages and posting state to the webview, which occurs before finalizing tool calls. This ensures users see the final usage statistics (input/output tokens, cache tokens, and total cost) reflected in the interface immediately after stream processing. --- src/core/task/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/core/task/index.ts b/src/core/task/index.ts index 620f5778..4b8d7906 100644 --- a/src/core/task/index.ts +++ b/src/core/task/index.ts @@ -2960,6 +2960,20 @@ export class Task { } } + // Update UI with final usage after stream is complete + await updateApiReqMsg({ + messageStateHandler: this.messageStateHandler, + lastApiReqIndex, + inputTokens, + outputTokens, + cacheWriteTokens, + cacheReadTokens, + api: this.api, + totalCost, + }) + await this.messageStateHandler.saveClineMessagesAndUpdateHistory() + await this.postStateToWebview() + // Finalize any remaining tool calls at the end of the stream if (this.useNativeToolCalls) { // For native tool calls, mark all pending tool uses as complete