feat(claude): account for /advisor escalations under the advisor model#659
Merged
Conversation
Claude Code's advisor tool (/advisor) escalates hard decisions mid-turn to a stronger model. Those tokens are recorded inside message.usage.iterations as advisor_message entries with their own model and are excluded from the top-level message.usage totals. The parser read only the top-level totals, so advisor spend was silently dropped and never attributed to the advisor model. Emit a separate call per advisor_message iteration priced under the advisor model, preserve those iterations through entry compaction and the large-line (>32KB) byte-scanner path, and fold advisor cost into the guard budget. Bump the claude parser and guard cache versions so existing caches re-parse and pick up the advisor spend.
The guard's advisor fold in computeSessionUsage had no test; dropping advisorCost from the line cost left all 30 guard tests green. Pins the fold (advisor line costs more than the same line without iterations) and the per-message replace semantics under streaming rewrites.
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.
What
Claude Code's new advisor tool (
/advisor) escalates hard decisions mid-turn to a stronger model. Those tokens are recorded insidemessage.usage.iterations[]asadvisor_messageentries carrying their ownmodel, and are excluded from the top-levelmessage.usagetotals (which cover only the main model).CodeBurn read only the top-level totals, so for anyone using
/advisor:This is the same gap ccusage closed in their advisor support.
Change
advisor_messageiteration into its own call, attributed to the advisor's model and priced accordingly. The main call keeps exactly the top-level totals, so there is no double counting.compactEntry), which trims usage for the session cache;iterationsbefore. The fix JSON-parses only the small usage-object slice, not the whole line.src/guard/usage.ts), which also reads these sessions.GUARD_CACHE_VERSIONso existing caches re-parse and pick up advisor spend.Advisor calls use a stable dedup key (
<msgId>:advisor:<ordinal>) keyed on advisor ordinal, so the report path (compacted, advisor-only iterations) and the guard path (raw iterations) agree.Verification
tests/parser-advisor-usage.test.ts: main-call attribution unchanged, separate advisor call priced under the advisor model, no double counting, survives compaction, and survives the >32KB large-line path. Mutation-verified each fails on pre-fix code.tsc --noEmitclean.Scope note
fallback_messageiterations (written when a turn retries on another model) are a related, pre-existing under-count in the same family. They were never counted before this change either, so they are left as a documented follow-up rather than expanding this PR.