Skip to content

fix: quota-weight quickstart headline, drop named-session reclaim list - #437

Merged
anshss merged 2 commits into
ticket-120from
ticket-119
Jul 9, 2026
Merged

anshss merged 2 commits into
ticket-120from
ticket-119

Conversation

@anshss

@anshss anshss commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two independent fixes to tj quickstart's "Where your quota goes" box, kept in one PR because they touch the same _render section.

(a) Headline was raw tokens mislabeled as quota. diag.reread_share is total_reread_tokens / total_tokens — a raw token share. Cache-read tokens are billed at a fraction of a base input token in both API pricing and Anthropic's subscription rate-limit weighting (every current model row in tokenjam/pricing/models.toml prices cache reads at 0.1x input, output at 5x — consistent across the whole table, not a per-model coincidence). Reporting the raw share as "quota" overstates re-reading's real cost.

Added quota_weighted_reread_share / quota_weighted_work_share (backed by quota_weighted_tokens) to TurnComposition and ContextDiagnostic in tokenjam/core/context_diagnostic.py, using two named constants (CACHE_READ_QUOTA_WEIGHT = 0.1, OUTPUT_QUOTA_WEIGHT = 5.0) with a comment citing the pricing table. Chose to weight the computation rather than just retitle the box — the whole point of tokenjam's quota-native framing is that the number should mean what it says; retitling to "raw tokens" abandons that thesis instead of fixing the mismatch. The raw reread_share/total_tokens properties are untouched, so tj context and tj tokenmaxx (which still use them) are unaffected — only quickstart's headline now reads quota-weighted. New fields also round-trip into the --json payload.

Verified against my own ~/.claude/projects history (61 sessions, 8823 turns): raw reread_share = 94.98% (matches the reported "95.0%" figure almost exactly) vs. quota_weighted_reread_share = 57.46% — a much bigger correction than the original back-of-envelope "~92%" estimate, because a full accounting also weights output tokens 5x heavier (comparatively rare but expensive), not just the cache-read discount alone.

(b) Per-session "Biggest reclaim opportunities" list was unactionable noise. A user has thousands of ended sessions and never returns to one closed days ago, so naming individual past sessions as "actionable" is noise regardless of copy. Replaced the list with one aggregate line (no session IDs): how many sessions cleared the existing compact-candidate threshold and what share of the window's re-read tokens they represent, pointing at the live statusline as the actionable surface instead.

Before / after (real output against my own logs)

Before:

95.0% of your tokens went to re-reading context (history, CLAUDE.md, tool output)
...
Biggest reclaim opportunities
  · session a1b2c3d4e5f6  84.1% re-read, 950.0k cache (12 turns)
  · session 9f8e7d6c5b4a  81.2% re-read, 720.3k cache (8 turns)
    → /compact mid-session (or start fresh) to reclaim that quota.

After:

57.4% of your quota went to re-reading context (history, CLAUDE.md, tool output)
16.7% went to net-new work (uncached input + output)

Re-read:   1278.7M tokens  (cache reads)
New work:  10.1M tokens

10 of your 61 sessions ran context-heavy enough to warrant a mid-session /compact
— 84.1% of this window's re-read tokens.
    The statusline flags this live, before a session ends — a closed session
can't be reclaimed.

Scope note

Another PR (branch statusline-preview) is concurrently adding a new statusline-preview section to the same _render function in cmd_quickstart.py. This PR is scoped to the composition-math/labels change and the reclaim-section removal only, to keep the two diffs merging cleanly. This PR should merge first.

Test plan

  • uv run pytest tests/unit/ tests/synthetic/ tests/agents/ tests/integration/ — 2169 passed, 1 pre-existing skip
  • New unit tests: test_quota_weighted_reread_share_discounts_cache_reads, test_quota_weighted_fields_in_json_payload (context_diagnostic), test_quickstart_headline_reads_as_quota_not_raw_tokens, test_quickstart_reclaim_section_is_aggregate_not_named_sessions, test_quickstart_no_compact_candidates_omits_reclaim_section (quickstart)
  • uv run ruff check clean on both changed source files
  • Manually ran tj quickstart --since 30d and --json against real ~/.claude/projects history to eyeball the new output and confirm the JSON fields

🤖 Generated with Claude Code

… list (#119)

The "Where your quota goes" headline reported a RAW token share as "quota"
(e.g. "95.0% of your tokens went to re-reading context"), but cache-read
tokens are billed at a fraction of a base input token in both API pricing
and Anthropic's subscription rate-limit weighting — the same discount every
current model row in tokenjam/pricing/models.toml applies (cache reads at
0.1x, output at 5x). A raw share mixes "tokens" and "quota" framings and
overstates re-reading's actual cost.

Added quota_weighted_reread_share / quota_weighted_work_share (and their
underlying quota_weighted_tokens) to TurnComposition and ContextDiagnostic
in context_diagnostic.py, using named constants (CACHE_READ_QUOTA_WEIGHT,
OUTPUT_QUOTA_WEIGHT) cited to the pricing table. Chose to weight the
computation rather than just retitle the box, since the whole point of
tokenjam's quota-native framing is that the number should mean what it
says — retitling to "raw tokens" would abandon that thesis rather than fix
the mismatch. The raw reread_share/total_tokens fields are unchanged for
existing consumers (tj context, tj tokenmaxx); only quickstart's headline
now reads quota-weighted.

Also dropped the per-session "Biggest reclaim opportunities" list: a user
has thousands of sessions and never returns to one closed days ago, so
naming past sessions as "actionable" is noise regardless of framing. In its
place, one aggregate line (no session IDs) reporting how many sessions
cleared the existing compact-candidate threshold and what share of the
window's re-read tokens they represent — actionability lives in the live
statusline, not a retrospective list.

Co-Authored-By: Claude <[email protected]>
@anshss
anshss requested a review from anilmurty as a code owner July 9, 2026 13:20
@greptile-apps

greptile-apps Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two issues in tj quickstart's "Where your quota goes" panel: (a) the headline now correctly reports a quota-weighted re-read share (quota_weighted_reread_share, discounting cache reads to 0.1× and weighting output at 5×) instead of the former raw token share that conflated the two framings, and (b) the per-session "Biggest reclaim opportunities" list is replaced by a single aggregate line (no session IDs) with a pointer to the live statusline.

  • Adds CACHE_READ_QUOTA_WEIGHT = 0.1 / OUTPUT_QUOTA_WEIGHT = 5.0 constants and total_quota_weighted_tokens, quota_weighted_reread_share, quota_weighted_work_share properties to both TurnComposition and ContextDiagnostic; the window-level variants drive the cmd_quickstart.py renderer, and the per-turn variants are documented groundwork for issue [follow-up] Harmonize the time basis of analyzer recoverable estimates #122.
  • diagnostic_to_dict now emits the three new quota-weighted fields so they round-trip into the --json payload.
  • Test suite adds a test_quota_weight_constants_match_anthropic_pricing_table cross-check that reads models.toml at test-time, directly addressing the previously flagged concern about pricing drift silently corrupting the headline.

Confidence Score: 5/5

Safe to merge — the only changed execution paths are the two headline lines and the reclaim section in cmd_quickstart.py; all existing raw token properties are untouched.

The math is straightforward, the formula is unit-tested with a pinned expected value, the JSON round-trip is tested, and a live pricing-table cross-check guards against the one gap previously flagged in review. All pre-existing tests continue to pass (2169 + 5 new). The per-turn TurnComposition properties are deliberate documented groundwork with an explicit 'do not remove' note. No data loss, no API surface changes, no migration risk.

No files require special attention.

Important Files Changed

Filename Overview
tokenjam/core/context_diagnostic.py Adds CACHE_READ_QUOTA_WEIGHT / OUTPUT_QUOTA_WEIGHT constants, quota_weighted_tokens / quota_weighted_reread_share on TurnComposition (documented as groundwork for #122), and total_quota_weighted_tokens / quota_weighted_reread_share / quota_weighted_work_share on ContextDiagnostic; all existing properties and raw token fields are untouched.
tokenjam/cli/cmd_quickstart.py Switches the two headline lines from raw diag.reread_share / computed work_share to diag.quota_weighted_reread_share / diag.quota_weighted_work_share, and replaces the per-session compact-candidate list with an aggregate count+share line; no other rendering paths are affected.
tests/unit/test_context_diagnostic.py Adds three new tests: quota-weighted share math (pinned formula), JSON round-trip, and a live pricing-table cross-check that fails loudly if models.toml drift away from the assumed ratios.
tests/unit/test_quickstart.py Adds three new quickstart CLI tests: headline wording (quota vs. tokens), aggregate reclaim section (no session IDs), and omission of the reclaim section when no compact candidates exist; uses Rich-safe border-stripping for panel text assertions.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[tj quickstart _render] --> B[ContextDiagnostic]
    B --> C[total_quota_weighted_tokens\nR×0.1 + I + O×5.0 + W]
    C --> D[quota_weighted_reread_share\nR×0.1 / total_qw]
    C --> E[quota_weighted_work_share\n I + O×5.0 / total_qw]
    D --> F[Headline: X% of your quota\nwent to re-reading]
    E --> G[Headline: Y% went to\nnet-new work]
    B --> H{compact_candidates?}
    H -- yes --> I[Aggregate line:\nN of your S sessions ran\ncontext-heavy enough…]
    H -- no --> J[Reclaim section omitted]
    I --> K[Pointer to live statusline]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[tj quickstart _render] --> B[ContextDiagnostic]
    B --> C[total_quota_weighted_tokens\nR×0.1 + I + O×5.0 + W]
    C --> D[quota_weighted_reread_share\nR×0.1 / total_qw]
    C --> E[quota_weighted_work_share\n I + O×5.0 / total_qw]
    D --> F[Headline: X% of your quota\nwent to re-reading]
    E --> G[Headline: Y% went to\nnet-new work]
    B --> H{compact_candidates?}
    H -- yes --> I[Aggregate line:\nN of your S sessions ran\ncontext-heavy enough…]
    H -- no --> J[Reclaim section omitted]
    I --> K[Pointer to live statusline]
Loading

Reviews (2): Last reviewed commit: "fix: address PR #437 review — guard drif..." | Re-trigger Greptile

Comment thread tokenjam/core/context_diagnostic.py Resolved
Comment on lines +138 to +142
# content this turn, not a re-read, so they're outside the discount this
# reflects. Named constants (not inlined) so the ratio's provenance is visible
# at every call site.
CACHE_READ_QUOTA_WEIGHT = 0.1
OUTPUT_QUOTA_WEIGHT = 5.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Hardcoded weights could silently drift from models.toml

CACHE_READ_QUOTA_WEIGHT = 0.1 and OUTPUT_QUOTA_WEIGHT = 5.0 are documented to match the ratios in tokenjam/pricing/models.toml, but nothing enforces that. If a new model row is added with a different ratio, or the cache-read discount changes, these constants stay stale and the headline quietly reports the wrong quota split with no failing test. A small test that reads the pricing table and asserts every Anthropic model row matches the expected ratios (or that the constants are at least internally consistent with the table's current values) would close this gap.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/core/context_diagnostic.py
Line: 138-142

Comment:
**Hardcoded weights could silently drift from `models.toml`**

`CACHE_READ_QUOTA_WEIGHT = 0.1` and `OUTPUT_QUOTA_WEIGHT = 5.0` are documented to match the ratios in `tokenjam/pricing/models.toml`, but nothing enforces that. If a new model row is added with a different ratio, or the cache-read discount changes, these constants stay stale and the headline quietly reports the wrong quota split with no failing test. A small test that reads the pricing table and asserts every Anthropic model row matches the expected ratios (or that the constants are at least internally consistent with the table's current values) would close this gap.

How can I resolve this? If you propose a fix, please make it concise.

…indent

- Add a doc comment on TurnComposition.quota_weighted_tokens /
  quota_weighted_reread_share noting they are deliberate groundwork for #122
  (tj context / tj tokenmaxx switching to quota-weighted shares) and are not
  yet consumed by any renderer — so a future cleanup pass doesn't delete them
  as dead code (Greptile P2).

- Add test_quota_weight_constants_match_anthropic_pricing_table: reads
  tokenjam/pricing/models.toml via load_pricing_table() and asserts every
  Anthropic row's cache_read/input and output/input ratios match
  CACHE_READ_QUOTA_WEIGHT / OUTPUT_QUOTA_WEIGHT. A future pricing change that
  drifts the ratio now fails loudly instead of silently invalidating the
  quickstart headline's credibility (Greptile P2).

- Drop the stray 4-space leading indent on the reclaim aggregate's second
  line so it renders flush with the sentence above instead of misaligned
  inside the panel (copy nit from founder review).

Co-Authored-By: Claude <[email protected]>
@anshss
anshss changed the base branch from main to ticket-120 July 9, 2026 18:41
@anshss
anshss merged commit f3cf6d1 into ticket-120 Jul 9, 2026
4 checks passed
anshss added a commit that referenced this pull request Jul 9, 2026
Combining #437 (ticket-119: aggregate reclaim line, never names a past
session) with #438 (statusline live preview: shows the exact statusline
line one concrete named session would have triggered, by design) broke
CI: test_quickstart_reclaim_section_is_aggregate_not_named_sessions
asserted "sess-heavy" absent from the ENTIRE quickstart output, which
was true when #437 was authored (quickstart never named a session
anywhere) but stopped being true once #438 added a later section that
intentionally names its preview session as a concrete "what you'd have
seen live" example — itself covered by dedicated #438 tests
(`test_quickstart.py` asserts "session sess-recent would have shown
this at turn 3" / "session sess-old ... turn 5").

Both invariants are correct and neither feature should be reverted:
the quota-composition PANEL must never name a session (#119's actual
intent — see the "(#119)" comment at cmd_quickstart.py's aggregate
line), while the separate, later statusline-preview section legitimately
does. Scoped the assertion to the panel's own text (everything before
the preview section's fixed intro, "With the statusline installed")
instead of the whole rendered output.

Co-Authored-By: Claude <[email protected]>
@anshss anshss changed the title fix: quota-weight quickstart headline, drop named-session reclaim list (#119) fix: quota-weight quickstart headline, drop named-session reclaim list Jul 9, 2026
@anilmurty
anilmurty deleted the ticket-119 branch July 29, 2026 23:07
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.

1 participant