intermediate ⏱ 15 minutes 12 min read

Claude Code Context Mode — Stop Wasting 70% of Your Token Budget

Your Claude Code sessions waste 70% of context before you write code. Context Mode cuts token usage by 25-99% and extends sessions to 3+ hours. Here's how.

claude-codemcpcontext-modetoken-optimizationcost-reductionai-development Mar 13, 2026
prerequisites
  • Claude Code installed
  • Basic knowledge of MCP tools
tools used
last tested
2026-03-13

The Problem: Your Context Window is Bleeding Tokens

If you’ve used Claude Code for serious work—especially multi-file projects or research tasks—you’ve hit the wall: context compaction.

Here’s what happens:

  1. You fire up Claude Code with a fresh conversation (200K token window)
  2. You use MCP tools: Playwright snapshots, GitHub issue reads, file system scans, analytics exports
  3. Each tool dumps raw output directly into your context window
  4. 30 minutes later: Your context is 70% full, AI starts forgetting previous decisions, you hit compaction
  5. Tokens evaporate: A single Playwright snapshot of a web page is 56 kilobytes. Read 20 GitHub issues (59 KB). A production log file (315 KB). That’s context bloat.

The math is brutal:

  • Playwright snapshot: 56 KB
  • 20 GitHub issues: 59 KB
  • Production logs: 315 KB
  • Analytics CSV: 50+ KB

Do this a few times in a session and you’ve consumed 70% of your window before Claude writes a single line of code. Not only are you running out of space—you’re also paying for every token that gets re-sent with each message.

Why This Happens

Claude Code has no built-in optimization for tool outputs. Every MCP call returns its full result, and that result stays in the conversation forever. The more tools you have in your belt, the faster your context depletes. Under typical conditions, you’re looking at 30 minutes of active agent use before compaction kicks in.

And when context compacts? Claude loses track of files you opened 10 minutes ago, decisions you made, failed approaches it shouldn’t repeat.


The Solution: Context Mode

There’s an MCP server that solves this. It’s called Context Mode, and it’s beautifully simple: instead of dumping raw tool output into your context window, it virtualizes the output. The AI doesn’t see raw data—it gets a confirmation that data is indexed, and then queries it intelligently.

The result: 98% token reduction on large files, and sessions that extend from 30 minutes to 3+ hours.

How Context Mode Works

Context Mode acts as a virtualization layer between your AI and your operating system:

  1. You run a tool call (Playwright snapshot, file read, API call, log analysis)
  2. Raw output goes to sandbox, not to context window
  3. Output is indexed in a local SQLite database using FTS5 (full-text search)
  4. AI receives confirmation: “315 KB file indexed. Ready to query.”
  5. AI queries the database instead of parsing raw text
  6. Result: Intelligent search without the token cost

Real example from the demo:

Raw access.log file: 5,000 lines (20 KB)
Dumped to context: Would be ~5 KB in the window
With Context Mode: Stays in sandbox, AI queries indexed database
Result: 1,200 tokens saved (25% reduction)

Scale to production: 100,000+ tokens saved on large repos

That 315 KB analytics CSV? Context Mode reduces it to 5.4 kilobytes in the context window. 98% reduction.

The Secret: Session Checkpoints

The really clever part isn’t just token reduction—it’s session continuity.

Context Mode uses hooks to monitor every file edit, git operation, and sub-agent task. When your conversation compacts, it doesn’t lose everything. Instead:

  1. Context Mode creates a snapshot (usually under 2 kilobytes) of critical decisions
  2. It injects that snapshot back when context resets
  3. The AI remembers: What code was written, what failed, what shouldn’t be tried again

This single feature can extend your session from 30 minutes to 3+ hours, because the AI never forgets the previous context—it’s restored intelligently after compaction.


Installation: 5 Minutes, 2 Commands

Context Mode installation depends on which development environment you use.

For Claude Code (Native Integration)

/plugin marketplace add mksglu/context-mode
/plugin install context-mode@context-mode

That’s it. Claude Code handles the rest automatically—the MCP server, the hooks, the routing.

For VS Code Copilot, Gemini CLI, Cursor, or Codex

npm install -g context-mode

Then register the MCP server in your platform’s config:

VS Code Copilot (~/.vscode/extensions/copilot/mcp-config.json):

{
  "mcp-servers": {
    "context-mode": {
      "command": "context-mode",
      "args": ["server"]
    }
  }
}

Gemini CLI (~/.config/gemini/mcp-config.json):

{
  "mcp-servers": {
    "context-mode": {
      "command": "context-mode",
      "args": ["server"]
    }
  }
}

Cursor (~/.cursor/mcp-config.json):

{
  "mcp-servers": {
    "context-mode": {
      "command": "context-mode",
      "args": ["server"]
    }
  }
}

Once installed, Context Mode runs in the background. You don’t interact with it directly—it just works.


Measuring Your Savings

After you install Context Mode, you can measure exactly how many tokens you’re saving. This is where the magic becomes real.

Step 1: Run a Typical Task

Open Claude Code and do what you normally do:

  • Read a large file or log
  • Query GitHub issues
  • Take Playwright snapshots
  • Analyze data

Step 2: Check Your Savings

In your Claude Code terminal, run:

context-mode stats

This shows you:

  • Raw data processed: How much tool output was generated
  • Data kept in sandbox: How much stayed out of your context
  • Tokens saved: Exact count of tokens spared
  • Compression ratio: Percentage reduction

Step 3: The Real Example

Here’s what the demo showed:

Input: 5,000-line access log with API requests and error codes (20 KB raw)

Without Context Mode:

  • Entire file dumped to context: ~5 KB
  • Tokens consumed: ~1,250

With Context Mode:

  • File indexed in SQLite: Stays in sandbox
  • Context window impact: Confirmation message only
  • Tokens saved: ~1,200 (25% reduction on this small file)

At scale (production logs, repo analysis):

  • 315 KB analytics file → 5.4 KB in context (98% reduction)
  • Real-world impact: 50,000–100,000 tokens saved per session

When to Use Context Mode

Context Mode is a game-changer for certain workflows. It’s overkill for others. Here’s the honest breakdown:

Use It For:

  • Long research sessions (analyzing 10+ GitHub issues, reading multiple files)
  • Large file processing (logs, analytics, CSVs, JSON dumps)
  • Multi-tool workflows (Playwright + GitHub + filesystem reads combined)
  • Complex agent projects (extended reasoning without hitting compaction)
  • Cost-sensitive work (token budget matters, saving 100K tokens/session is real money)

Skip It For:

  • Quick coding tasks (single file edits, <10 min sessions)
  • Small context needs (simple prompts, minimal tool usage)
  • Low-token budgets (where Context Mode’s overhead isn’t worth it)

The installation is so lightweight that there’s little downside to having it installed. But you’ll see real savings when you’re doing the heavy lifting: research, data analysis, complex multi-step projects.


Real Cost Calculation

Let’s put numbers to this. Say you run one serious Claude Code session per day, and you typically:

  • Read 15 GitHub issues (59 KB)
  • Query a production log (100 KB)
  • Take 3 Playwright snapshots (56 KB × 3)
  • Analyze a CSV export (75 KB)

Total raw tool output: ~410 KB per session

Without Context Mode:

  • Context window impact: ~100 KB → ~12,500 tokens
  • Tokens cost: ~12,500 × $0.003 per 1K tokens (Claude 3.5 Sonnet pricing) = $0.0375/session
  • Monthly cost: 22 working days × $0.0375 = $0.83/month (small, but it adds up)
  • Context remaining: ~50K tokens left for actual coding work
  • Session length: 30 minutes before compaction

With Context Mode:

  • Context window impact: ~5 KB → ~500 tokens
  • Tokens cost: ~500 × $0.003 = $0.0015/session
  • Monthly savings: 22 × ($0.0375 – $0.0015) = $0.79/month
  • Context remaining: ~100K tokens left for coding work
  • Session length: 2–3 hours before compaction

The token savings are modest in absolute terms—Context Mode pays for itself in improved productivity, not cost reduction. But the session extension is the real win: 3 hours of continuous work instead of hitting compaction every 30 minutes.


Advanced: Session Recovery in Action

Here’s what happens under the hood when your context compacts (you don’t have to do anything—it’s automatic):

  1. Context Mode monitors every file change, git commit, and decision
  2. When compaction is imminent, it builds a priority-tiered snapshot
    • Code files: Full paths and critical sections
    • Decisions: “Tried X, failed because Y”
    • Tasks: “Still need to implement Z”
    • Errors: “Don’t repeat approach Q”
  3. The snapshot is injected back into the context when it resets
  4. Claude continues without forgetting the previous 2 hours of work

This is why sessions extend so dramatically. Without Context Mode, compaction is a reset button. With it, it’s just a pause.


Limitations & Caveats

Context Mode is powerful, but it’s not magic. A few things to know:

SQLite Overhead

For very small operations (reading a 2 KB file, querying 3 GitHub issues), the SQLite indexing overhead might not be worth it. Context Mode is optimized for large-scale operations.

Learning Curve

If you’re new to Claude Code, Context Mode adds one more concept. Once you understand it, it becomes invisible—but the first few sessions require awareness.

Not Every Tool Call Benefits

Some quick tool calls might be more efficient without Context Mode. The system is smart about when to sandbox vs. when to keep in context, but there’s a slight performance trade-off for tiny operations.

Platform Support

Context Mode works on Claude Code, VS Code Copilot, Gemini CLI, Cursor, OpenCode, and Codex. If you’re using an older editor or a different platform, check the GitHub repo for compatibility.


Getting Started: Next Steps

  1. Install Context Mode using the 5-minute setup above
  2. Run a normal Claude Code session (research, file reads, whatever you usually do)
  3. Check your stats with context-mode stats
  4. Watch your session extend to 2–3 hours without hitting compaction

If you’re building complex projects with AI agents, Context Mode is one of those tools that quietly multiplies your productivity. Not because it does anything flashy—but because it lets you work longer, deeper, and cheaper.


Further Reading

  • GitHub: mksglu/context-mode
  • Benchmarks: See BENCHMARK.md in the repo for detailed performance data
  • Installation: Full platform-specific guides in the repo docs/ folder
  • Related Tools:
    • Claude Code — The IDE that Context Mode optimizes
    • Playwright MCP — Pairs well with Context Mode for web automation
    • GitHub MCP — Large issue reads benefit most from Context Mode