Documentation
¶
Overview ¶
Command muster-toolctx-calibrate measures how well the rendered view's tool-context ESTIMATE (cctranscript.EstimateTokens) matches the MEASURED growth, over a directory of Claude Code transcripts, and fits the calibration constant the estimate uses (cctranscript.ResultBytesPerToken).
🔴 IT PRINTS AGGREGATES ONLY — counts, medians, percentiles. No transcript text, path, tool name or id is ever printed, and nothing is written. Nothing in CI runs it (it has no tests; `go test ./...` only compiles it), and its input is whatever directory it is pointed at:
go run ./cmd/muster-toolctx-calibrate [-dir ~/.claude/projects]
THE SAMPLES are single-call gaps: one call, its result, and the next turn, with no prompt, notice or error between — read with EVERY attachment type allowed, and the types each gap held recorded beside it. For each: the measured growth (next turn's context − the issuing turn's), the issuing turn's output_tokens, and the call's and result's sizes (Event.Bytes).
THE ATTACHMENT TYPES ARE CLASSIFIED HERE, not by hand. A gap's EXCESS is its growth − output − result/ResultBytesPerToken: what entered the context that is neither. The baseline is the median excess of gaps with no attachment. A type is NEGLIGIBLE when the gaps holding it and otherwise only negligible types number at least minTypeGaps, their median excess is within maxTypeExcess tokens of the baseline, AND their p75 within maxTypeExcessP75 — either way: a type that is usually small but often large (a tool listing) is not negligible, nor one whose gaps read far BELOW the baseline (a truncated read, whose result bytes overstate what entered the context); the set is grown greedily (most frequent type first) until nothing more joins. The command prints the table and the set, and says whether the set matches cctranscript's (NegligibleInjected) — a mismatch is the signal to update it.
The CLEAN samples (every type negligible) are what the ledger labels CostMeasured. Transcripts are split by a hash of their path into a FIT half and a HELD-OUT half: the rate is fitted on the first, and the error is reported on the second, for the old estimate and the new one.
THE MODEL is a split, not one factor: growth = the turn's own output (which re-enters the context in full) + the result's tokens. The result's share is fitted as bytes per token: the median of resultBytes / (growth − output) over the fit half's samples whose result is big enough to measure (≥ minBytes).