pickuma.
Dev Knowledge

Context Windows in AI Coding Agents Explained

Context windows limit how much code an AI agent can see at once. Understanding that limit explains why agents miss files, repeat work, and sometimes lose track of the task.

5 min read

When you ask an AI coding agent to work on your project, the model does not have your entire codebase in its head. It has a context window, which is the fixed amount of text it can process in one go. For coding agents, that window is the budget for everything: your prompt, the files the agent reads, the agent’s own reasoning, and the response it produces.

Why Context Windows Matter

A typical coding agent context window ranges from 32,000 to 200,000 tokens. A token is roughly a word fragment. In practice, a large file might be a few thousand tokens, and a medium-sized codebase is hundreds of thousands of tokens.

That means the agent cannot load everything at once. It has to pick. If it picks the wrong files, it will make mistakes. If it picks the right files but misses a subtle interaction, it will still make mistakes.

How Agents Cope

Agents use several strategies to fit within the window:

  • File selection. They read only the files that seem relevant to the task.
  • Summarization. They condense long files into shorter notes.
  • Iterative reading. They read a file, decide what to do, then read another file.
  • Context files. They load a project conventions file that gives high-level guidance without reading every file.

Each strategy trades completeness for capacity. The agent is constantly deciding what to keep and what to ignore.

OpenCode

OpenCode lets you configure context file patterns so the agent loads the right files and keeps the most relevant code within its context window.

Free tier available

Try OpenCode

Affiliate link · We earn a commission at no cost to you.

What This Means for Your Project

You can make the agent more effective by reducing what it has to load:

  • Keep files focused. A 5,000-line file is harder to load than five 1,000-line files.
  • Use clear names. The agent searches by name and keyword.
  • Provide a map. A CONTEXT.md or architecture note gives the agent the big picture without reading the whole repo.
  • Scope your requests. “Update the auth middleware” is easier than “fix the app.”

Local Models and Context

Local models often have smaller context windows than cloud models. If you run OpenCode against a local 14B model, you might have 32K tokens to work with. That is enough for a single-file task or a small refactor, but not for a large cross-file change. Plan local-model tasks accordingly.

FAQ

How do I know how big my context window is?
Check your model provider's documentation. Claude Sonnet and GPT-4o offer large windows, often 128K-200K tokens. Local models vary widely, from 8K to 128K.
Can the agent remember what it read earlier?
Only what stays in the context window. If the agent reads a file early in the session and then does many other things, it may lose details from that file unless it summarized them.
Why does the agent ask for the same file twice?
It may have dropped the file from context or need to re-read it after making changes. Re-reading is normal in long sessions.

Tools used in this review

Some links above are affiliate links. We may earn a commission if you sign up. See our disclosure for details.

Related reading

See all Dev Knowledge articles →

Get the best tools, weekly

One email every Friday. No spam, unsubscribe anytime.