# context-mode [Health: Active]

**Category:** 🤖 Coding Agents  
**Repository:** https://github.com/mksglu/context-mode  
**GitHub Stars:** 31610  
**Views:** 0  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/context-mode

## Description
Context window optimization for AI coding agents. Sandboxes tool output (98% reduction), persists session memory, and   enforces routing across 17 platforms via MCP + hooks.

## Tools
Capabilities this server exposes over MCP:

- **ctx_batch_execute** — Run multiple commands + search multiple queries in ONE call. Opt-in `concurrency: 1-8` for I/O-bound batches.
- **ctx_execute** — Run code in 12 languages. Only stdout enters context.
- **ctx_execute_file** — Process files in sandbox. Raw content never leaves.
- **ctx_index** — Chunk markdown into FTS5 with BM25 ranking.
- **ctx_search** — Query indexed content with multiple queries in one call.
- **ctx_fetch_and_index** — Fetch URL, chunk and index. Cache reuses content within TTL (default 24h, override per-call with `ttl: <ms>`). `ttl: 0` or `force: true` to bypass. Pass `requests: [{url, source}, ...]` + `concurrency: 1-8` for parallel multi-URL.
- **ctx_stats** — Show context savings, call counts, and session statistics.
- **ctx_doctor** — Diagnose installation: runtimes, hooks, FTS5, versions.
- **ctx_upgrade** — Upgrade to latest version from GitHub, rebuild, reconfigure hooks.
- **ctx_purge** — Permanently deletes all indexed content from the knowledge base.

## Claude Desktop Quick Installation
No confirmed install details yet, so no config is published. Follow the setup steps in the repository above.

## Documentation

## What the context-mode MCP server does

The context-mode MCP server is designed for coding sessions where tool output consumes too much of the model's context. Rather than placing every raw result in the conversation, it provides tools that execute code, process data, index content, and return selected results. The README describes reductions such as turning hundreds of kilobytes of raw data into a few kilobytes of output, though the actual savings depend on the task and the way tools are used.

It also preserves session state. File edits, Git operations, tasks, errors, and user decisions are recorded in a SQLite database. When a conversation is compacted, the stored events are not all reinserted into the prompt. Relevant information can instead be located through full-text search.

The system does not enforce a particular style for the model's final response. Its routing guidance concerns where data should be processed, not whether the agent should be brief, verbose, or formatted in a specific way.

## How it works

The context-mode MCP server exposes sandbox tools for running JavaScript, running a script file, processing batches, indexing local content, searching indexed material, and fetching and indexing content. A coding agent can use these operations to calculate results close to the data instead of reading many files into the conversation. For example, a script can count lines across a directory and print only the totals.

Indexed session information uses SQLite with FTS5. Search uses BM25 ranking to retrieve relevant events rather than restoring the entire prior session. A continued session can therefore recover selected context after compaction. If continuation is not requested, the README says previous session data is deleted, providing a clean session instead.

Routing is enforced through hooks on supported hook-capable platforms. The project describes this routing and code-oriented workflow as applying across its supported clients, as well as through an OpenClaw gateway integration.

## Setup and configuration

Claude Code can install the project through its plugin marketplace. The documented flow is to add the `mksglu/context-mode` marketplace, install the `context-mode@context-mode` plugin, and restart Claude Code or reload plugins. Claude Code version 1.0.33 or newer is required.

The Claude Code plugin registers hooks for session start, tool use, prompts, compaction, and stopping. Its session-start hook supplies routing instructions at runtime rather than writing a routing file into the project. The plugin also registers the MCP tools and provides a diagnostic command that checks runtimes, hooks, FTS5, and plugin registration.

On other platforms, the README states that non-hook clients require a one-time routing-file copy, while hook-capable clients receive automatic routing enforcement. The supplied material does not specify the exact file contents or installation commands for those platforms.

## Tools and capabilities

The documented Claude Code installation includes 11 MCP tools:

- `ctx_batch_execute`, `ctx_execute`, and `ctx_execute_file` for sandboxed computation.
- `ctx_index`, `ctx_search`, and `ctx_fetch_and_index` for building and querying the local knowledge base.
- `ctx_stats` for context-use and savings information.
- `ctx_doctor` for diagnostics.
- `ctx_upgrade` for updating and repairing the installation.
- `ctx_purge` for permanently removing indexed content.
- `ctx_insight` for opening the hosted Insight dashboard in a browser.

The same functions can be reached through Claude Code slash commands. The README says other platforms can invoke the utility functions by typing commands such as `ctx stats`, `ctx doctor`, `ctx index`, or `ctx search` in chat.

## Limitations and notes

This tool changes how data is routed and processed; it does not guarantee a fixed reduction for every workload. Agents still need to use the sandbox and indexing tools appropriately. The project also does not replace a model's response-style instructions. Indexed content can be permanently removed with `ctx_purge`, and sessions that are not continued lose their previous stored data according to the documented behavior.

_Full upstream README: https://allmcps.com/mcp/context-mode/readme_

