mksglu /
context-mode
Keeps bulky tool output out of your coding agent's context window
- 31.9k stars
- 7k stars since 3 Oct
- TypeScript
- Updated today
- Some experience
- Token & cost savings
AI coding agents fill their context windows fast. One browser snapshot, a list of GitHub issues or a log file can add tens of kilobytes of raw text. When the agent later compacts the conversation, it can also lose track of which files it was editing and what you asked for.
Context Mode adds an MCP server whose tools run code or fetch data in a sandbox and return only the printed result. The idea is to have the model write a short script that does the counting or filtering, instead of reading 50 files into context. Hooks nudge the agent to use these tools instead of raw Bash, Read or WebFetch.
For continuity, it logs file edits, git operations, tasks and errors in SQLite, indexes them with FTS5, and pulls back only the relevant parts with BM25 search after a compaction. It does not dictate how the model writes its answers, only where data goes. The README says it supports 17 platforms. The license is Elastic License 2.0, which is not an OSI open-source license.
What it does
Sandboxed tool output
Tools such as ctx_execute and ctx_batch_execute run code or commands outside the context window and return only what the script prints. The README gives an example where 315 KB becomes 5.4 KB.
Session continuity
File edits, git operations, tasks, errors and user decisions go into SQLite. After a compaction, relevant events are found with BM25 search and given back to the model. Without --continue, old session data is deleted.
Searchable knowledge base
ctx_index and ctx_fetch_and_index store local files and fetched pages in a full-text index, and ctx_search queries them later.
Hooks for automatic routing
On hook-capable platforms such as Claude Code, Gemini CLI and VS Code Copilot, hooks steer the agent toward the sandbox tools. Other platforms need a routing file copied in once.
Stats and diagnostics
ctx_stats shows savings per tool, ctx_doctor checks runtimes, hooks and FTS5, and an optional status line shows savings as you work.
What you could build
- Cut context use when an agent works with large Playwright snapshots, logs or issue lists.
- Keep a long coding session on track across conversation compactions.
- Index a codebase or docs folder and search it without loading whole files into context.
- Measure how much context and cost your agent sessions save.
- Use the same context-saving setup across Claude Code, Gemini CLI and Copilot.
Get started
In Claude Code, add the marketplace, install the plugin, then restart and run /context-mode:ctx-doctor to check it. If you only want to try the tools without hooks, use the MCP-only command. Other platforms need a global npm install plus a config file.
/plugin marketplace add mksglu/context-mode/plugin install context-mode@context-modeclaude mcp add context-mode -- npx -y context-modeCommands are copied from the project's README. Read it on GitHub for the full setup.
More in Token & cost savings
caveman
Makes coding agents answer tersely and shrinks the logs and output they read
billion-context
A proxy that compresses long coding-agent chats so one session can run for weeks