TIPS & TRICKS · AGENTS · CONTEXT
Keep the Context Small: Faster, Sharper Agents
A coding agent works best when its context holds only what the task needs. Use a lean project file, point at the right files, and keep one task per session.
3 Nov 2026 · 5 min read
Everything a coding agent knows about your task lives in its context window: your instructions, the files it has read, every command and its output, and the whole conversation so far. That window is large, but it is not free, and it is not neutral.
Every turn, the model rereads all of it. A bigger context is slower and costs more. Worse, quality drops. The detail that matters, like a constraint you mentioned at the start, has to compete with three thousand lines of test output from twenty minutes ago. Agents with bloated contexts forget instructions, repeat work and drift off task.
So treat context like memory in a small device: keep what the task needs, drop the rest.
A lean project instructions file
Most agents read a project file on every task, such as CLAUDE.md or AGENTS.md. Because it is loaded every time, every line in it costs you on every task. Keep it to things that are always true and not obvious from the code:
- how to build, test and run the project, as exact commands;
- the few rules that apply everywhere (“never commit
.envfiles”, “all prices are integers in cents”); - where the important things live (“problem write-ups are in
src/content/problems”).
What does not belong there: long explanations of how modules work (the agent can read them), procedures you need once a week (make those skills), and history (“in 2024 we migrated from…”). If the file is past a page or two, trim it. A short file that is always followed beats a long one that is half ignored.
Point at the right files
Left alone, an agent searches. That is useful, but every file it opens to check “is this the one?” stays in the context. If you know where the work is, say so:
The bug is in
src/lib/streak.ts,getStreak(). The test file issrc/lib/streak.test.ts. You should not need to read anything else.
Two sentences save a dozen file reads. The same goes for logs: paste the twenty relevant lines of an error, not the whole build output.
When the agent does need to explore a large codebase, many tools can hand the search to a sub-agent that reads widely in its own separate context and returns only a short summary. The main conversation gets the answer without the forty files it took to find it.
Keep tool output short
Commands are a common source of bloat. A full test run, a verbose build or a big git diff can add thousands of lines in one go. Ask for focused output:
- run just the failing test file, not the whole suite, while iterating;
- use quiet flags, and filter with
greportail; - look at
git diff --statbefore the full diff.
Run the full suite once at the end, as the final check.
One task per session
This is the biggest win. When a task is done, start a fresh session for the next one. A session that has already fixed a bug, refactored a module and debugged a deploy carries all of that into the fourth task, where none of it helps and much of it confuses.
Signs that a session has gone stale:
- the agent re-asks something you answered earlier;
- it reintroduces an approach you already rejected;
- responses get slower and vaguer;
- it confuses two files or two tasks.
When you see these, do not argue with it. Ask for a short summary of where things stand, start a new session, and paste the summary in. You keep the useful state and drop the noise.
Use files as memory
For work that spans sessions, keep the state in files rather than in a conversation. A plan in docs/plan.md, a hand-off note at the end of the day, a checklist of what is done. The next session reads one short file instead of reliving a long chat. This is also how a team shares work between people and agents: the file is the source of truth, not anybody’s context window.
Clear up after detours
If a session wanders, say into an investigation that turned out to be unrelated, many tools let you compact or clear the history. Use it. Or simply say: “Ignore the logging investigation above; it was unrelated. Back to the streak bug.” Explicitly marking something as irrelevant helps the model weigh it down.
Takeaway: the context window is the agent’s working memory, and smaller is sharper. Keep the project file short, point at the exact files, trim command output, and start one fresh session per task, carrying state forward in files rather than in a long chat.