GitHub - mksglu/context-mode: Privacy-first. MCP is the protocol for tool access. We're the virtualization layer for context.

Source

Summary

Context Mode is an MCP server that intercepts tool calls (Bash, Read, WebFetch, Playwright, etc.) and executes them inside sandboxed subprocesses, returning only a compact summary to the context window instead of raw output. It achieves 94–100% context reduction per call (e.g. 56 KB Playwright snapshot → 299 B), extending a typical Claude Code session from ~30 minutes to ~3 hours. A SQLite + FTS5 session tracker survives context compaction by rebuilding full working state - active tasks, edited files, user decisions - before the conversation window is wiped.

Key Insight

  • Context savings are dramatic and measured: 315 KB of raw tool output per session becomes 5.4 KB on average. Playwright snapshots: 56 KB → 299 B (99%). GitHub Issues (20): 59 KB → 1.1 KB (98%). Access logs (500 lines): 45 KB → 155 B (100%).
  • Two distinct problems solved: (1) context bloat from raw data dumped by MCP tools, (2) session amnesia after the model compacts the conversation. Both require hooks - instruction files alone (~60% compliance) are not enough.
  • Hooks are the difference between 60% and 98% savings. Without hooks, one unrouted Playwright call undoes an entire session’s savings. With hooks, every tool call is intercepted before execution.
  • Session continuity architecture: PostToolUse hook captures every file edit, git op, error, task, and user decision into SQLite. PreCompact builds a priority-tiered XML snapshot (≤2 KB). SessionStart restores working state via a “Session Guide” injected into context - the model picks up from the last user prompt without being re-briefed.
  • Platform support varies sharply: Full session continuity on Claude Code, Gemini CLI, VS Code Copilot, OpenClaw. Partial on Cursor and OpenCode. None on Codex CLI, Antigravity, Kiro.
  • Install for Claude Code is two commands: /plugin marketplace add mksglu/context-mode then /plugin install context-mode@context-mode. Hooks, routing instructions (CLAUDE.md patch), and slash commands (/ctx-stats, /ctx-doctor, /ctx-upgrade) are configured automatically.
  • Privacy-first by design: no telemetry, no cloud sync, no account. SQLite databases live locally and are deleted when session ends (unless --continue is used).
  • Security policy integration: Deny/allow rules from .claude/settings.json are enforced inside the sandbox too - commands chained with &&, ;, or | are split and each part checked.
  • FTS5 search with three-layer fallback: Porter stemming → trigram substring → Levenshtein fuzzy correction. Enables the model to retrieve specific indexed content rather than re-loading full documents.