Skip to content

Issue #10567: Record token usage and optionally display for turn/session/history#10568

Open
benjschiller wants to merge 2 commits intocontinuedev:mainfrom
benjschiller:10567-token-usage-tracking
Open

Issue #10567: Record token usage and optionally display for turn/session/history#10568
benjschiller wants to merge 2 commits intocontinuedev:mainfrom
benjschiller:10567-token-usage-tracking

Conversation

@benjschiller
Copy link
Copy Markdown

@benjschiller benjschiller commented Feb 17, 2026

Description

Address issue #10567

Adds token usage persistence/display improvements in VS Code Chat + History with a single display setting and turn/session/history granularity.

I used codex to help me to do this cause my typescript is is rusty. This is my first PR for continue, so please let me know anything I can do to conform better to your flow! Open to adding support for JetBrains if desired.

Main changes:

  • Added a unified setting: continue.showTokenUsage with values:
    • never
    • history
    • session (history + session)
    • turn (history + session + turn)
  • Made setting behavior dynamic via ideSettingsUpdate so UI updates immediately without manual window reload.
  • Persisted usage in session artifacts:
    • per assistant turn (message.usage in session history)
    • per session totals (session.usage)
    • mirrored in sessions.json metadata (BaseSessionMetadata.usage)
  • Added history usage display:
    • per time bucket group rows (Today / This Week / etc.)
    • per session row, styled to match existing repo/folder secondary text
  • Added session usage summary in Chat and turn-level footer display based on setting mode.
  • Standardized wording to “Tokens used” and “turn” terminology.
  • Kept existing stats database/schema intact; updated stats page wording to clarify that stats totals are local analytics totals and may differ from visible session totals.
  • Extended provider usage extraction where available (including OpenAI-compatible usage paths and provider-specific mappings implemented in this change).

Scope notes:

  • Token tracking is "always on", setting controls display only
  • No database migration introduced.

AI Code Review

  • Team members only: AI review runs automatically when PR is opened or marked ready for review
  • Team members can also trigger a review by commenting @continue-review

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created
  • The relevant tests, if any, have been updated or created

Screen recording or screenshot

Turn + session token usage display
image

History token usage display
image

help->stats (added consistency warning)
image

new config option
image

Tests

Manual testing: ran extension in debug mode and checked that features appear and work as expected

Automated testing below

Updated tests:

  • core/llm/openaiTypeConverters.test.ts
    • added coverage for usage extraction from non-stream and usage-only stream chunks
  • gui/src/redux/slices/sessionSlice.test.ts
    • added coverage for persisting assistant usage on normal and usage-only stream updates

Local checks run:

  • npm run format:check (repo root)
  • cd core && npx tsc --noEmit
  • cd core && npm run lint
  • cd core && npm run vitest
  • cd gui && npx tsc --noEmit
  • cd gui && npm run lint
  • cd gui && npm test
  • cd binary && npx tsc --noEmit
  • cd extensions/vscode && npm run write-build-timestamp
  • cd extensions/vscode && npx tsc --noEmit
  • cd extensions/vscode && npm run lint
  • cd extensions/vscode && npm run vitest
  • node ./scripts/build-packages.js
  • cd extensions/vscode && npm run e2e:compile
  • package tests run across packages/* (with npm ci where needed)

Note:

  • cd core && npm test had an environment-specific network failure in this local machine (ENOTFOUND to Sentry host in llm/countTokens.test.ts), not tied to this feature logic.

Continue Tasks: ✅ 1 no changes — View all


Summary by cubic

Adds per-turn, per-session, and history token usage tracking with a single display setting in VS Code, updated live without reload. Addresses Issue #10567.

  • New Features

    • Added setting: continue.showTokenUsage = "never" | "history" | "session" | "turn" (tracking always on; setting controls visibility).
    • Live UI updates via ideSettingsUpdate (webview passthrough added).
    • Persist usage in assistant turns, session metadata, and prompt logs; hydrate usage for older sessions on load.
    • History shows totals per time group and per session; Chat shows a session summary and per-turn footer based on the setting.
    • Extract and attach provider usage for OpenAI, Anthropic, Bedrock, Cohere, Gemini, and Ollama (streaming and non-stream paths).
    • Updated docs and tests for usage parsing, display, and persistence.
  • Bug Fixes

    • Fallback to local token counting when providers return zero usage, preventing undercounting.
    • Improved history hydration to backfill session usage from saved turns.
    • Ensured ide settings changes propagate to the webview immediately.
  • Migration

    • No migration required. Default setting is "never".

Written for commit a4aaf9d. Summary will update on new commits.

@benjschiller benjschiller requested a review from a team as a code owner February 17, 2026 04:39
@benjschiller benjschiller requested review from RomneyDa and removed request for a team February 17, 2026 04:39
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Feb 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 17, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

3 issues found across 31 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="core/protocol/passThrough.ts">

<violation number="1" location="core/protocol/passThrough.ts:114">
P2: IntelliJ PASS_THROUGH_TO_WEBVIEW is missing the new "ideSettingsUpdate" message type added to CORE_TO_WEBVIEW_PASS_THROUGH, so JetBrains clients won’t receive this update.</violation>
</file>

<file name="core/util/history.ts">

<violation number="1" location="core/util/history.ts:43">
P2: list() now hydrates usage for every session with synchronous disk reads before applying limit/offset, causing O(n) blocking I/O even when only a small slice is requested.</violation>
</file>

<file name="core/llm/index.ts">

<violation number="1" location="core/llm/index.ts:360">
P2: `_logEnd` now trusts numeric usage token counts, but upstream usage parsing normalizes missing values to 0. When prompt/completion counts are absent, this bypasses `countTokens` and records 0 tokens, undercounting batching/logging.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

"didCloseFiles",
"toolCallPartialOutput",
"freeTrialExceeded",
"ideSettingsUpdate",
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 17, 2026

Choose a reason for hiding this comment

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

P2: IntelliJ PASS_THROUGH_TO_WEBVIEW is missing the new "ideSettingsUpdate" message type added to CORE_TO_WEBVIEW_PASS_THROUGH, so JetBrains clients won’t receive this update.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At core/protocol/passThrough.ts, line 114:

<comment>IntelliJ PASS_THROUGH_TO_WEBVIEW is missing the new "ideSettingsUpdate" message type added to CORE_TO_WEBVIEW_PASS_THROUGH, so JetBrains clients won’t receive this update.</comment>

<file context>
@@ -111,4 +111,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] =
     "didCloseFiles",
     "toolCallPartialOutput",
     "freeTrialExceeded",
+    "ideSettingsUpdate",
   ];
</file context>
Fix with Cubic

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

  • Added "ideSettingsUpdate" to IntelliJ PASS_THROUGH_TO_WEBVIEW to match core passthrough updates.
  • File: extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt

@benjschiller
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@benjschiller
Copy link
Copy Markdown
Author

Checking if there's anything else I need to do. I believe the failing CI checks were not due to the PR

Copy link
Copy Markdown
Contributor

@RomneyDa RomneyDa left a comment

Choose a reason for hiding this comment

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

@benjschiller some merge conflicts popped up but otherwise might take a while to review. The main concern is it touches many providers and the UI. A smaller set of targeted PRs e.g. usage per provider, then UI could go through quicker.

note removing as any type casting is also a soft requirement for new code, applies to many files in this PR.

@benjschiller
Copy link
Copy Markdown
Author

@benjschiller some merge conflicts popped up but otherwise might take a while to review. The main concern is it touches many providers and the UI. A smaller set of targeted PRs e.g. usage per provider, then UI could go through quicker.

note removing as any type casting is also a soft requirement for new code, applies to many files in this PR.

you got it @RomneyDa , I'll work on that this week. I'll clean up the typing too, that's AI slop and tbh I didn't notice it because I usually work in Python. I can at least break this into separate backend + frontend PRs. I need to noodle on breaking up the backend changes per provider, since there's some model changes that touch many providers

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

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants