From 90a34f6e6a2718ab2d63f2474fe6c7b35f7a57f9 Mon Sep 17 00:00:00 2001 From: Javier Coll Date: Wed, 11 Feb 2026 22:28:02 +0100 Subject: [PATCH 1/3] fix: prevent context token indicator flickering Fixed a bug where the context token indicator would flicker to 0% when a new API request started. The issue occurred because the loop would break on placeholder messages without valid token data instead of continuing to search for the last complete message with token data. Affected: packages/core/src/message-utils/consolidateTokenUsage.ts --- .changeset/fix-context-flickering.md | 7 +++++++ packages/core/src/message-utils/consolidateTokenUsage.ts | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 .changeset/fix-context-flickering.md diff --git a/.changeset/fix-context-flickering.md b/.changeset/fix-context-flickering.md new file mode 100644 index 00000000000..49fd304428a --- /dev/null +++ b/.changeset/fix-context-flickering.md @@ -0,0 +1,7 @@ +--- +"@roo-code/core": patch +--- + +fix: prevent context token indicator flickering + +Fixed a bug where the context token indicator would flicker to 0% when a new API request started. The issue occurred because the loop would break on placeholder messages without valid token data instead of continuing to search for the last complete message with token data. diff --git a/packages/core/src/message-utils/consolidateTokenUsage.ts b/packages/core/src/message-utils/consolidateTokenUsage.ts index 7f1a324b376..803b228ebcd 100644 --- a/packages/core/src/message-utils/consolidateTokenUsage.ts +++ b/packages/core/src/message-utils/consolidateTokenUsage.ts @@ -112,21 +112,16 @@ export function consolidateTokenUsage(messages: ClineMessage[]): TokenUsage { const hasTokenData = typeof tokensIn === "number" || typeof tokensOut === "number" if (hasTokenData) { - // Since tokensIn now stores TOTAL input tokens (including cache tokens), - // we no longer need to add cacheWrites and cacheReads separately. - // This applies to both Anthropic and OpenAI protocols. result.contextTokens = (tokensIn || 0) + (tokensOut || 0) foundValidTokenData = true + break } } catch { - // Ignore JSON parse errors continue } } else if (message.type === "say" && message.say === "condense_context") { result.contextTokens = message.contextCondense?.newContextTokens ?? 0 foundValidTokenData = true - } - if (foundValidTokenData) { break } } From 7bcc15813a166f6bf01a7ef0009c062d4b5cc164 Mon Sep 17 00:00:00 2001 From: Kevin van Dijk Date: Thu, 12 Feb 2026 16:16:19 +0100 Subject: [PATCH 2/3] Apply suggestion from review --- .changeset/fix-context-flickering.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fix-context-flickering.md b/.changeset/fix-context-flickering.md index 49fd304428a..8b6798cdd70 100644 --- a/.changeset/fix-context-flickering.md +++ b/.changeset/fix-context-flickering.md @@ -1,5 +1,5 @@ --- -"@roo-code/core": patch +"kilo-code": patch --- fix: prevent context token indicator flickering From 22fc3a4527ac0a8931cb09d6225b04aa99d8ce64 Mon Sep 17 00:00:00 2001 From: Kevin van Dijk Date: Thu, 12 Feb 2026 16:47:06 +0100 Subject: [PATCH 3/3] Fix linting issue --- packages/core/src/message-utils/consolidateTokenUsage.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/core/src/message-utils/consolidateTokenUsage.ts b/packages/core/src/message-utils/consolidateTokenUsage.ts index 803b228ebcd..6f8ac9f2789 100644 --- a/packages/core/src/message-utils/consolidateTokenUsage.ts +++ b/packages/core/src/message-utils/consolidateTokenUsage.ts @@ -99,7 +99,6 @@ export function consolidateTokenUsage(messages: ClineMessage[]): TokenUsage { // with only apiProtocol (no token data). We need to skip these placeholders and // find the last message with actual token data to avoid showing 0% context. result.contextTokens = 0 - let foundValidTokenData = false for (let i = messages.length - 1; i >= 0; i--) { const message = messages[i] @@ -113,7 +112,6 @@ export function consolidateTokenUsage(messages: ClineMessage[]): TokenUsage { if (hasTokenData) { result.contextTokens = (tokensIn || 0) + (tokensOut || 0) - foundValidTokenData = true break } } catch { @@ -121,7 +119,6 @@ export function consolidateTokenUsage(messages: ClineMessage[]): TokenUsage { } } else if (message.type === "say" && message.say === "condense_context") { result.contextTokens = message.contextCondense?.newContextTokens ?? 0 - foundValidTokenData = true break } }