HubLensMCPmksglu/context-mode
// archived 2026-04-27
mksglu

context-mode

AI#MCP#LLM#Context Window#Agentic Workflow#SQLite
View on GitHub
24

// summary

Context Mode is an MCP server designed to prevent context window exhaustion by offloading raw data into a sandboxed SQLite database. It tracks session events and uses BM25 retrieval to ensure the AI agent retains relevant information even after conversation compaction. Additionally, it enforces terse output patterns and promotes code-based analysis to significantly reduce token consumption.

// technical analysis

Context Mode is an MCP server designed to optimize LLM context windows by offloading raw data into a local SQLite-backed sandbox, achieving up to 98% reduction in token usage. It shifts the paradigm from treating LLMs as data processors to utilizing them as code generators, where the model writes scripts to perform analysis rather than consuming large raw outputs. By implementing session continuity through FTS5 indexing and enforcing terse output compression, it prevents context loss during conversation compaction and improves overall agent efficiency.

// key highlights

01
Reduces context window consumption by up to 98% by sandboxing raw data from tool calls.
02
Maintains session state in SQLite, allowing the model to resume tasks accurately after context compaction.
03
Promotes a 'think in code' approach where the LLM generates scripts to process data, replacing verbose tool outputs.
04
Implements output compression to strip filler and pleasantries, reducing output token usage by 65-75%.
05
Provides an insight dashboard with 90 metrics to track productivity, context health, and delegation scores.
06
Supports seamless integration across multiple platforms like Claude Code, Gemini CLI, VS Code Copilot, and Cursor.

// use cases

01
Context Saving: Offloads raw data from the context window to reduce token usage by up to 98%.
02
Session Continuity: Indexes file edits and git operations in SQLite for accurate retrieval during long sessions.
03
Think in Code: Enables the LLM to execute scripts for data analysis instead of reading large files into context.

// getting started

To begin, install the package globally via npm and configure your specific IDE or CLI tool by adding the provided MCP server definitions and hook configurations to your project or global settings. Once installed, verify the setup by running the 'ctx-doctor' command or checking the status via 'ctx stats' in your agent's chat interface. Consult the platform-specific installation sections in the README to ensure proper routing and hook registration for your environment.