Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-context-flickering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"kilo-code": 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.
10 changes: 1 addition & 9 deletions packages/core/src/message-utils/consolidateTokenUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -112,21 +111,14 @@ 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
}
}
Expand Down
Loading