Skip to content

The context window

Foundations

If you only learn one thing from these Foundations, learn this. The context window is the single constraint that shapes how every AI tool behaves. Get a feel for it and everything else (better prompts, cleaner workflows, fewer wrong answers) follows almost for free.

The context window is the model’s working memory: a finite space holding everything it is considering right now. That includes more than your last message:

  • Your messages, and the model’s own replies so far
  • The contents of any file it has read
  • The output of any command it ran
  • Its standing instructions (system prompt, your persistent-instructions file)

If something is not in that window, the model does not know it; see How AI coding tools work. The window is the model’s entire awareness of your task.

The window has a fixed size, measured in tokens (roughly, pieces of words). Today’s models hold context measured in the hundreds of thousands of tokens, and some now reach a million. That sounds enormous. It runs out faster than you’d think. The part people miss: it gets worse long before it runs out.

There are two distinct failure modes:

  1. It fills up. A long session of reading files and running commands packs the window. When it hits the limit, the oldest content falls out or the tool compresses it, and detail is lost.
  2. It degrades. Long before the hard limit, a window stuffed with old tangents, dead ends, and irrelevant output buries the signal. The model loses the thread, repeats itself, forgets an instruction you gave ten minutes ago, or contradicts an earlier decision. People call this context rot.

Treat the context window like a desk, not a warehouse. Keep what you’re using on it and clear the rest. The exact commands differ per tool, but the moves are the same everywhere:

MoveWhen to use itTypical form
Start freshYou’re switching to an unrelated taskNew chat, or /clear in a terminal agent
CompactThe thread is long but still mattersA /compact or “summarize and continue” step
Watch usageAlwaysThe token / context indicator the tool shows you
Scope tightlyEvery promptPoint at the 2–3 relevant files, not the whole repo

The biggest single habit: a fresh conversation per task. Carrying a finished task into the next one is the most common way people quietly poison their results.

Almost every advanced technique in these guides is, underneath, a way of putting the right things in the context window and keeping the wrong things out. Choosing which files to load, writing a persistent-instructions file, planning before doing: all of it is context management. That craft has a name: Context engineering.

Context limits and the commands to manage them show up in every tool, most visibly here: