Skip to content

Fix: Persist total API cost after message deletion#5523

Merged
kevinvandijk merged 18 commits intoKilo-Org:mainfrom
abdulrahimpds:fix/persist-delete-api-costs
Feb 12, 2026
Merged

Fix: Persist total API cost after message deletion#5523
kevinvandijk merged 18 commits intoKilo-Org:mainfrom
abdulrahimpds:fix/persist-delete-api-costs

Conversation

@abdulrahimpds
Copy link
Contributor

This PR fixes an issue where the "Total API Cost" would incorrectly decrease when chat messages were deleted, instead of showing the real resource usage for the session. The cost tracking now keeps costs from deleted messages.

  • Backend (Task.ts): Added a _deletedApiCost property to keep track of costs from deleted messages and updated getTokenUsage to include this value.
  • Logic (webviewMessageHandler.ts): Hooked into message deletion to calculate and save the cost of messages before they are removed.
  • Frontend (ChatView.tsx): Updated the cost display to use the backend’s currentTaskCumulativeCost as the source of truth instead of recalculating it from the visible messages.

The "Total API Cost" now correctly shows the full cost of the session, even if messages are deleted.

@changeset-bot
Copy link

changeset-bot bot commented Jan 29, 2026

🦋 Changeset detected

Latest commit: 90a4495

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kilo-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Collaborator

@kevinvandijk kevinvandijk left a comment

Choose a reason for hiding this comment

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

Thanks @abdulrahimpds! It took a while to get around to this one but nice fix. If you feel like, reach out to me on Discord (Kevin) with the email address you used to sign up for Kilo so I can grant you some credits as a token of our appreciation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants