Real Use Case

Use Case #11: Context Window Optimization

Techniques for managing context windows, reducing token usage, and maintaining coherence across long sessions.

W

William Welsh

Author

Jan 10, 2026
7 min read

Use Case #11: Context Window Optimization

I ran out of context mid-task. Important information lost. Work duplicated. Frustrating.

So I learned to optimize.

The Problem

Context windows have limits. MCPs consume tokens just sitting there. Long conversations hit walls. Sessions compact and lose nuance.

What I Learned

1. MCP Loading is Expensive - Each MCP adds 3K-20K tokens just to exist in context. Having 7 MCPs loaded when you only need 1? Wasted space. Solution: MCP profiles. Load only what's needed.

2. Subprocess Delegation - Need to use an MCP once? Don't load it permanently. Delegate with "/mcp run notion query database X". This spawns a subprocess with Notion loaded, runs the query, returns results, and restores original config. No permanent context cost.

3. Prompt Structure Matters - Bad: "Can you look at the code in the file I mentioned earlier and see if there's a problem with the thing we discussed?" Good: "Fix the auth bug in src/auth/login.ts:45 - the token validation should check expiry before checking signature." Specific prompts use fewer tokens and get better results.

4. Summary Checkpoints - Before hitting context limits, create explicit summaries: "Summarize what we've done so far and the current state." This creates a resumption point that survives compaction.

5. Reference Don't Repeat - Let Claude read what it needs rather than stuffing context with content it already has access to.

Results

MetricBeforeAfter
Average session length45 min90 min
Compaction events3-4 per session1-2
Information lossFrequentRare
MCP token overhead60K+15K

The Meta Lesson

Claude Code is a tool. Tools have constraints. Understanding the constraints lets you work with them instead of against them.


These patterns emerged from 500+ sessions of optimization.

W

William Welsh

Building AI-powered systems and sharing what I learn along the way. Founder at Tech Integration Labs.

View Profile
Share this article:

Related Articles

View all →