Context Management Strategies
Universal patterns for managing token budget efficiently in long conversations.
Core Principles
- •Search before read - Find what you need, don't read everything
- •Progressive disclosure - Overview → Sample → Targeted deep-dive
- •Summarize as you go - Extract key points, discard verbose content
- •Save large outputs to files - Keep conversation context lean
- •Proactive awareness - Monitor usage, warn before limits
Smart Reading Strategy
For Any Large Content
code
Step 1: List/Search → Identify what exists Step 2: Quick scan → Read headers/summaries only Step 3: Relevance ranking → Prioritize what matters Step 4: Targeted reading → Deep dive only on relevant sections Step 5: Synthesize → Create concise summary, reference files for details
Progressive Disclosure Pattern
| Phase | Context Cost | Action |
|---|---|---|
| Discovery | Low | List files, search keywords |
| Sampling | Medium | Read first N lines, headers only |
| Targeted | Medium-High | Read specific sections of interest |
| Full | High | Only if absolutely necessary |
File-Based Output Strategy
When outputs would be large (>100 lines, >1000 rows):
markdown
✅ GOOD: Save to file, show summary "Saved 1,500 results to output/analysis.csv Summary: Top 10 items by revenue..." ❌ BAD: Dump everything into conversation [1,500 rows of data filling context...]
When to Save to Files
- •Query results > 100 rows
- •Code generation > 100 lines
- •Analysis with detailed breakdowns
- •Multi-step outputs with intermediate results
- •Reference material for later use
Context Checkpoints
Periodically assess context usage:
markdown
**Context Check**: ~60% used - Explored: 15 files ✓ - Key findings: documented ✓ - Remaining work: 3 tasks **Action**: Continuing normally
markdown
**Context Check**: ⚠️ ~85% used **Saving state**: - Analysis summary → saved to scratch/analysis_summary.md - Query history → saved to scratch/queries.sql **Options**: A) Run `/compact` to continue with fresh context B) Focus on specific remaining question C) Wrap up with executive summary
Proactive Warnings
Before large operations, warn:
markdown
"This query will return ~50,000 rows. **Context Management Plan**: ✓ Execute query ✓ Save full results to CSV ✓ Show summary statistics in chat ✓ Display top 20 rows as preview This keeps our conversation efficient. Proceed?"
Best Practices Checklist
Before each major read:
- • Will this return >100 lines? → Sample first
- • Multiple files to read? → Search for relevant ones
- • Already at 70% context? → Save next output to file
During exploration:
- • Check context every 5-10 operations
- • Save intermediate findings to files
- • Aggregate instead of showing raw data
When context is low:
- • Immediately save current state
- • Summarize findings so far
- • Suggest
/compactor focused continuation - • Offer clear next steps
Recovery Patterns
When You Hit the Limit
markdown
⚠️ Context limit approaching **Saved to files**: - findings.md - Key discoveries - next_steps.md - Remaining work **Summary**: [Key points that survive context reset] **To continue**: Run `/compact`, then reference saved files
Handoff Format
When context resets are needed, save:
markdown
# Session Handoff ## Completed - [What was accomplished] ## Key Findings - [Important discoveries] ## Remaining Work - [What still needs to be done] ## Files to Reference - path/to/relevant/files
Remember
Context is a precious resource. Be surgical: search to find, sample to assess, read only what matters. Save verbose outputs to files and keep the conversation focused on insights and decisions, not raw data.