My agents kept getting worse halfway through long sessions, and I assumed I had built the harness badly. That was part of it. The bigger part was that I had no idea what was actually sitting in my context window. So I modeled one session filling a 200k window and drew it cell by cell, mostly so I could see it myself.
System prompt, AGENTS.md. Re-sent on every single turn.
Tool & MCP schemas
Definitions for every tool the agent could call, whether it calls them or not.
Retrieval on demand
File reads, greps, command output. Everything the agent pulled in to do the work.
Skills & subagents
Progressive disclosure and context isolation. The only mechanism that gives context back.
154,400/200,000
77.2%
A map of a 200,000 token context window as a 25 by 16 grid of cells, each cell 500 tokens. At the end of the modeled session 154,400 tokens are in use, 77.2% of the window. The full breakdown is in the session ledger below.
ModeledA representative session, not a recording. Token costs are mid-range figures for the thing named: a real AGENTS.md, a real MCP schema, a real 300-line file. If one of them is wrong, the figure is wrong, which is about the right amount of pressure to be under. Swap in a transcript and every number here moves.
Before I've typed anything
The context window starts empty. It stays empty for about half a second, as upon loading your coding agent, it'll initialize the context window.
By the time the cursor is blinking at me, the agent has loaded its system prompt, the JSON schema for every tool it can call, whatever I left in AGENTS.md, and a one-line index of every skill it might later decide it needs.
I haven't asked for anything yet. 15,200 tokens gone.
None of that was a decision. Some of it was my configuration like MCP servers and skills. There's also the system prompt which I cannot control.
The MCP servers I connected at user level
Three MCP servers are wired up. GitHub, Postgres, Sentry. I configured them at some point at user level, and now they are always loaded upon starting my coding agent.
Each one hands over the full schema of every tool it exposes. Names, descriptions, parameter types, enums, examples. 33,800 tokens of definitions for tools this session may never call.
And they stay. Tool schemas are not fetched when needed, they sit in the window and get re-sent on every turn, because the model cannot call a tool it cannot see.
A quarter of the window is gone and I have not started working.
Now the actual work starts
I ask it to fix a bug in session refresh. It does what I would do: it goes and looks.
A grep to find the call sites. Three files read in full, because a diff on its own tells you nothing.
This is retrieval, and it is the one I actually steer, turn by turn.
How tool call output expands the context window
The coding agent runs the test suite. The output is, for example, 7,400 tokens and every single tool call lands more tokens in the window.
Even worse, it stays in my context window for the entire session.
Then a git diff. Then the schema file, because the failure is in a migration. Then another grep, wider this time.
I used to picture context as the things I told the agent. In a real session it is mostly the things the agent told itself. Tool output is context, it is the biggest line in the budget, and I never counted it.
Tool output is context. I never counted it.
More operations
A build with warnings. A migration. Another test run after the first attempted fix.
That's 34,000 tokens in one step, continuously filling up the context window. The window is past 60%.
Three quarters full
A file read for the second time, because the first copy is 65,500 tokens back. A Sentry trace. A 561-line integration test. A third test run, green at last.
152,600 tokens. The agent is still working and still confident, and the code it hands me still looks fine.
A way to play with context windows: subagents
Last task: check every call site in the repo for the same bug. Done in the main window that is another forty thousand tokens of reads, and the window is already at 76%.
Unknowingly, I did something smart here. I delegated this bit to a subagent. The subagent runs the task in a window of its own, burns 38,000 tokens across 22 files, and hands back one answer.
1,800 tokens land in the main context window. The other 38,000 never touch this window at all.
It is the only mechanism on this page that subtracts instead of adds.
The subagent read 38,000 tokens. It brought back 1,800.
The session ledger
Every allocation, in the order it landed. Same data the map is drawing. Focus a row and its cells light up above.
Every context allocation in the modeled session, with its mechanism and token cost.
Source
Mechanism
Tokens
Running
System promptHarness instructions, tone, safety, tool-use protocol.
Persistent
2,800
2,800
Built-in tool definitionsFile read, file write, edit, shell exec, grep, glob, subagent dispatch. Full JSON schema for each.
Tools
9,400
12,200
AGENTS.mdProject conventions plus my global instructions, concatenated.
Persistent
2,100
14,300
Skill indexName and one-line description of 14 skills. Bodies are not loaded yet. This is progressive disclosure earning its keep.
Grep "refreshSession"24 matches across 11 files, with two lines of context each.
Retrieval
1,600
50,600
src/auth/session.ts318 lines, read in full.
Retrieval
4,200
54,800
src/auth/tokens.ts241 lines.
Retrieval
3,100
57,900
src/middleware/auth.ts196 lines.
Retrieval
2,700
60,600
npm test2 failures, 84 passes, with stack traces.
Retrieval
7,400
68,000
tests/auth.test.ts412 lines.
Retrieval
5,800
73,800
git diff HEAD~3Nine files, mostly unrelated to the bug.
Retrieval
3,900
77,700
src/db/schema.ts503 lines. Table definitions for the whole app.
Retrieval
6,200
83,900
Grep "refresh_token"38 matches, repo-wide.
Retrieval
2,400
86,300
src/api/routes.ts487 lines.
Retrieval
6,900
93,200
npm run buildSucceeds. 61 deprecation warnings, all printed.
Retrieval
8,200
101,400
migrations/0007_sessions.sql84 lines.
Retrieval
2,600
104,000
src/auth/refresh.ts363 lines. The actual bug lives here.
Retrieval
5,100
109,100
Skill: debugging-asyncBody loaded on demand. It was one line in the index until the agent decided it needed it.
Subagents
3,400
112,500
npm testAfter the first fix attempt. 1 failure remains.
Retrieval
7,800
120,300
src/auth/session.tsRead again. The first copy is 65,500 tokens back and the agent no longer trusts it.
Retrieval
4,400
124,700
Sentry: issue detailThe production stack trace, plus 12 recent events.
Tools
6,100
130,800
tests/integration/auth.spec.ts561 lines.
Retrieval
7,300
138,100
npm testThird run. Green.
Retrieval
8,100
146,200
Grep "SessionStore"19 matches.
Retrieval
2,900
149,100
src/lib/crypto.ts224 lines.
Retrieval
3,500
152,600
Subagent: audit call sitesRead 22 files in an isolated window. Returned a list of 3 affected sites and nothing else.
Subagents
1,800
154,400
What does a full window actually cost me
So that is what fills it. The consequence took me a while to join up. Every turn re-sends the whole window, so a full one is expensive. And somewhere along the way the agent stops attending to it properly, so a full one is also worse.
window at this turn
154,400 / 200,000
input tokens billed so far
2,250,000
1,078,000 of that is the always-on block, sent on all 22 turns.
modeled attention
22%
ModeledThe token figures are arithmetic on the session above. Attention is how well the coding agent can "pay attention" to every detail in the context window, which is similar to overfilling our brain with too much context. The attention percentage is an indication and not exact. It's meant to demonstrate the idea of context rot.
Paid every turn
The window ends at 154,400 tokens. But you do not buy that context once and keep it. It gets re-sent in full on every turn, because the model remembers nothing between turns and the only thing it knows is what I hand it this time.
So the bill is not 154,400. Across 22 turns it is 2,250,000 input tokens, which is 14.6 times what I thought I was spending. Every file the agent reads early is not paid for once, it is paid for on every turn that follows.
Everything that loaded before I typed anything comes to 49,000 tokens, and it never changes and never leaves, so it is re-sent 22 times. That is 1,078,000 tokens, roughly half the entire bill, spent on context that was sitting there before I typed anything.
Caching genuinely helps. Cache reads are cheaper than fresh input, and on a session shaped like this one most of that always-on block is a cache hit rather than a full-price re-read. It changes the price of re-sending. The re-sending still happens, and the count still climbs.
Context rot
Money I can at least see on a bill. The other cost is the one I could not see at all, and it is the reason I built this thing.
Quality degrades as the window fills.[1] It happens slowly, with no error message and no line it crosses. The agent gets worse while sounding exactly as sure of itself, and it never tells you it has stopped being reliable. I have shipped code from the back half of a long session and not enjoyed the follow-up.
This is what I would call vibe coding. If we are conscious of our context window, we get to a better practice, or perhaps something we can call agentic engineering.
The 1M-token model does not fix this. These models still degrade once the context window is 40% to 50% full. It raises the ceiling on how much I can stuff in the context window before things break, which is not the same as fixing the underlying problem. The degradation shows up well below the advertised limit anyway.[2]
A bigger window is not a fix. It is more room to be wrong in.
The middle goes soft
How full the window is matters. So does where things sit in it. Models attend well at the beginning and well at the end, and in the long soft middle they attend badly.[3]
My AGENTS.md is fine, it is pinned at the top. The file the agent read twenty turns ago, the one it needs right now, is somewhere in the middle, and it may as well not be there. That is why the map blurs hardest through its middle rows and stays sharp at both ends.
They point the same way
Usually cost and quality pull against each other and I have to pick which one I am optimising for today. Here they do not. The full window is the expensive one and the stupid one at the same time, and every token I keep out of it is both cheaper and better.
That is genuinely a first for me. In my experience in IT it has always been that if you want something cheap, you get bad quality, and if you want something done well, you get an expensive solution. With coding agents the unusual position is that being disciplined about the context window gets me both. Being cheap is enough.
Sources
The numbers in the context window are half based on a real session and half made up, however the fundamental pieces of this writing are not. I lean a lot into the sources found below.
Liu, Lin, Hewitt, Paranjape, Bevilacqua, Petroni and Liang. Transactions of the ACL, vol. 12 (2024), pp. 157-173.
Accuracy is highest when the relevant text sits at the start or the end of the context, and drops when it sits in the middle.
Being conscious of your context is a desperately needed skill
Three quarters of that window went to things I never chose on purpose. Tool schemas for servers I never called. A test suite printed in full, three times. A file read twice because the first copy had drifted too far back to trust.
None of it was a mistake exactly. Each one was locally reasonable, and together they produced an agent that was worse at the end of the session than at the start.
My instinct when an agent starts failing is to give it more. More instructions, more files, a bigger window. Every one of those makes the actual problem worse, and the fix is to go the other way. Disconnect the MCP server I am not using. Put the thing that matters at the end rather than burying it in the middle. Send the expensive read into a subagent and take back a paragraph instead of forty thousand tokens.
The agent didn't forget. I overfilled it. That part, at least, I can fix.