You’re working with Aider and get:
Warning: messages exceed model context window (32768 tokens)
The conversation plus file contents exceeded your model’s context limit. Here are the fixes, from quickest to most thorough.
Fix 1: Drop files from context
Aider loads every added file into context. Remove files you’re not actively editing:
/drop src/large-file.ts
/drop src/utils/helpers.ts
# See what's loaded
/tokens
Only keep files Aider needs to edit. Reference files can be mentioned in your prompt instead of added to context.
Fix 2: Use a model with larger context
| Model | Context | Command |
|---|---|---|
| Qwen3 8B | 32K | aider --model ollama/qwen3:8b |
| Claude Sonnet | 200K | aider --model claude-sonnet-4 |
| GPT-5.4 | 1M | aider --model gpt-5.4 |
| GPT-5.4 Mini | 400K | aider --model gpt-5.4-mini |
| DeepSeek Chat | 128K | aider --model deepseek/deepseek-chat |
Switching from a 32K model to Claude Sonnet (200K) gives you 6x more context.
Fix 3: Reduce map tokens
Aider creates a “repo map” of your codebase. Reduce its size:
# Default map tokens varies by model
aider --map-tokens 1024 # Reduce from default
# Or disable the map entirely
aider --map-tokens 0
The repo map helps Aider understand your codebase structure, but it consumes context. For focused edits on specific files, you can reduce or disable it.
Fix 4: Start a fresh session
Long sessions accumulate context from previous messages:
# Clear and start fresh
/clear
# Or exit and restart
exit
aider src/specific-file.ts # Only add the file you need
Fix 5: Use /undo and retry concisely
If a failed attempt bloated the context:
/undo # Remove the last change and its context
# Then rephrase your request more concisely
Prevention
- Add only the files you’re editing, not the whole project
- Use specific, concise prompts (not “refactor everything”)
- Start fresh sessions for new tasks
- Use models with larger context for big refactors
- Check
/tokensregularly
Related: Aider Complete Guide · Aider Git Error Fix · Ollama Out of Memory Fix · Long-Running AI Agents · Best AI Coding Tools