Your AI Agent Is Drowning in Its Own Tool Output
Here is a number that should worry anyone paying for Claude Code by the token. A single Playwright snapshot costs 56 KB of context. Twenty GitHub issues cost 59 KB. One access log, 45 KB. Every MCP tool call dumps raw data straight into the context window, and after about 30 minutes of real work, 40% of it is gone.
Then comes the second blow. When the conversation gets too long, the agent compacts it to free space, and the compaction wipes its working memory. It forgets which files it was editing, what tasks were in progress, and what you last asked for. You spend the next ten minutes re-explaining everything.
And there is a third leak most people never notice: the agent burns output tokens on filler, pleasantries and verbose explanations, eating context from both sides at once.
This is the problem Context Mode was built for. It is an open-source MCP server by mksglu that attacks context bloat from four directions simultaneously, and the numbers are startling: 315 KB of raw tool output becomes 5.4 KB. That is a 98% reduction, and it extends a typical session from about 30 minutes to around 3 hours.
How It Works: Sandboxes, Memory, and Thinking in Code
Context Mode solves what its README calls all four sides of the context problem.
1. Context saving. Sandbox tools intercept raw tool output and keep it out of the context window. Instead of the model reading the full output, it gets a compact reference. A Playwright snapshot goes from 56.2 KB to 299 bytes (99% saved). Twenty GitHub issues go from 58.9 KB to 1.1 KB (98%). An access log of 500 requests goes from 45.1 KB to 155 bytes, effectively 100%. The benchmark table in the repo lists 21 scenarios, and the pattern holds across all of them.
2. Session continuity. Every file edit, git operation, task, error and user decision is tracked in a local SQLite database. When the conversation compacts, Context Mode does not dump all of that back into context. It indexes events with FTS5 full-text search and retrieves only what is relevant via BM25 ranking. The model picks up exactly where it left off, and it only pays context for the memories it actually needs. There is a privacy-conscious default worth knowing: if you do not pass --continue, previous session data is deleted immediately. A fresh session means a clean slate.
3. Think in code. This is the most opinionated idea in the repo, and arguably the smartest. Instead of reading 50 files into context to count functions, the agent writes a script that does the counting and logs only the result. One ctx_execute call replaces 47 Read calls: 700 KB becomes 3.6 KB. The philosophy is blunt: stop treating the LLM as a data processor and start treating it as a code generator. This is enforced as a mandatory paradigm across all supported clients.
4. No prose policing. Context Mode keeps raw data out of context but deliberately never tells the model how to write its final answer. Brevity, completeness, formatting, that is your model's call (or yours, via your own CLAUDE.md). The README cites research showing aggressive brevity prompts degrade coding benchmarks. The routing stays focused on where data goes, not how the model talks.
The Benchmarks: 315 KB Becomes 5.4 KB
The repo ships a full benchmark table, and it is worth reading because the savings are consistent rather than cherry-picked. Playwright snapshot: 56.2 KB raw, 299 bytes in context, 99% saved. GitHub issues (20): 58.9 KB to 1.1 KB, 98%. Access log with 500 requests: 45.1 KB to 155 bytes, effectively 100%. Context7 React docs: 5.9 KB to 261 bytes, 96%. An analytics CSV with 500 rows: 85.5 KB to 222 bytes, 100%. Git log of 153 commits: 11.6 KB to 107 bytes, 99%. Test output across 30 suites: 6.0 KB to 337 bytes, 95%. Even a deep repo-research subagent run drops from 986 KB to 62 KB, 94% saved.
Over a full session, the headline number is 315 KB of raw output becoming 5.4 KB in context. Session time extends from roughly 30 minutes to around 3 hours. If you are paying per token, that is not a marginal improvement, it is the difference between an agent that taps out mid-task and one that finishes.
Installing It Takes Two Commands on Claude Code
On Claude Code, installation is a plugin marketplace add. You need Claude Code v1.0.33 or newer. Open Claude Code and run:
/plugin marketplace add mksglu/context-mode
/plugin install context-mode@context-modeRestart Claude Code (or run /reload-plugins), then verify with /context-mode:ctx-doctor. Every check should show green. The plugin registers hooks for SessionStart, PreToolUse, PostToolUse, UserPromptSubmit, PreCompact and Stop, plus 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).
The hooks do the heavy lifting automatically. The SessionStart hook injects routing instructions at runtime, so no file gets written into your project. PreToolUse and PostToolUse hooks intercept tool calls and redirect raw output to the sandbox before it ever touches your context.
There is also a status line you can add with a one-time edit to ~/.claude/settings.json. It shows dollars saved this session, dollars saved across sessions, and your efficiency percentage, updating in real time as you work. Watching the savings accumulate is the fastest way to believe the benchmarks.
17 Platforms, but Hooks Are What Make It Work
Context Mode supports 17 platforms: Claude Code, Qwen Code, Gemini CLI, VS Code Copilot, JetBrains Copilot, GitHub Copilot CLI, Cursor, OpenCode, KiloCode, OpenClaw, Codex CLI, Kimi Code, Antigravity, Antigravity CLI, Kiro, Zed and Pi. That breadth matters because most developers do not live in one agent.
But the README is honest about a split that matters more than the platform count. On hook-capable platforms, hooks intercept tool calls programmatically: they can block dangerous commands and redirect output to the sandbox before execution. Measured savings sit around 98%. On platforms without hook support, Context Mode falls back to routing instruction files (a copied AGENTS.md or GEMINI.md), which guide the model through prompt instructions but cannot block anything. Measured savings there drop to around 60%, because one unrouted curl or Playwright snapshot can dump 56 KB into context and wipe out a whole session's savings.
Concretely: Claude Code, Gemini CLI, the Copilots, Cursor, OpenCode, Codex CLI, Kiro and Pi get the full ~98% treatment. Antigravity and Zed do not support hooks, so they rely on the manually copied routing file at ~60%. If you are choosing where to run it, pick a hook-capable host. The README's own advice is direct: always enable hooks where supported.
The Utility Commands You Will Actually Use
Inside any AI session, you just type the command and the model calls the MCP tool for you. ctx stats shows your context savings with a per-tool breakdown, tokens consumed and savings ratio. ctx doctor diagnoses runtimes, hooks, FTS5 and versions. ctx index indexes a local file or directory into the persistent knowledge base, and ctx search searches it later. ctx upgrade pulls the latest from GitHub, rebuilds and fixes hooks. ctx purge permanently deletes all indexed content. ctx insight opens the hosted Insight dashboard at context-mode.com/insight, which gives org-level analytics for AI-assisted engineering teams.
From the terminal, the same operations run without an AI session: context-mode doctor, context-mode index, context-mode search, context-mode upgrade. There is also a debug script (scripts/ctx-debug.sh) that collects OS info, runtime versions, hook validation and environment into a single pasteable markdown report for bug reports, which tells you something about how the maintainer thinks about support.
One design decision deserves credit: everything is stored locally in SQLite under your own machine. The privacy section of the README is explicit about the architecture, and combined with the delete-on-fresh-session default, it is clear the project was designed by someone who has thought about what it means to let a tool watch every file edit.
Who Should Install It (and Who Can Skip)
Install it if you use Claude Code (or another hook-capable agent) for sessions longer than 30 minutes, you pay per token and watch usage climb, your agent keeps forgetting context after compaction, or you run lots of MCP tools like Playwright, GitHub or database queries whose raw output is enormous relative to what you actually need from it.
Skip it if your sessions are short and simple, you work exclusively in Zed or Antigravity where only the ~60% instruction-file mode applies, or you are uncomfortable with a tool that hooks every tool call, even though the hooks run locally and the data stays in SQLite on your machine.
The social proof is hard to ignore: #1 on Hacker News with 570+ points, 30,000+ GitHub stars, and a README that lists usage across teams at Microsoft, Google, Meta, Amazon, IBM, NVIDIA, ByteDance, Stripe, Datadog and Salesforce. It is ELv2 licensed and free to use. If context bloat is the tax you pay on every agent session, this is the most concrete rebate anyone has shipped.



