# context-mode [Health: Active]

**Category:** 🤖 Coding Agents  
**Repository:** https://github.com/mksglu/context-mode  
**GitHub Stars:** 34646  
**npm Downloads (last month):** 1456  
**Views:** 20  
**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_execute** — Runs code or a shell command in a sandbox; returns what it prints
- **ctx_batch** — Runs many commands, indexes the output, and searches it in one call
- **ctx_index** — Indexes a file, a text or a URL into the project database
- **ctx_search** — Searches the local index; returns the matching parts
- **ctx_resume** — Returns the plugin's local state block (at most 2,048 B), or one full row by `seq
- **ctx_stats** — Shows how much output stayed out of context
- **ctx_doctor** — Checks the install; each check prints PASS or a fix command
- **ctx_upgrade** — Installs, upgrades or uninstalls; replaces old contextmode entries
- **ctx_purge** — Deletes indexed data by session, source or project

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `npx` (confidence: high):

```json
"mcpServers": {
  "context-mode": {
    "command": "npx",
    "args": ["-y","@context-mode/cli"]
  }
}
```

## Documentation

## What context-mode does

context-mode reduces the amount of tool output inserted into a coding agent's context window. Commands, scripts, file contents, and URLs can be processed locally, with the full results stored in a SQLite index rather than returned wholesale. The agent receives the output a command prints or the matching portions requested through search.

The plugin stores one `context.db` per project beneath `~/.context-mode`. It is designed for local use and can continue working offline after installation for sandbox execution, file indexing, and search. Indexed data and usage information remain on the machine.

A code-oriented workflow lets an agent write a short script to process data and return only the script's printed output. Batch execution can also collect results from many commands, index them, and search them through one MCP call.

## How it works

The MCP tools provide the agent-facing interface, while hooks connect the workflow to supported coding agents. Tool output is handled in the local sandbox and persisted to the project's SQLite database. Search then retrieves relevant sections instead of requiring the agent to load an entire command result or document.

Session state can be resumed through a compact state block of up to 2,048 bytes, or by retrieving a complete row using its sequence identifier. This supports continuing work after context compaction without placing the full stored transcript back into the context window.

The plugin makes local processes and uses the runtimes available on the machine. After installation, sandbox execution, indexing, and search do not require a network connection.

## Setup and configuration

The package requires Node.js 24.15.0 or later. On Windows, Git for Windows is also required because shell tools run through Git Bash.

Installation is agent-specific. The supported installation paths include:

- Claude Code: add the `mksglu/context-mode` marketplace and install `context-mode@context-mode`.
- Codex: add the marketplace, install the plugin, then run `npm i -g context-mode` and `context-mode setup --agents codex` to trust the hooks.
- Gemini CLI: install the extension from the GitHub repository.
- Qwen Code: install the `context-mode` extension from GitHub.
- Pi: install `npm:context-mode`.
- OMP: install the `context-mode` plugin.

The repository also lists installation paths for OpenCode, Copilot CLI, Kiro, VS Code, and ZCode. Each agent's installation block includes corresponding update, check, and removal commands. The `ctx_doctor` tool reports installation checks as `PASS` or prints a remediation command.

## Tools and capabilities

- `ctx_execute` runs code or a shell command in the sandbox and returns what it prints.
- `ctx_batch` executes multiple commands, indexes their output, and searches the results in one request.
- `ctx_index` adds a file, text, or URL to the local project database.
- `ctx_search` searches indexed content and returns matching sections.
- `ctx_resume` returns the local state block or one complete stored row by sequence number.
- `ctx_stats` reports how much output remained outside the agent's context.
- `ctx_doctor` checks the installation and provides fixes for failed checks.
- `ctx_upgrade` installs, upgrades, or uninstalls the plugin and replaces older context-mode entries.
- `ctx_purge` removes indexed data by session, source, or project.

## Limitations and notes

The plugin is source-available under the Elastic License 2.0. It is separate from Context Mode Gateway, a hosted service with its own account and subscription; the local plugin does not require that service. The local database is project-scoped, and deleting indexed data requires using the purge capability or managing the local data directly.

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

