Favicon of Context Mode

Context Mode

MCP server that cuts AI coding agent tool output by up to 98% and restores session memory across Claude Code, Copilot, Gemini CLI, and more.

Context Mode website screenshot
Context Mode GitHub repository preview

Context Mode is an MCP (Model Context Protocol) server built for developers using AI coding agents like Claude Code, GitHub Copilot, Gemini CLI, Cursor, and similar tools. It targets a specific pain point: raw tool output (file dumps, API responses, browser snapshots) flooding the model's context window and eating the budget meant for actual reasoning. It's for anyone running long agent sessions who notices the model forgetting what it was doing after a context compaction, or burning through context on a single Playwright snapshot or GitHub issue dump.

The core idea is that agents shouldn't read raw data into context when they can write a script to process it and log only the result. Context Mode enforces this pattern through sandboxed execution tools, tracks session state in SQLite with FTS5 indexing for retrieval after compaction, and avoids dictating how the model phrases its final answers.

Key features

  • Context Saving: Sandbox tools (ctx_execute, ctx_batch_execute, ctx_execute_file) run code and return only console output, turning a 315 KB tool result into roughly 5.4 KB, a claimed 98% reduction.
  • Session Continuity: File edits, git operations, tasks, errors, and user decisions get tracked in SQLite. On compaction, only relevant events are retrieved via BM25/FTS5 search instead of dumping everything back into context.
  • Think in Code enforcement: A mandatory pattern across 17 supported clients pushes the agent to write scripts (e.g., counting lines across files) instead of reading many files individually, replacing dozens of tool calls with one.
  • No prose-style enforcement: The routing layer controls where data goes, not how the model writes its answers, avoiding the documented downside of aggressive brevity prompts on reasoning benchmarks.
  • Automatic routing on hook-capable platforms: SessionStart hooks inject routing instructions at runtime on platforms like Claude Code and Gemini CLI without writing files to the project.
  • Diagnostics and stats tooling: Meta-tools (ctx_stats, ctx_doctor, ctx_upgrade, ctx_purge, ctx_insight) and slash commands expose per-tool token savings, run health checks, and manage the local knowledge base.
  • Session data cleanup: If you don't explicitly continue a session, previous session data is deleted, so each fresh session starts clean.

Ideal use cases

  • Long-running agent sessions where tool calls (file reads, web fetches, shell commands, Playwright snapshots) generate large amounts of raw output that isn't all needed in context.
  • Codebases where agents repeatedly need to count, filter, or aggregate data across many files, a case better handled by a generated script than dozens of individual Read calls.
  • Teams running Claude Code, Copilot (VS Code/JetBrains/CLI), Gemini CLI, Cursor, or other supported clients who want automatic context routing via hooks rather than manual prompt engineering.
  • Projects where session continuity across compactions matters, e.g., multi-hour coding sessions where losing track of in-progress edits or tasks is costly.
  • Not a good fit for short, single-turn agent interactions where context pressure never builds up, or for platforms not among the 17 supported clients where you'd need to build custom hook integration yourself.
  • Not useful if your workflow doesn't route through MCP-compatible agents at all.

Installation

Installation steps differ by platform since each agent has its own hook and MCP registration mechanism. Claude Code has the most automated path via its plugin marketplace:

/plugin marketplace add mksglu/context-mode
/plugin install context-mode@context-mode

Restart Claude Code (or run /reload-plugins), then verify with:

/context-mode:ctx-doctor

For an MCP-only install without hooks or slash commands on Claude Code:

claude mcp add context-mode -- npx -y context-mode

For Gemini CLI (requires Node.js >= 22.5 or Bun):

npm install -g context-mode

Then add the MCP server and hook definitions to ~/.gemini/settings.json (see README for the full JSON block), restart Gemini CLI, and verify with /mcp list.

For VS Code Copilot and JetBrains Copilot, install globally with npm install -g context-mode, then create the platform-specific MCP config (.vscode/mcp.json or the JetBrains Settings UI) plus a .github/hooks/context-mode.json hook file, and restart the IDE.

For GitHub Copilot CLI, the recommended path is:

npm install -g context-mode
copilot plugin install mksglu/context-mode:configs/copilot-cli

After any install, run the platform's diagnostic command (ctx doctor or the equivalent slash command) to confirm hooks, FTS5, and MCP registration are working.

Frequently asked questions

Share:

Stars
30.5K
Forks
2.2K
Last commit
20 hours ago
Repository age
8 months
Self-hosted
No
Activity score
83/100
View Repository
Ad
Favicon

 

  
 

Similar to Context Mode

Favicon

 

  
 
Favicon

 

  
 
Favicon