context-mode
Context window optimization for AI coding agents. Sandboxes tool output (98% reduction), persists session memory, and enforces routing across 17 platforms via MCP + hooks.
- 31.9k estrellas
- 2.2k forks
- 356 issues abiertos
- Lenguaje: TypeScript
- Licencia: NOASSERTION
- actualizado
Instalación
local · npxclaude mcp add context-mode -- npx -y context-mode{
"mcpServers": {
"context-mode": {
"command": "npx",
"args": ["-y", "context-mode"]
}
}
}{
"mcpServers": {
"context-mode": {
"command": "npx",
"args": ["-y", "context-mode"]
}
}
}- Run the command above in your terminal (Claude Code), or paste the JSON config into claude_desktop_config.json (Claude Desktop).
- Replace any <placeholder> values with your API keys or paths.
- Restart Claude. The MCP server and its tools appear automatically.
Nota editorial
Context Mode is a TypeScript MCP server that addresses context window exhaustion in AI coding agents by intercepting and compressing tool output before it reaches the model. Its core mechanism is a set of sandbox tools that strip raw data from the context window entirely, reducing payloads like Playwright DOM snapshots or GitHub issue lists by up to 98% (for example, 315 KB down to 5.4 KB). A SQLite backend with FTS5 indexing and BM25 retrieval tracks file edits, git operations, tasks, and errors across a session, so when Claude Code compacts a conversation, the agent can retrieve only relevant history rather than reloading everything. The `ctx_execute` tool lets the model write and run short scripts instead of reading dozens of files directly, replacing many sequential tool calls with a single execution. Context Mode integrates with Claude Code via MCP and also supports 15 other platforms including Cursor, Codex CLI, and Zed. Developers working on long coding sessions with heavy file or API tool usage are the primary audience.
Resumen de MCP Servers
Context Mode
The other half of the context problem.
Used across teams at
The Problem
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 — 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, what tasks are in progress, and what you last asked for. On top of that, the agent wastes output tokens on filler, pleasantries, and verbose explanations — burning context from both sides.
How Context Mode Solves It
Context Mode is an MCP server that solves all four sides of this problem:
Context Saving — Sandbox tools keep raw data out of the context window. 315 KB becomes 5.4 KB. 98% reduction.
Session Continuity — Every file edit, git operation, task, error, and user decision is tracked in SQLite. When the conversation compacts, context-mode doesn't dump this data back into context — it indexes events into FTS5 and retrieves only what's relevant via BM25 search. The model picks up exactly where you left off. If you don't
--continue, previous session data is deleted immediately — a fresh session means a clean slate.Think in Code — The LLM should program the analysis, not compute it. Instead of reading 50 files into context to count functions, the agent writes a script that does the counting and
console.log()s only the result. One script replaces ten tool calls and saves 100x context. This is a mandatory paradigm across all 17 supported clients, plus the OpenClaw gateway integration: stop treating the LLM as a data processor, treat it as a code generator.// Before: 47 × Read() = 700 KB. After: 1 × ctx_execute() = 3.6 KB. ctx_execute("javascript", ` const files = fs.readdirSync('src').filter(f => f.endsWith('.ts')); files.forEach(f => console.log(f + ': ' + fs.readFileSync('src/'+f,'utf8').split('\\n').length + ' lines')); `);No prose-style enforcement — context-mode keeps raw data out of context but never dictates how the model writes its final answer. Brevity, completeness, formatting — your model's call (or yours via your own
CLAUDE.md/AGENTS.md). Aggressive brevity prompts have been shown to degrade coding/reasoning benchmarks (Moonshot AI onkimi-k2.5) — the routing block stays focused on where data goes, not on how the model talks.
Install
Platforms are grouped by install complexity. Hook-capable platforms get automatic routing enforcement. Non-hook platforms need a one-time routing file copy.
Claude Code — plugin marketplace, fully automatic
Prerequisites: Claude Code v1.0.33+ (claude --version). If /plugin is not recognized, update first: brew upgrade claude-code or npm update -g @anthropic-ai/claude-code.
Install:
/plugin marketplace add mksglu/context-mode
/plugin install context-mode@context-modeRestart Claude Code (or run /reload-plugins).
Verify:
/context-mode:ctx-doctorAll checks should show [x]. The doctor validates runtimes, hooks, FTS5, and plugin registration.
Routing: Automatic. The SessionStart hook injects routing instructions at runtime — no file is written to your project. The plugin registers all hooks (PreToolUse, PostToolUse, UserPromptSubmit, PreCompact, SessionStart, Stop) and 11 MCP tools — six sandbox tools (ctx_batch_execute, ctx_execute, ctx_execute_file, ctx_index, ctx_search, ctx_fetch_and_index) plus five meta-tools (ctx_stats, ctx_doctor, ctx_upgrade, ctx_purge, ctx_insight).
| Slash Command | What it does |
|---|---|
/context-mode:ctx-stats | Context savings — per-tool breakdown, tokens consumed, savings ratio. |
/context-mode:ctx-doctor | Diagnostics — runtimes, hooks, FTS5, plugin registration, versions. |
/context-mode:ctx-index | Index a local file or directory into the persistent FTS5 knowledge base. |
/context-mode:ctx-search | Search previously indexed content. |
/context-mode:ctx-upgrade | Pull latest, rebuild, migrate cache, fix hooks. |
/context-mode:ctx-purge | Permanently delete all indexed content from the knowledge base. |
/context-mode:ctx-insight | Opens the hosted Insight dashboard (context-mode.com/insight) in your browser — org analytics for AI-assisted engineering teams. |
Note: Slash commands are a Claude Code plugin feature. On other platforms, type
ctx stats,ctx doctor,ctx index,ctx search,ctx upgrade, orctx insightin the chat — the model calls the MCP tool automatically. See Utility Commands.
Status line (optional): Claude Code's plugin manifest cannot declare a status line, so this is a one-time manual edit to ~/.claude/settings.json:
{
"statusLine": {
"type": "command",
"command": "context-mode statusline"
}
}After saving, restart Claude Code. The bar shows $ saved this session · $ saved across sessions · % efficient so you can see savings accumulate in real time. The wiring is path-free — context-mode statusline resolves through the bundled CLI regardless of where the plugin cache lives.
Alternative — MCP-only install (no hooks or slash commands)
claude mcp add context-mode -- npx -y context-modeThis gives you all 11 MCP tools without automatic routing. The model can still use them — it just won't be nudged to prefer them over raw Bash/Read/WebFetch. Good for trying it out before committing to the full plugin.
Lo que la gente pregunta sobre context-mode
¿Qué es mksglu/context-mode?
mksglu/context-mode es mcp servers para el ecosistema de Claude AI. Context window optimization for AI coding agents. Sandboxes tool output (98% reduction), persists session memory, and enforces routing across 17 platforms via MCP + hooks. Tiene 31.9k estrellas en GitHub y su última actualización registrada es del 2026-10-23.
¿Cómo se instala context-mode?
Puedes instalar context-mode clonando el repositorio (https://github.com/mksglu/context-mode) o siguiendo las instrucciones del README en GitHub. ClaudeWave también te ofrece bloques de instalación rápida en esta misma página.
¿Es seguro usar mksglu/context-mode?
Nuestro agente de seguridad ha analizado mksglu/context-mode y le ha asignado un Trust Score de 90/100 (tier: Verified). Revisa el desglose completo de comprobaciones superadas y flags en esta página.
¿Quién mantiene mksglu/context-mode?
mksglu/context-mode es mantenido por mksglu. La última actividad registrada en GitHub es del 2026-10-23, con 356 issues abiertos.
¿Hay alternativas a context-mode?
Sí. En ClaudeWave puedes explorar mcp servers similares en /categories/mcp, ordenados por popularidad o actividad reciente.
¿Mantienes este repo? Muestra su Trust Score en tu README
La insignia muestra el Trust Score y el veredicto actuales de este repositorio y enlaza a esta página. Sigue los datos del catálogo: nadie puede comprar ni editar la puntuación que enseña.
[](https://claudewave.com/en/repo/mksglu-context-mode)<a href="https://claudewave.com/en/repo/mksglu-context-mode"><img src="https://claudewave.com/api/badge/mksglu-context-mode" alt="ClaudeWave Trust Score for mksglu/context-mode" width="320" height="64"></a>