← Terse Blog
Agent Sessions

The Context Window Diet

By ·Founder, Terse·Updated

Context bloat is the number-one hidden cost in agentic coding: every file read, search result, and command output lands in the context window and is re-billed on every subsequent turn until something pushes it out. An unmanaged session commonly carries 120K tokens by turn 20; a pruned one does the same work in about 45K.

How the Window Fills Up

Agentic coding tools love to read files. That's usually helpful — until you notice the pattern: the agent reads five files, glances at four of them, and edits one. All five stay in context. So does the 300-line command output from three turns ago, the search results that produced two false positives, and the full text of a config file that was relevant exactly once.

Reads accumulate; they don't expire. Because LLM APIs are stateless, the entire window is re-sent — and re-billed as input — on every turn. Ten thousand tokens of stale file reads carried for thirty turns is 300,000 billed tokens that bought you nothing. By turn 20, the difference between an unmanaged window (~120K tokens) and a pruned one (~45K) is not just cost: on long sessions the gap is worth around $220 a year per developer, and the leaner window also leaves the model more room to reason before old context gets truncated away.

Three Habits That Keep the Window Lean

1. Read narrow

Ask for specific functions and line ranges, not whole files. "Show me lines 40–80" or "read the validate_token function" beats "read this 800-line file" nine times out of ten. If the agent needs more, it can ask for the next range — that costs a turn, but a turn is cheaper than carrying 700 unneeded lines forever. The same logic applies to tool output: a filtered git diff or a --stat summary first, details on demand.

2. Summarize, then drop

After a burst of exploration, have the agent restate what it learned in a few sentences — then the raw reads no longer need to stay live. A 200-token summary replacing 15K tokens of source is the single highest-ratio compression available in an agent session, and the summary is often more useful to the model than the raw text, because it has already been distilled into conclusions.

3. Start fresh between tasks

One endless session is the most expensive way to work. A new task rarely needs the last task's context, but it pays for all of it, every turn. When a task completes, open a clean session. The few sentences of orientation a fresh session needs cost far less than the tens of thousands of stale tokens it avoids.

Delegate the Messy Work

The biggest window-fillers are broad searches and multi-file sweeps — work that is noisy by nature. The fix is structural: hand it to a subagent that burns its own throwaway context and returns only the conclusion. That pattern is important enough to get its own guide.

Measure It, Don't Guess

Terse's agent monitor tracks tokens per source and per turn, so you can watch the window filling in real time — and see exactly which habit (file reads, tool output, search results) is doing the filling. Most developers who look at the breakdown for the first time find one category responsible for over half their session cost. Fix that one first; the diet is easier when you know what you're eating.

See What's Filling Your Window

Terse tracks per-source, per-turn token usage across agent sessions — file reads, tool output, prompts — so context bloat shows up as a number. On-device, free to start.

Download Terse

Frequently Asked Questions

Why does old context cost money on every turn?

LLM APIs are stateless: the full conversation — including every old file read and command output — is re-sent and re-billed as input with every request. A 10K-token file kept in context for 30 turns is billed roughly 30 times.

How big should an agent session's context get?

There's no fixed number, but a coding session that passes 100K tokens of context usually carries mostly stale reads. Pruned sessions doing equivalent work commonly stay under 50K, which is both cheaper and leaves the model more room to reason.

Is starting a new session really cheaper than continuing?

Almost always, when the task changes. A fresh session pays a small orientation cost once; a continued session pays for the entire old context on every turn. If the new task doesn't need the old files, the math favors a clean start within a few turns.

Further Reading