Concepts
Two ideas do most of the work: the resident/on-demand/dropped split, and a chaff% definition built to survive a hostile reading.
Resident, on-demand, dropped
A context file does not cost the same amount every turn. Claude Code’s own documented rules put every entry into one of three classes, and chaff models them separately instead of reporting one undifferentiated token count:
- Resident, loaded in full every turn whether or not the turn needs it: the root
CLAUDE.md, ancestorCLAUDE.md/CLAUDE.local.mdfiles, their@-imports, tool definitions,.claude/rules/*.mdfiles with nopaths:key, andMEMORY.mdup to its read limit. - On-demand, loaded only when something routes to it: skill and subagent bodies (their frontmatter
descriptionis resident; the body is not),.claude/rules/*.mdfiles scoped withpaths:, subdirectoryCLAUDE.mdfiles, andMEMORY.mdtopic files. - Dropped: never loaded at all.
MEMORY.mdcontent past the documented 200-line / 25 KB cut (whichever comes first) is cut on every load, silently, whether the author knows it or not.
For the generic harness, none of this is guessed: nothing is resident unless you declare it, and an undeclared entry prints a note rather than an assumption.
The chaff% numerator, defined to survive a hostile reading
chaff% = (resident tokens under enforced-finding spans, deduplicated) / (total resident tokens), per set, per named tokenizer. Every clause in that definition closes a specific way the number could be gamed or misread:
- enforced-finding spans only
- Heuristic findings are excluded entirely. A believed-but-unmeasured claim cannot inflate a score that is supposed to mean “evidence-backed.” Their token weight still gets reported as the separate
UNVERIFIEDline, so it is visible without being counted. - deduplicated
- Overlapping spans are merged before counting, so two rules flagging the same bytes cannot double the number. No rule may claim a span larger than the text it identifies either: a finding’s anchor cannot quietly annex neighboring, unflagged prose.
- resident tokens only
- On-demand and dropped tokens never enter either side of the ratio. A file that is mostly on-demand content cannot be made to look worse (or better) by folding tokens it never pays for every turn into the count.
- set-level aggregates are excluded from the numerator, on purpose
budget.resident-exceededasserts a fact about the whole set (“the total exceeds the declared budget”), not that any one span is removable. It still anchors on the largest resident contributor for reporting, and it still drives exit code 3. But its tokens are excluded from the chaff% numerator entirely, not partially: counting that anchor span would let one aggregate fact claim an entire file as chaff, which is exactly what “no rule may claim a span larger than the text it identifies” forbids. A structural finding can even exist with zero effect on chaff% for the same reason, when its span points at content that was never resident to begin with. The case study has a real example:memory.index-over-read-limitfires on content past the read limit, which by definition is already in theDROPPEDband, not the resident one, so that enforced finding contributes nothing to the numerator either.
The absolute numerator is always printed beside the percentage, because a bare ratio is a vanity metric. And the honest caveat, stated plainly rather than buried: chaff% is the share of your always-loaded tokens that chaff can point at a specific, evidence-backed reason to remove. It is not a quality score. A 0% file can still be a bad file; it just means nothing in it cleared the enforced bar yet.