Skip to content
Merged
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
9 changes: 1 addition & 8 deletions src/core/task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,9 @@ export class Task extends EventEmitter<ClineEvents> {
if (!summary) {
return
}
const lastMessageContent = this.apiConversationHistory.at(-1)?.content
await this.overwriteApiConversationHistory(messages)
const { contextTokens } = this.getTokenUsage()
const lastContent =
typeof lastMessageContent === "string"
? [{ type: "text" as const, text: lastMessageContent }]
: lastMessageContent
const lastMessageTokens = lastContent ? await this.api.countTokens(lastContent) : 0
const prevContextTokens = contextTokens + lastMessageTokens
const contextCondense: ContextCondense = { summary, cost, newContextTokens, prevContextTokens }
const contextCondense: ContextCondense = { summary, cost, newContextTokens, prevContextTokens: contextTokens }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the extra token count for the last message avoids double counting during manual condense, which is the intended fix. Consider adding a brief comment explaining that getTokenUsage() already accounts for the last message, so there's no need to add extra tokens.

await this.say(
"condense_context",
undefined /* text */,
Expand Down
Loading