Documentation
¶
Overview ¶
Package contexttax prices what a session pays to re-send its own context.
Every tool call re-reads the whole conversation as a cache read before it does anything. At 382k tokens that is about $0.19 a call on Opus 5, and a loop of twelve pays it twelve times. That charge is the context tax, and until now Caprock stored every number needed to compute it and showed none of them.
The formulas are spec/spec-context-tax.md section 5. Prices come from the pricing table rather than from multipliers on the input price: Fable 5.1 and Mythos 5.1 read cache at 0.025x, not the 0.1x the rest of the table uses.
Index ¶
Constants ¶
const ( // SubStartTokens is a subagent's starting context, median over 364 // archived subagent transcripts. SubStartTokens = 17_900 // SummaryTokens is what a subagent hands back to its parent, median over // the same archive. It is cache-written once and re-read by every turn // left in the session, so it is a material cost, not a rounding error. SummaryTokens = 10_900 // BriefTokens is the task description the lead writes to start the // subagent. BriefTokens = 1_000 )
The isolation counterfactual (spec section 5.4). It is displayed and never acted on: Stage 0 nudged the model 8 times on eligible series and it complied once, with delivery confirmed, so the lever is parked. What survives is the number, because it is what tells a user their loop was expensive. The intervention that follows is compaction.
The constants are measured, not guessed. Stage 0 read 364 real subagent transcripts: a subagent's first turn is a 17.9k median context, and the summary it hands back is 10.9k median -- not the 1k the spec first assumed, which is why the summary is charged here rather than rounded away.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Call ¶
Call is one priced tool call: the context it re-read, what it returned, and how many assistant turns still followed it in the session.
type Isolation ¶
type Isolation struct {
Actual float64 `json:"actual"`
Isolated float64 `json:"isolated"`
Saved float64 `json:"saved"`
}
Isolation is what a series cost, and what it would have cost inside a subagent that starts small.
The saving is not a cheaper model. Same-model isolation captured 96% of it in Stage 0 ($466 of $487), so the subagent is charged at the parent's own rates by default. The saving is that a subagent never re-reads the parent's 380k context: it starts near zero and grows only by its own results.
type Lifetime ¶
type Lifetime struct {
TaxUSD float64 `json:"tax_usd"`
CostUSD float64 `json:"cost_usd"`
// Unpriced is how many cache-read tokens belong to models with no pricing
// row, so the tax above excludes them. A tax figure that silently dropped
// them would understate itself with no way for a reader to tell.
UnpricedTokens int64 `json:"unpriced_tokens,omitempty"`
}
Lifetime is the context tax over a range, and what share of the spend it is.
Share is against the spend actually priced, so a workload with unpriced models reports a share of what it could price rather than a share diluted by what it could not. Unpriced volume is already reported separately.
type Prices ¶
Prices are the per-token rates a series is charged at, already divided out of the table's per-million figures.
type Table ¶
Table is the subset of the pricing table this package needs, so callers can pass the real one without this package importing the daemon.
Lookup, not LookupAt: an aggregate over a range has no single instant to price at. Where a model's rate changed inside the range -- Sonnet 5 went from $0.20 to $0.30 per million cache-read tokens on 2026-08-30 -- the lifetime tax is charged at today's rate for that model's whole volume. The error is bounded by how much a rate moved and applies only to the models that moved; per-call figures, where an instant does exist, use LookupAt.