feat: expose current context tokens in session data#4
Closed
AaronGoldsmith wants to merge 3 commits intoblock:mainfrom
Closed
feat: expose current context tokens in session data#4AaronGoldsmith wants to merge 3 commits intoblock:mainfrom
AaronGoldsmith wants to merge 3 commits intoblock:mainfrom
Conversation
The UI was displaying accumulated_total_tokens (sum of input tokens across every API call) instead of total_tokens (current context window size). This made sessions appear to use 10-100x more tokens than they actually had in context — e.g. showing 1M+ tokens for a session whose context was only ~10K. Now the per-session cards show current context size, and the clockworks status bar shows both: "34.5K ctx / 390K tot" so you can see both the live context and cumulative usage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The children query now fetches total_tokens (current context window size) in addition to accumulated_total_tokens (per-session cumulative usage). The new field is available as tokens_current on each child and stats.tokens.current in the SSE payload. No UI changes — existing display continues to use accumulated_total_tokens via the tokens field. Confirmed semantics in block/goose reply_parts.rs: total_tokens is set from the latest API response (resets after compaction), while accumulated_total_tokens sums each call's usage onto the session total. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73e6e46ed6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
10 tasks
Addresses PR feedback: tokens_current wasn't part of the hash used to detect tree changes, so SSE events wouldn't fire when only total_tokens changed (e.g. after context compaction). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
Closing - no movement in 2 weeks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
total_tokens(current context window size) alongsideaccumulated_total_tokens(per-session cumulative API usage)tokens_currentper child session,stats.tokens.currentfor the aggregateaccumulated_total_tokensvia the existingtokensfieldContext
The goose sessions DB tracks two token metrics per session:
total_tokens— current context window size. Resets after compaction.accumulated_total_tokens— running sum of tokens across all API calls within the session. Only grows.Previously the server only queried
accumulated_total_tokensfor child sessions. This addstotal_tokensto the query so both values are available to the frontend. Confirmed the semantics inblock/goose reply_parts.rs—total_tokensis set from the latest API response, whileaccumulated_total_tokensuses an additiveaccumulate()helper.Test plan
tokens_currentfield is populated from DB (checked againstsqlite3query of real sessions)accumulated_totalas before🤖 Generated with Claude Code