Context Mode: Cut AI Coding Agent Context Bloat by 98% with Sandboxed MCP & SQLite FTS5
Developers relying on autonomous coding agents—such as Claude Code, Cursor, Gemini CLI, VS Code Copilot, and OpenCode—routinely encounter a hidden bottleneck: context window pollution from raw tool outputs . While frontier models boast 200K to 1M+ token context windows, everyday Model Context Proto

Developers relying on autonomous coding agents—such as Claude Code, Cursor, Gemini CLI, VS Code Copilot, and OpenCode—routinely encounter a hidden bottleneck: context window pollution from raw tool outputs.
While frontier models boast 200K to 1M+ token context windows, everyday Model Context Protocol (MCP) and shell tool calls exhaust that capacity at an alarming rate:
Within 30 minutes of active debugging, over 40% of the context window is filled with raw JSON payloads, log lines, and file dumps. When the coding agent triggers conversation compaction to free up space, it suffers from compaction amnesia —losing track of which files were edited, which edge cases were already ruled out, and what the user originally requested.
Context Mode ( mksglu/context-mode ) is an open-source MCP server and lifecycle hook engine engineered to solve this exact problem. By sandboxing heavy tool outputs, enforcing programmatic analysis, and indexing session history into SQLite FTS5, Context Mode shrinks 315 KB tool payloads down to 5.4 KB —a 98% reduction in context consumption.
Context Mode addresses context degradation across four distinct architectural layers:
┌─────────────────────────────────────────────────────────────────┐ │ AI Coding Agent Session │ │ (Claude Code · Cursor · Gemini CLI · Copilot · OpenCode) │ └───────────────┬─────────────────────────────────┬───────────────┘ │ PreToolUse / BeforeTool Hook │ PreCompact Hook ▼ ▼ ┌───────────────────────────────┐ ┌───────────────────────────────┐ │ 1. Sandboxed Execution │ │ 2. SQLite + FTS5 Memory │ │ • ctx_execute / batch │ │ • Tracks edits, git, tasks │ │ • 315 KB raw → 5.4 KB │ │ • BM25 relevance retrieval │ │ • "Think in Code" paradigm │ │ • Zero-amnesia compaction │ └───────────────────────────────┘ └───────────────────────────────┘ Enter fullscreen mode Exit fullscreen mode 1.
Context Saving via Sandboxed Tools (98% Reduction) Standard MCP servers return complete raw responses directly into the conversation transcript. Context Mode provides six specialized sandbox tools ( ctx_batch_execute, ctx_execute, ctx_execute_file, ctx_index, ctx_search, and ctx_fetch_and_index ) that process heavy outputs outside the prompt buffer, returning only high-signal summaries.
Every file modification, git operation, task transition, error trace, and user decision is captured in a local SQLite database. When the host IDE or CLI compacts the conversation:
One of the most wasteful anti-patterns in agentic coding is using the LLM as a manual data processor—such as calling Read() 47 times to count lines or search for exports across a codebase (consuming ~700 KB of context).
Context Mode enforces a Think in Code paradigm across all 17 supported platforms: the LLM writes a compact script to perform the analysis in a sandbox and console.log() s only the result:
Research from frontier model teams has shown that aggressive "be concise / no explanations" system prompts degrade coding and reasoning benchmarks. Context Mode's runtime routing block focuses strictly on where data goes (intercepting heavy Bash, Read, Grep, and WebFetch calls), leaving response style, completeness, and formatting entirely up to your model and your project's CLAUDE.md or AGENTS.md.
Context Mode registers 11 MCP tools out of the box—six sandbox execution/indexing tools and five operational meta-tools:
Context Mode supports 17 coding platforms, including Claude Code, Gemini CLI, Cursor, VS Code Copilot, JetBrains Copilot, GitHub Copilot CLI, OpenCode, and KiloCode.
/plugin marketplace add mksglu/context-mode /plugin install context-mode@context-mode Enter fullscreen mode Exit fullscreen mode Restart Claude Code and verify your installation:
/context-mode:ctx-doctor Enter fullscreen mode Exit fullscreen mode All lifecycle hooks ( SessionStart, PreToolUse, PostToolUse, UserPromptSubmit, PreCompact, Stop ) and all 11 MCP tools are registered automatically.
npm install -g context-mode Enter fullscreen mode Exit fullscreen mode For OpenCode ( opencode.json ) or KiloCode ( kilo.json ), register the in-process TypeScript plugin with a single line:
{ "$schema": "https://opencode.ai/config.json", "plugin": [ "context-mode" ] } Enter fullscreen mode Exit fullscreen mode For GitHub Copilot CLI, install the full bundle (MCP + hooks + routing skill) in one command:
copilot plugin install mksglu/context-mode:configs/copilot-cli Enter fullscreen mode Exit fullscreen mode Conclusion As AI coding agents take on longer, multi-file engineering tasks, raw context window size is no longer enough— context hygiene determines whether an agent stays sharp after an hour of debugging or collapses under tool output bloat.
By combining sandboxed code execution, automatic hook interception, and FTS5 BM25 session memory, Context Mode gives developers a drop-in upgrade that cuts token burn by up to 98% while keeping long-running coding sessions rock-solid.