← ~/pillars / cost-engineering / session-hygiene-context-budgeting
Session hygiene and context budgeting
The dollar mechanics of context: what /clear versus compaction actually costs, CLAUDE.md and MCP overhead priced per year, subagent isolation, and the 7× agent-team multiplier.
updated 2026-07-11 ~5 min read pattern 05/07 Cost Engineering
on this page
Context. Every turn of an agentic session resends the whole window, so context size is the unit price of everything you do next. The context engineering pillar treats a bloated window as a quality problem: context rot, drifting attention. This page prices the same behaviours in dollars, because the two arguments compound and the dollar one is the easier sell.
Forces. The naive token maths overstates the cost of stale context
(cached history rides at 0.1×), so hygiene sceptics have a point until the
cache-write cliffs are counted. Fixed overhead (CLAUDE.md, MCP servers)
is invisible per session and shocking per year. Isolation via subagents
cuts main-context cost but is not free, and agent teams multiply spend
roughly sevenfold. And each hygiene action has a price, not just a
benefit: /clear throws away paid-for cache, compaction buys a smaller
window with an expensive request.
Resolution. Budget context like memory in an embedded system: a fixed overhead you audit, a working set you keep small at task boundaries, and overflow mechanisms (compaction, subagents) whose costs you know before you need them.
What a turn actually costs
With caching working, a turn’s input bill is: the new tokens at full price, plus the entire prior window at 0.1× (prompt caching). So carrying 100k tokens of stale context costs about the same as 10k fresh tokens, every turn: real, but modest. The expensive events are the cliffs, where the whole window suddenly reprices at the 1.25× write premium: a pause past the TTL, a mid-session config change, anything in the invalidation catalogue. A bloated window makes every cliff proportionally more expensive: the honest dollar case for hygiene is not “stale tokens are pricey”, it is “stale tokens multiply the price of every accident, and they rot output quality while doing it”.
Watch it live: context_window.used_percentage on the
status line, /context for what is
consuming the space, /usage for the session’s running total
(costs).
/clear versus compaction, priced
The two overflow mechanisms have opposite cost shapes:
/clearcosts you your cache and your context: the next turn starts cold and repays whatever re-establishment the new task needs. It is the right move at task boundaries, where the old context was pure liability anyway: stale context wastes tokens (and attention) on every subsequent message./renamefirst, so/resumecan find the session if you were wrong.- Compaction costs a summarisation request over the whole window,
then, because the rewritten history is a new prefix, a full cache
rewrite at 1.25× on the next turn. In exchange, every subsequent turn
is smaller. It pays on continuation: same task, long horizon, the
history’s facts still needed. The OTel
compactionevent reportspre_tokensandpost_tokens(monitoring usage), so your dashboard can price what each compaction saved downstream. Steer what survives with/compact Focus on…or compact instructions in CLAUDE.md.
The decision rule is one question: is the accumulated context an asset
or a liability for the next hour? Liability → /clear. Asset that no
longer fits → compact. Auto-compaction firing repeatedly on the same
session is the smell that the answer was “liability” several turns ago.
Fixed overhead: CLAUDE.md and MCP, priced per year
Everything loaded at session start is a tax on every session, and on every post-cliff rewrite. The arithmetic makes small numbers large: a CLAUDE.md that is 2,000 tokens heavier than it needs to be, across a twenty-developer fleet averaging four fresh sessions a day, is roughly 58 million tokens a year of pure overhead before anyone types. At Sonnet-class input prices, that is hundreds of dollars a year for prose nobody reads, plus its cache-write premiums, plus its share of every invalidation cliff. The guidance is blunt: keep CLAUDE.md under 200 lines, move workflow-specific instructions into skills that load on demand (costs).
MCP servers are the other standing charge. Tool definitions are deferred
by default (only names enter context until a tool is used), which
capped what used to be the worst offender; the residual habits still
pay: disable servers you are not using (/mcp), and prefer CLI tools
(gh, aws) where they exist, since they add no per-tool listing at
all. Then audit, rather than assume: /context shows the actual
breakdown, and the fleet-level view falls out of the
OTel kit’s token series.
Isolation: subagents cheap, teams dear
Delegating verbose work to a subagent (test runs, log trawls, doc fetches) keeps thousands of output tokens in a context you throw away, returning only a summary to the window every future turn repays. The same logic runs in reverse for agent teams: each teammate is a full Claude instance with its own window, and token usage runs roughly 7× a standard session when teammates plan (costs). Neither number is an argument against the mechanisms; both are arguments for pricing them. A subagent that saves your main window 50k tokens of test logs costs a fraction of what it saves. A seven-agent team on a task one agent handles is paying 7× for coordination you did not need: put Sonnet-class models on teammates, keep teams small, and shut teammates down when their piece is done.
Hooks buy the same isolation for free in narrow cases: a PreToolUse hook that greps a 10,000-line log for errors before Claude reads it turns tens of thousands of context tokens into hundreds (costs).
A context budget that survives contact
The practices, as a checklist with prices attached:
- Audit the fixed overhead once a quarter:
/context, CLAUDE.md under 200 lines, unused MCP servers off. This is the only item that pays fleet-wide without anyone changing behaviour. /clearat task boundaries, compact on continuation: one question, asked at the moment the window feels heavy.- Front-load configuration: model, MCP servers, thinking settings before the long work, per the invalidation catalogue.
- Delegate verbosity down: subagents for logs and test output; summaries up.
- Price agent teams before spawning them: 7× is a fine multiplier for genuinely parallel work and a terrible one for company.