Context management for long-horizon agent work
Published 29/10/2026
A long-horizon job is one that outlives a single context window: a migration over several days, a backlog worked through overnight, a codebase an agent maintains for weeks. On jobs like these the context window behaves less like memory and more like a desk. It is where the current work lies open, it is cleared regularly, and anything that only lived on the desk is gone when it is cleared.
So the question is not "how do I fit everything in the window?" but "what goes in the filing cabinet, and how does the desk get set up again each morning?"
What fills the window#
On a typical agentic coding session, the window fills with:
- Tool output. Test runs, build logs and search results are by far the biggest item. A single full test run can be thousands of lines.
- Exploration. File reads made to find out who calls what, often repeated after every compaction.
- The conversation itself, including plans that were later abandoned.
Every token in the window is paid for again on every later turn, as a cache read (see what a cold cache costs). Output that sits in the window for fifty turns costs fifty times.
Four habits that keep it lean#
- Keep big output out of the window. Store long logs outside the conversation and show the agent the head, the tail and the errors, with a way to page or search the rest on demand.
- Answer the exploration questions up front. "Who calls this file? Which tests reach it?" can be answered from a generated map of the code in a hundred tokens, instead of five file reads.
- Write state down as it happens. Decisions, open questions and dated observations go into records, not into the chat, so compaction cannot lose them. (Why this beats a summary.)
- Make a fresh start and a compacted one identical. If the same generated briefing arrives at session start and after compaction, compaction stops being an event you have to manage.
Small units of work#
The other lever is the size of each job. A change with a stated goal and a short list of paths fits comfortably in one window, even with review and tests. A vague "improve the auth module" does not, and it is the vague jobs that end up being compacted mid-flight. Long-horizon work goes better as many small, finished pieces than as one long unfinished one.
Where ADE fits#
Atlas ADE does each of these by default. ade q run keeps long output in a local store and shows the agent the parts that matter. The first-edit briefing answers the exploration questions from the graph in at most 250 tokens. Decisions, observations and questions are records, and the handover is generated from them at session start and after compaction. Every change is a card with paths and a done line. See Day to day and How it flies.