Blowing Through Context Windows
In January I started pair-programming every day with Amazon Q, and later with Kiro, Amazon's newer AI coding tool, on a large, old .NET codebase. I'd like to tell you it went great from the start. It didn't. I had to watch it like a hawk.
This is the first in a short series about my progress. Nothing in it is fancy. It's a handful of folders and habits I built up one at a time, each one because I got tired of watching the same thing go wrong.
What a context window is
If you haven't worked with these tools much, here's the one idea you need. The agent can only keep so much in front of it at once. Everything in the session counts against that limit: what I type, what it says back, and every file it opens to look around. That limit is the context window.
Amazon Q tries to warn you as the window fills up. At around 70% it starts suggesting that you compact the conversation, which means having it write itself a summary of what happened so far, throw away the details, and keep going from the summary. Q won't do that on its own; you have to ask for it. And a summary is a summary. The details it throws away are often the ones you needed.
At 80%, Q may simply clear the whole conversation. And if the agent reads a large file and jumps from under 70% to past 80% in one step, you never see the warning at all. Your chat history is just gone. (Kiro, as I learned later, compacts on its own in both the IDE and the CLI. More on that in a later post.)
What getting nowhere looked like
A typical session went like this. I'd describe a bug, and the agent would start exploring. It would search for a word, open a file, search again, open another file, and so on. In a newer codebase that might be fine. In ours, some of those files are thousands of lines long, and every one it opened ate a big piece of the window.
By the time it had a theory, the window was nearly full. Then I'd compact it, and the summary would keep the theory but lose most of what it had read to get there. So it would go back and read the same files again, sometimes the same file over and over in one session. More than once I watched it rediscover something it had figured out an hour earlier. Ouch!
The turning point
What finally changed my thinking was noticing that the agent would rather guess a table or column name than look it up. The guesses sounded right, and they were often wrong. If the real names are written down where it can find them, checking takes a few seconds, and it stops making them up.
That's really the whole idea behind this series. Instead of letting the agent rediscover the codebase every session, I started giving it small, focused notes it could read on demand: one file per database table, a map of how the main classes relate, and a folder of things we'd learned the hard way. None of them are clever. What makes them work is that each one is small, so the agent can read exactly what it needs and leave the rest of the window for the actual problem.
Next time I'll start with the rules folder, and my early decision to keep the details out of the context window until the agent actually needs them.
If you've hit the same wall with these tools, I'd like to hear how you got around it.
Comments
Post a Comment