Skip to the content.

Token-footprint audit

A request answers “how big is this turn?” with one number. This audit answers the more useful question: which slice is the bloat? — so a reduction effort aims at the biggest, cheapest-to-cut slice instead of guessing.

fak sits in front of the model, so it sees every token Claude Code sends. On the flagship Claude Code route fak forwards those bytes byte-identically to preserve the provider’s prompt-cache prefix (that passthrough is the core thesis). Byte-faithful passthrough is a constraint as much as a feature: fak cannot rewrite Claude Code’s system prompt or reorder its tools without breaking the cache hit. So the audit is what is actionable — you cannot cut what you have not counted, and you should not cut what would cost more (a broken cache) than it saves.

The measurement: RequestFootprint

agent.RequestFootprint(req) (internal/agent/anthropic_footprint.go) decomposes one inbound Messages request into a labeled partition. It is the bucketed twin of EstimateAnthropicTokens: the same ~4-char/token walk, so Total.Tokens == EstimateAnthropicTokens(req) by construction. Provenance is ESTIMATED — the house heuristic, not the provider’s billed count. It composes with the managed-context arm (internal/gateway/ctxvalue.go), which reports the provider’s OBSERVED resident tokens as one number: OBSERVED says how full the window is; ESTIMATED says where the bytes went.

Bucket What it holds Grows with
system the system prompt: harness spine + any injected memory / CLAUDE.md roughly fixed per session
tools every tool definition (name + description + JSON-Schema parameters) tool count
history every message except the most recent conversation length
tail the most recent message (the volatile suffix that breaks the cache prefix) current turn

Two derived roll-ups:

Per-tool cost is broken out (PerTool), which is the exact primitive #2924 uses to gate growth of the tool floor.

The floor is the thing to watch

The floor is where fak has the most leverage because it is paid every turn. Two grounded data points on the tool half of the floor:

This is exactly why fak_tools_search (lazy MCP schema loading) exists: it presents a search interface and faults in a tool’s full schema only when the model picks it, so the per-call tool tax is a floor you can shrink rather than a constant you pay in full.

Reduction lever per slice

The honest split from the awesome-token-efficiency catalog: the biggest mechanical, lossless wins change cost without changing what the model sees, so they are default-on; lossy wins (compression, summarization) trade fidelity for size and stay behind a flag with a witness.

Slice Lever Loss fak status Tracking
system byte-faithful passthrough keeps the cached prefix alive; author-side distillation is the only way to shrink it without a cache break lossless (cache) / author-side (distill) ✅ passthrough; ➖ distillation is Claude Code’s to do #1258 syspromptmmu (fak’s own future spine, not the Claude route)
tools tool-floor pruning drops provably-unreachable defs; fak_tools_search lazy-loads schemas lossless ✅ both shipped; ✅ floor gated #2924 per-tool footprint budget + floor-growth gate (shipped)
history compact-history sheds the un-cacheable middle past the 48k budget by splicing original bytes; ctxplan O(1) view re-materializes under a budget bounded ✅ both on by default #3028 measure compaction cache-hit impact
history (tool results) oversized-result elision shrinks a scrolled-past tool_result to head+tail at 16 KB bounded ✅ on by default
tail inbound content exact-dedup (same file/output sent twice in one request) lossless ✅ shipped #1101 (closed)

The six default-on savers are audited and locked by fak token-defaults-scorecard (grade A, 6/6). This audit is the map of which slice each one attacks, so a new saver can be aimed at the slice that is actually largest for a given workload.

What is measured now, and what is next

See also: awesome-token-efficiency (the full field of methods), token-defaults-scorecard (what is on by default), and CONTEXT-IS-NOT-MEMORY (why shedding history is safe when the durable state lives elsewhere).