context-windows.mdx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ---
  2. title: "Context Window Guide"
  3. description: "Understanding and managing AI model context windows"
  4. ---
  5. ## What is a Context Window?
  6. A context window is the maximum amount of text an AI model can process at once. Think of it as the model's "working memory" - it determines how much of your conversation and code the model can consider when generating responses.
  7. <Note>
  8. **Key Point**: Larger context windows allow the model to understand more of your codebase at once, but may increase costs and response times.
  9. </Note>
  10. ## Context Window Sizes
  11. ### Quick Reference
  12. | Size | Tokens | Approximate Words | Use Case |
  13. |------|--------|------------------|----------|
  14. | **Small** | 8K-32K | 6,000-24,000 | Single files, quick fixes |
  15. | **Medium** | 128K | ~96,000 | Most coding projects |
  16. | **Large** | 200K | ~150,000 | Complex codebases |
  17. | **Extra Large** | 400K+ | ~300,000+ | Entire applications |
  18. | **Massive** | 1M+ | ~750,000+ | Multi-project analysis |
  19. ### Model Context Windows
  20. | Model | Context Window | Effective Window* | Notes |
  21. |-------|---------------|------------------|-------|
  22. | **Claude Sonnet 4.5** | 1M tokens | ~500K tokens | Best quality at high context |
  23. | **GPT-5** | 400K tokens | ~300K tokens | Three modes affect performance |
  24. | **Gemini 2.5 Pro** | 1M+ tokens | ~600K tokens | Excellent for documents |
  25. | **DeepSeek V3** | 128K tokens | ~100K tokens | Optimal for most tasks |
  26. | **Qwen3 Coder** | 256K tokens | ~200K tokens | Good balance |
  27. *Effective window is where model maintains high quality
  28. ## Managing Context Efficiently
  29. ### What Counts Toward Context
  30. 1. **Your current conversation** - All messages in the chat
  31. 2. **File contents** - Any files you've shared or Cline has read
  32. 3. **Tool outputs** - Results from executed commands
  33. 4. **System prompts** - Cline's instructions (minimal impact)
  34. ### Optimization Strategies
  35. #### 1. Start Fresh for New Features
  36. ```
  37. /new - Creates a new task with clean context
  38. ```
  39. Benefits:
  40. - Maximum context available
  41. - No irrelevant history
  42. - Better model focus
  43. #### 2. Use @ Mentions Strategically
  44. Instead of including entire files:
  45. - `@filename.ts` - Include only when needed
  46. - Use search instead of reading large files
  47. - Reference specific functions rather than whole files
  48. #### 3. Enable Auto-compact
  49. Cline can automatically summarize long conversations:
  50. - Settings → Features → Auto-compact
  51. - Preserves important context
  52. - Reduces token usage
  53. ## Context Window Warnings
  54. ### Signs You're Hitting Limits
  55. | Warning Sign | What It Means | Solution |
  56. |-------------|---------------|----------|
  57. | **"Context window exceeded"** | Hard limit reached | Start new task or enable auto-compact |
  58. | **Slower responses** | Model struggling with context | Reduce included files |
  59. | **Repetitive suggestions** | Context fragmentation | Summarize and start fresh |
  60. | **Missing recent changes** | Context overflow | Use checkpoints to track changes |
  61. ### Best Practices by Project Size
  62. #### Small Projects (< 50 files)
  63. - Any model works well
  64. - Include relevant files freely
  65. - No special optimization needed
  66. #### Medium Projects (50-500 files)
  67. - Use 128K+ context models
  68. - Include only working set of files
  69. - Clear context between features
  70. #### Large Projects (500+ files)
  71. - Use 200K+ context models
  72. - Focus on specific modules
  73. - Use search instead of reading many files
  74. - Break work into smaller tasks
  75. ## Advanced Context Management
  76. ### Plan/Act Mode Optimization
  77. Leverage Plan/Act mode for better context usage:
  78. - **Plan Mode**: Use smaller context for discussion
  79. - **Act Mode**: Include necessary files for implementation
  80. Configuration:
  81. ```
  82. Plan Mode: DeepSeek V3 (128K) - Lower cost planning
  83. Act Mode: Claude Sonnet (1M) - Maximum context for coding
  84. ```
  85. ### Context Pruning Strategies
  86. 1. **Temporal Pruning**: Remove old conversation parts
  87. 2. **Semantic Pruning**: Keep only relevant code sections
  88. 3. **Hierarchical Pruning**: Maintain high-level structure, prune details
  89. ### Token Counting Tips
  90. #### Rough Estimates
  91. - **1 token ≈ 0.75 words**
  92. - **1 token ≈ 4 characters**
  93. - **100 lines of code ≈ 500-1000 tokens**
  94. #### File Size Guidelines
  95. | File Type | Tokens per KB |
  96. |-----------|---------------|
  97. | **Code** | ~250-400 |
  98. | **JSON** | ~300-500 |
  99. | **Markdown** | ~200-300 |
  100. | **Plain text** | ~200-250 |
  101. ## Context Window FAQ
  102. ### Q: Why do responses get worse with very long conversations?
  103. **A:** Models can lose focus with too much context. The "effective window" is typically 50-70% of the advertised limit.
  104. ### Q: Should I use the largest context window available?
  105. **A:** Not always. Larger contexts increase cost and can reduce response quality. Match the context to your task size.
  106. ### Q: How can I tell how much context I'm using?
  107. **A:** Cline shows token usage in the interface. Watch for the context meter approaching limits.
  108. ### Q: What happens when I exceed the context limit?
  109. **A:** Cline will either:
  110. - Automatically compact the conversation (if enabled)
  111. - Show an error and suggest starting a new task
  112. - Truncate older messages (with warning)
  113. ## Recommendations by Use Case
  114. | Use Case | Recommended Context | Model Suggestion |
  115. |----------|-------------------|------------------|
  116. | **Quick fixes** | 32K-128K | DeepSeek V3 |
  117. | **Feature development** | 128K-200K | Qwen3 Coder |
  118. | **Large refactoring** | 400K+ | Claude Sonnet 4.5 |
  119. | **Code review** | 200K-400K | GPT-5 |
  120. | **Documentation** | 128K | Any budget model |