Overview
Context Optimizer helps you manage your context window and token budget effectively. It provides strategies for proactive compaction, MCP audits, subagent delegation, and CLAUDE.md optimization.Quick Diagnosis
Optimization Strategies
Immediate Actions
| Action | Saves | When |
|---|---|---|
/compact | 30-50% context | At task boundaries |
| Disable unused MCPs | ~5% per MCP | When switching domains |
| Use subagents for exploration | Keeps main context clean | Heavy search/read tasks |
Fresh session via /resume | 100% reset | When starting unrelated work |
Configuration
Set proactive auto-compaction:Default auto-compact triggers at ~95%. Override to 50% for proactive compaction before quality degrades.
Context Discipline Rules
1. Read Before Edit
1. Read Before Edit
Always read files before editing. Builds accurate context.Bad:Good:
2. Compact at Task Boundaries
2. Compact at Task Boundaries
Manual compact between major tasksGood compact points:
- After planning, before execution
- After completing a feature
- When context >70%
- Before switching task domains
3. Disable Unused MCPs
3. Disable Unused MCPs
Keep <10 MCPs enabled, <80 tools totalEach MCP adds overhead to every request.
4. Summarize Explorations
4. Summarize Explorations
After exploring code, summarize findingsInstead of:
- 50 file reads in context
- Explore with subagent
- Subagent returns summary
- Main session stays clean
5. Delegate High-Volume Tasks
5. Delegate High-Volume Tasks
Use subagents to isolate high-volume outputDelegate to subagents:
- Test suite output
- Large file exploration
- Documentation generation
- Log analysis
Context Compaction
How It Works
- Auto-compacts at ~95% capacity (keeps long-running agents alive)
- Configure earlier:
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50 - PreCompact hooks save state before compaction
- Subagents auto-compact independently from main session
Manual Compaction
- Before Compact
- After Compact
MCP Audit
Keep <10 MCPs enabled, <80 tools total.Essential MCPs
context7
Live documentation lookup
playwright
Browser automation (token-efficient)
github
PRs, issues, code search
Audit Process
- MCPs used <1x per week
- Overlapping functionality (e.g., 2 database MCPs)
- Development-only MCPs in production sessions
- Essential for current project domain
- Used >3x per session
- No alternatives available
Prompt Engineering for Efficiency
Scoped Prompts
Provide Constraints
Give Acceptance Criteria
Subagent Delegation
Heavy operations that generate lots of output should go to subagents:Test Suite Output
Test Suite Output
Large File Exploration
Large File Exploration
Documentation Generation
Documentation Generation
Log Analysis
Log Analysis
Context Budget Planning
Plan your context usage by phase:| Phase | Target Usage | Action If Over |
|---|---|---|
| Planning | < 20% | Keep plans concise |
| Implementation | < 60% | Compact between files |
| Testing | < 80% | Delegate to subagent |
| Review | < 90% | Start fresh session |
If you hit 90% during implementation, you’re doing too much in one session. Compact or break into smaller tasks.
CLAUDE.md Optimization
Size Guidelines
- Root CLAUDE.md: < 60 lines ideal, < 150 max
- Package-level: Move package-specific info here
- CLAUDE.local.md: Personal preferences
- Remove: Obvious or rapidly-changing information
Split Memory Architecture
- Keeps root file concise
- Modular, easy to maintain
- Learnings don’t clutter core instructions
When Context Is Degraded
Signs
- Claude repeats itself or forgets earlier context
- Responses become generic or lose project-specific knowledge
- Tool calls start failing for reasons that worked earlier
- “I don’t recall” or “I don’t have that information”
Fix
Examples
Example 1: Proactive Compaction
Example 2: MCP Audit
Example 3: Subagent Delegation
Integration with Pro Workflow
Pro Workflow
Context discipline is a core pattern
Parallel Worktrees
Worktrees isolate context by task
Orchestrate
Subagents keep research phase context clean
Insights
Track context usage patterns over time
Best Practices
Compact at 50%, Not 95%
Compact at 50%, Not 95%
Don’t wait for auto-compact. Manual compact at 50% keeps quality high.
Start Sessions Clean
Start Sessions Clean
Use
/resume to start fresh with relevant history, not /reopen with full context.One Domain Per Session
One Domain Per Session
Don’t work on auth, then database, then UI in one session. Context gets muddy.
Delegate Heavy Operations
Delegate Heavy Operations
Tests, logs, large file reads — all go to subagents. Main session for high-level decisions.
Troubleshooting
Context Always Full
Check:- CLAUDE.md size (<60 lines?)
- Active MCP count (<10?)
- Auto-compact percentage (set to 50%?)
- Are you reading too many files without summarizing?
Auto-Compact Not Triggering
Verify:Subagents Not Helping
Ensure:- Subagent has
background: true - Subagent returns summary, not full output
- Main session doesn’t read subagent’s tool outputs
Next Steps
Master Pro Workflow
Context discipline is a core pillar
Try Parallel Worktrees
Isolate context by task with worktrees
Learn Orchestrate
Multi-phase development with clean context
View All Skills
Explore the complete skill system