When you use MCP tools in Claude Code, have you noticed that the context window is being consumed rapidly? A Playwright snapshot consumes 56KB, 20 GitHub issues consume 59KB, and 500 access logs consume 45KB. After 30 minutes, 40% of the context space is gone.
A developer has shared a solution: Context Mode. This open-source project adds an intermediate layer between Claude Code and tool output, with the core goal of preventing raw large data blocks from entering the context window.
How It Works: Sandbox Isolation + Precise Retrieval
Context Mode adopts a two-pronged strategy. The first is sandbox isolation execution: each tool call runs in an independent subprocess, supporting 10 language runtimes including JavaScript, Python, and Shell. Raw output data remains in the sandbox, and only stdout results are returned to the model.
The second is a knowledge base system: using SQLite FTS5 virtual tables paired with the BM25 ranking algorithm to index Markdown content. When the model needs specific information, the system precisely pulls relevant code blocks instead of stuffing in the entire document or a summary.
Real-world Data: From MB-level to KB-level
The author tested the effectiveness in 11 real-world scenarios:
- Playwright snapshot: 56KB → 299B
- 20 GitHub issues: 59KB → 1.1KB
- 500 access logs: 45KB → 155B
- 500 rows of CSV analysis: 85KB → 222B
- 153 git commit logs: 11.6KB → 107B
In a complete session, 315KB of raw output was compressed to 5.4KB, saving 98% of the context space. This means the usable time of the session is extended from about 30 minutes to about 3 hours.
Complementary to Cloudflare Code Mode
The project was inspired by Cloudflare's Code Mode, which compresses tool definitions from millions of tokens to about 1,000. Context Mode solves the problem in the other direction—the compression of tool output. Combined, the two can optimize context usage efficiency more comprehensively.
Installation and Usage
There are two installation methods. Installing via the plugin marketplace allows for automatic routing hooks and slash commands:
/plugin marketplace add mksglu/claude-context-mode
/plugin install context-mode@claude-context-mode
Or install only the MCP server:
claude mcp add context-mode -- npx -y context-mode
Simply restart Claude Code after installation. The system automatically routes tool output via the PreToolUse hook, and users do not need to change their workflow.
Although token prices are currently falling, usage is surging; you haven't made money yet, but costs are getting out of control. This project does not attempt to reinvent the wheel but cleverly solves a real pain point in using MCP tools. For AI practitioners who frequently use multiple tools for development, this context optimization may mean a significant improvement in work efficiency.
mcpx? Here to save mcp! Stop tool calls from eating up your context
Project address: https://github.com/mksglu/claude-context-mode