context-mode: Keeping MCP Tool Output Out of the Context Window, 315 KB Down to 5.4 KB, With SQLite Session Memory Across Compaction

Published · AI Daily — AI-assisted deep research, methodology & disclosure

mksglu/context-mode is an MCP server aimed at coding agents whose context windows fill up with tool output. Sandbox tools keep raw data out of context; the README's example turns 315 KB into 5.4 KB, a 98% reduction. Session events are stored in SQLite and, after the conversation is compacted, only the relevant parts are retrieved with FTS5 and BM25. It supports 17 clients and exposes 11 MCP tools. The repo has about 27k stars; the README badge says ELv2, while GitHub's license detector reports "NOASSERTION".

The most overlooked cost for coding agents is the context window. The README of mksglu/context-mode puts it bluntly at the top: every MCP tool call dumps raw data into your context window. A Playwright snapshot costs 56 KB. Twenty GitHub issues cost 59 KB. One access log costs 45 KB. After 30 minutes, 40% of your context is gone. And when the agent compacts the conversation to free space, it forgets which files it was editing, which tasks are in progress and what you last asked for. context-mode is an MCP server that tackles these problems together. As of October 13, 2026, the repository has about 27,340 stars and 1,948 forks, is written in TypeScript, and was last pushed on October 12. The answer has four parts. The first is context saving: sandbox tools keep raw data out of the context window, and the README's example turns 315 KB into 5.4 KB, a 98% reduction. The second is session continuity: every file edit, git operation, task, error and user decision is tracked in SQLite. When the conversation compacts, it does not dump that data back into context; it indexes the events into FTS5 and retrieves only what is relevant via BM25 search, so the model can pick up where it left off. The README states that without --continue, previous session data is deleted immediately, so every new session starts clean. The third is "think in code": the LLM should program the analysis instead of acting as a data processor. To count functions across 50 files, do not read 50 files into context; write a short script and print only the result. The README contrasts about 700 KB for 47 file reads with 3.6 KB for one ctx_execute. The fourth is no prose-style enforcement: it keeps raw data out of context but never dictates how the model writes its answer, citing a Moonshot AI issue on kimi-k2.5 that aggressive brevity prompts can degrade coding and reasoning benchmarks.

On the tool side, it exposes 11 MCP tools: six sandbox tools (ctx_batch_execute, ctx_execute, ctx_execute_file, ctx_index, ctx_search, ctx_fetch_and_index) and five meta-tools (ctx_stats, ctx_doctor, ctx_upgrade, ctx_purge, ctx_insight). In Claude Code it installs as a plugin that registers PreToolUse, PostToolUse, UserPromptSubmit, PreCompact, SessionStart and Stop hooks. Routing is automatic: the SessionStart hook injects routing instructions at runtime and writes no file into your project. Install takes two commands, /plugin marketplace add mksglu/context-mode and /plugin install context-mode@context-mode, then a restart. To try it first, you can add MCP only with claude mcp add context-mode -- npx -y context-mode, but without hooks there is no automatic routing, so the model may not prefer it. Slash commands include ctx-stats for savings, ctx-doctor for diagnostics, ctx-index and ctx-search for the local knowledge base, and ctx-purge to permanently delete indexed content.

Its platform reach is another feature. The README says it supports 17 clients, grouped by install complexity: hook-capable platforms get automatic routing, while platforms without hooks need a one-time copy of a routing file. Beyond Claude Code, the docs cover Gemini CLI, VS Code Copilot, JetBrains Copilot, Copilot CLI, OpenCode, KiloCode and more, mostly requiring Node.js 22.5 or newer, or Bun. OpenCode and KiloCode lack a real SessionStart hook, so the project uses an experimental system-prompt transform hook as a surrogate and the chat.message hook in place of the missing UserPromptSubmit. Separately, ctx_insight opens a hosted Insight dashboard for organization-level analytics of AI-assisted engineering teams, a hosted service entry point alongside the local tool.

The license deserves its own warning. The README badge says ELv2, the Elastic License 2.0, while GitHub's detection returns NOASSERTION, meaning it was not recognized as a standard SPDX license. ELv2 is a source-available license, unlike open source licenses such as MIT or Apache-2.0, and it restricts uses such as offering the software as a hosted service. If you plan to use it in a company product or external service, read the LICENSE file in the repository yourself first. Our reading is that the project targets a real and expensive pain, with clear engineering logic: keep raw data out of context, make session events searchable, and have the model write scripts instead of reading data. Stay measured, though. First, 98% and 315 KB to 5.4 KB are the README's example figures; real savings depend on your tool output and habits, so measure on your own tasks with ctx_stats. Second, it relies on hooks to enforce routing, and on platforms without hooks the effect depends on the model's own discipline. Third, session data goes into a local SQLite database, so for sensitive code or logs, learn where it lives, the retention policy and what ctx_purge does. Compare context use and completion quality with and without it on one medium-sized real task before rolling it out to a team.

Sources

FAQ

What problem does context-mode solve?

The README splits it into four sides: tool output dumps raw data into context (a Playwright snapshot costs 56 KB, twenty GitHub issues 59 KB, one access log 45 KB, and after 30 minutes 40% of context is gone); compaction makes the agent forget files and tasks; models compute instead of writing scripts; and the tool should not dictate prose style. It offers an answer to each.

How does it keep continuity after compaction?

Every file edit, git operation, task, error and user decision is tracked in SQLite. When the conversation compacts, it does not dump that data back into context; it indexes events into FTS5 and retrieves only what is relevant via BM25 search. The README notes that without --continue, previous session data is deleted immediately.

What should I know about install and license?

In Claude Code, run /plugin marketplace add mksglu/context-mode and /plugin install context-mode@context-mode, or add MCP only with claude mcp add context-mode -- npx -y context-mode. Most platforms need Node.js 22.5 or newer. The README badge states ELv2 while GitHub detects NOASSERTION, so read the LICENSE file before commercial use.