Context Mode Stretches AI Coding Sessions from 30 Minutes to 3 Hours
Context Mode is a free, open-source MCP server that cuts AI coding agent context usage by 98% and survives session compaction across 17 tools
ProTakeaways
- Context Mode is a free MCP server that reduces AI coding agent context usage by up to 98% by sandboxing tool output into isolated subprocesses.
- Session memory persists to SQLite across compaction events -- the agent resumes exactly where it left off, including tasks, file edits, errors, and user decisions.
- Benchmarks show 315 KB of raw session output compressed to 5.4 KB, extending typical session length from ~30 minutes to ~3 hours.
- Supports 17 platforms including Claude Code, Gemini CLI, Cursor, VS Code Copilot, Codex CLI, OpenCode, and Kiro via MCP + hooks.
- Completely local and private -- no telemetry, no cloud sync, no account; licensed under Elastic License 2.0 (source-available, not SaaS-able).
- Install on Claude Code with two commands:
/plugin marketplace add mksglu/context-modethen/plugin install context-mode@context-mode.
Context Mode is an open-source MCP server that tackles one of the most frustrating problems with long AI coding sessions: context window blowout. Every tool call your agent makes -- reading files, fetching URLs, running shell commands -- dumps raw data directly into the context window. After 30 minutes, you've burned through 40% of your budget. When the agent hits its limit and compacts the conversation, it forgets what files it was editing, what tasks were in progress, and what you last asked for. Context Mode intercepts all of that before it happens.
The bleeding is coming from inside the house
The numbers are stark. A single Playwright DOM snapshot costs 56 KB. Twenty GitHub issues cost 59 KB. One access log from 500 requests costs 45 KB. These aren't edge cases -- they're routine operations in any non-trivial coding session. The cumulative effect is that a typical session burns through context in about 30 minutes, forcing compaction and losing state.
Context Mode attacks this from four angles simultaneously:
- Sandbox execution -- Instead of reading raw data into context, the agent writes a small script that processes the data and logs only the result. 315 KB of raw output becomes 5.4 KB.
- Session memory -- Every file edit, git operation, task, error, and user decision is persisted to a local SQLite database. When compaction happens, the model picks up exactly where it left off.
- Routing enforcement -- Hooks intercept tool calls before they execute, redirecting large-output tools to the sandbox automatically.
- No style enforcement -- The tool controls where data goes, not how the model writes its answers. Aggressive brevity prompts have been shown to degrade coding benchmarks, so Context Mode deliberately avoids them.
The sandbox is the core trick
The key insight is a paradigm shift: stop treating the LLM as a data processor, treat it as a code generator. Instead of reading 47 TypeScript files into context to count functions, the agent writes a 3-line script that does the counting and logs only the result.