Every coding agent works inside a context windowContext windowMaximum text an LLM can process at once, in tokens. Exceeding it causes earlier content to be forgotten.Learn more →: a fixed budget of tokens holding your instructions, the code it has read, the conversation so far, and its own output. Understanding this budget is the difference between an agent that stays sharp and one that gets slow, expensive, and confused.
What a token is
A token is roughly three-quarters of a word, or a few characters of code. Your prompt, every file the agent reads, every tool result, and every reply all consume tokens. Models have a large but finite window (hundreds of thousands of tokens on current models). You are billed per token, input and output, so context is both a capability limit and a cost lever.
Why a full context hurts
More context is not better. As the window fills:
- Cost and latency rise. Every turn reprocesses the accumulated context, so a long session gets pricier and slower with each message.
- Focus drops. Relevant details get diluted by noise. An agent buried in twenty half-relevant files reasons worse than one looking at the three that matter. This is sometimes called context rot.
- You hit the ceiling. Overflow forces truncation or summarization, and the agent silently forgets earlier decisions.
A worked example of the cost
Say a task genuinely needs three files totaling about 800 lines. Read those directly and you spend a few thousand input tokens per turn. Now imagine you instead say "look through the repo and figure it out" on a 200k-line codebase. The agent greps, opens a dozen files, reads a lockfile it did not need, and each subsequent turn re-sends all of it. Same task, ten times the tokens, and worse answers because the signal is buried. The fix is not a bigger window; it is pointing at the three files.
Include the right things, exclude the rest
Curate what the agent sees:
- Include the specific files and symbols the task touches, the spec, and any pattern to follow.
- Exclude generated code,
node_modules, lockfiles, and giant data files. Use.gitignoreand tool-level ignore files (a.cursorignore, or the ignore rules Claude Code honors) so the agent does not read them. - Reference exact paths instead of asking the agent to search the whole repo, which pulls in far more than you need.
Keep sessions focused
Start a fresh conversation for a new task. Long-running chats accumulate stale context from unrelated work that confuses the agent and wastes tokens. In Claude Code, /clear resets the conversation and /compact summarizes it, keeping the useful conclusions while dropping the raw back-and-forth. A good rule: one task, one session.
Signs your context is bloated
Watch for these tells and reset when you see them:
- Replies slow down noticeably as the session grows.
- The agent contradicts a decision you made earlier in the same thread.
- It re-reads files it already read, or asks about things you covered.
- It "forgets" a constraint you stated ten messages ago.
Any of these means it is time to /compact, /clear, or restate the essentials in a fresh thread.
Awareness of consumption
Treat tokens like a metered utility. Habits that keep cost and quality in check:
- Point at files instead of dumping the whole repo into context.
- Prefer several small, scoped sessions over one sprawling one.
- Do not paste large logs or data blobs when a summary or the relevant ten lines will do.
- Let the agent read what it needs rather than pre-loading everything "just in case."
- Persist durable facts (conventions, architecture) in
CLAUDE.mdso you are not re-explaining them every session and paying for it each time.
Rules of thumb
- One task, one session. Clear or compact between tasks.
- Name paths; do not make the agent search when you know where the code is.
- If a paste is longer than the code you are changing, trim it.
- When the agent starts forgetting or slowing down, reset instead of pushing through.
The mental model
Context is a desk, not a warehouse. A cluttered desk slows you down even though everything is technically within reach. Keep on it only what the current task needs, clear it between jobs, and the agent stays fast, cheap, and accurate.