Tokens and Context Windows
Every file, rule, and message you send consumes tokens from a fixed context window. Budgeting context is the highest-leverage skill after writing clear prompts.
Last reviewed: June 2026
Context window sizes vary by model. Check Anthropic model docs and OpenAI model docs for current limits.
Prerequisites
Skim How LLMs Work for token prediction basics. This page focuses on practical budgeting in the IDE.
What Counts Toward Context
| Source | Typical cost |
|---|---|
System prompt + rules (AGENTS.md, .cursor/rules) | Fixed per session — keep lean |
| Conversation history | Grows every turn — summarize or reset |
| @Files / @Codebase attachments | Proportional to file size |
| Tool outputs (MCP, terminal) | Can explode quickly |
| Model response | Counts toward same window |
Input + output share one limit on most models.
Rough Size Estimates
| Content | Approx tokens |
|---|---|
| 1 line of code | 5–15 |
| 100-line file | 800–1,500 |
Full package.json + lock excerpt | 2,000+ |
| Long chat (20 turns) | 10,000+ |
Use provider tokenizers for accuracy: OpenAI tokenizer tool.
Priority Order (When Window Is Full)
When you must cut context, drop in this order:
- Old chat turns unrelated to current task
- Large generated outputs you already applied
- Broad @Codebase search results — replace with specific @Files
- Duplicate rules already in project defaults
- Never drop: security constraints, stack version, file boundary instructions
See Context Engineering for IDE tactics.
Attachment Strategies
| Strategy | When |
|---|---|
| @File specific paths | You know the module |
| @Codebase search | Unknown location; narrow query |
| MCP doc search | Internal KB too large to attach |
| Paste error only | Debug loop — not whole log file |
| New chat | Topic changed; history is noise |
Bad vs good context attachment
Bad: @Codebase + entire package-lock.json + 30-turn history for a one-line typo.
Good: New chat, @File src/components/Button.tsx, rules file loaded once, paste exact TS error.
Context Window by Use Case
| Task | Budget guidance |
|---|---|
| Inline completion | Current file + nearby imports only |
| Single-file bugfix | Target file + test file + error output |
| Cross-module refactor | Plan mode first; attach 3–5 files max per agent step |
| Large migration | Chunk by directory; multiple sessions |
Symptoms of Context Pressure
| Symptom | Likely cause | Fix |
|---|---|---|
| Model "forgets" rules mid-chat | Window full | New chat; shorten rules |
| Wrong file edited | Irrelevant files attached | Remove @ mentions |
| Slower responses | Huge attachments | Split task |
| Drops early instructions | Long prompt | Put constraints at top and bottom |
Cost Link
Tokens cost money in API products and often in IDE plans. See Cost, Latency, and Tokens.
For shipped features:
- Cache stable system prompts
- Summarize long histories server-side
- Use smaller models for classification; larger for generation
For Teams
| Policy | Recommendation |
|---|---|
| Rules file size | Keep AGENTS.md under ~500 lines; split by package in monorepos |
.cursorignore | Exclude node_modules, build output, secrets, large fixtures |
| Contractor access | Narrow repo scope — less context leakage risk |
| Logging | Do not log full prompts with PII in production apps |
Document exclusions in Team AI Policy.
Related
- How LLMs Work
- Context Engineering
- RAG for Codebases — when attachments are not enough
- Cost, Latency, and Tokens