AI Coding Entry

Context management, explained

Reviewed August 2026

TL;DR: Everything a coding agent knows about your task lives in its context window, and that window is finite. Context management is the craft of keeping what is in it relevant - compacting old history, externalizing knowledge to memory files, delegating searches to subagents - because an agent drowning in stale file dumps writes worse code than one with a clean desk.

How it works

An agent's context window is its entire working memory: the instructions, the conversation, and every tool result - each file read, each test run - accumulates there. A long session fills it fast, and with the wrong things. After two hours of debugging, the window holds five versions of the same file, three dead-end hypotheses, and pages of logs. Quality degrades well before the hard limit is hit: the model starts attending to stale copies and abandoned plans as if they were current. Practitioners call it context rot.

The first family of fixes shrinks what is there. Compaction summarizes older conversation into a short recap, keeping decisions while dropping the noise that led to them. Most agents auto-compact near the limit, but deliberate compaction - or simply starting a fresh session per task - beats emergency compaction, which cannot know which details tomorrow's step will need. Scoping helps the same way from the front: three focused sessions beat one sprawling one because each window stays coherent.

The second family moves knowledge out of the window entirely. Durable facts - build commands, conventions, architecture notes - belong in instruction files like AGENTS.md, loaded fresh each session instead of rediscovered each time. Notes an agent writes for its own future reference are a simple form of agent memory. And subagents protect the window by contract: a helper agent burns its own context reading thirty files to answer "where is retry logic implemented?", and only the two-line conclusion returns to the main agent.

A concrete before-and-after: asked to fix a failing checkout test, a naive session dumps the whole test suite and six source files into context, wanders, and starts contradicting itself. A managed session reads the instruction file, sends a subagent to locate the relevant code, pulls in only the two files that matter, and fixes the bug with room to spare. Same model, same task - the difference is what the model was looking at. That is why context management, not prompt phrasing, is where experienced agent users spend their effort.

Where it sits in the AI stack

Context management is the filter between everything an agent could know and the window the model actually sees:

Key tools and implementations

  • Auto-compaction

    Built into agents like Claude Code - older conversation is summarized in place as the window fills.

  • Instruction + memory files

    AGENTS.md and CLAUDE.md style files that hold durable project knowledge outside the session.

  • Subagent delegation

    Spawning helper agents whose file dumps stay in their own context, returning only conclusions.

  • Prompt caching

    An inference-side companion that makes re-sending stable context cheap and fast across turns.