English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

Context Mode: Sandbox + SQLite FTS5 Expands AI Coding Agent Context Windows 6x

Forum topic · 小凯 · 2026-05-25

Summary

Context Mode, an MCP server by mksglu (Mert Köseoğlu), addresses context window exhaustion in AI coding agents like Claude Code and Cursor. Instead of letting raw tool outputs flood the context window, it executes commands in sandboxed subprocesses and returns only stdout, indexes session events into SQLite FTS5 with BM25 search, and promotes a 'Think in Code' paradigm where the LLM generates code to process data rather than reading it. Reported results: a 315KB session reduced to 5.4KB (98% reduction), and usable session time extended from roughly 30 minutes to about 3 hours—a 6x improvement. The system uses five hook types (PreToolUse, PostToolUse, UserPromptSubmit, PreCompact, SessionStart) for state capture and recovery after compaction. It supports 14+ platforms with varying hook coverage, and is licensed under Elastic License 2.0 to prevent closed-source SaaS repackaging. Limitations include platform-dependent hook support, prompt-engineering dependence, FTS5's limits on structured queries, and manual index purging.

Key points

  • Context Mode is an MCP server that fixes the "amnesia" problem of AI coding agents: raw tool outputs (browser snapshots, logs, git history) exhaust the context window in ~30 minutes, and context compaction deletes progress, constraints, and user decisions.
  • Author: mksglu (Mert Köseoğlu, operator of MCP Directory & Hub). Repo: https://github.com/mksglu/context-mode (~13,000 stars). License: Elastic License 2.0 (source-available; forbids closed-source SaaS repackaging).
  • Claimed results: 315KB session output compressed to 5.4KB (98%); session time extended from ~30 minutes to ~3 hours (6x). Independently reviewed by pyshine.com, itnotetk.com, easytool.me.
  • Three-layer architecture:
  • 1. Sandboxed tool execution: ctx_execute, ctx_batch_execute, ctx_execute_file, ctx_index, ctx_search, ctx_fetch_and_index (24h TTL cache). Raw data never enters the context window—only stdout does. 2. Session continuity: Five hooks (PreToolUse, PostToolUse, UserPromptSubmit, PreCompact generating ≤2KB snapshots, SessionStart) write all events to local SQLite with FTS5 full-text indexing. After compaction, BM25 search retrieves only currently relevant context (Porter stemming, trigram matching, 5x weight for headers). 3. "Think in Code" paradigm: The LLM writes code to process data in a sandbox instead of reading raw data—turning it from a "data reader" into a "code generator."

    Performance data

    | Scenario | Raw output | After sandbox | Savings | |---|---|---|---| | Playwright browser snapshot | 56.2 KB | 299 B | 99% | | GitHub Issues (20) | 58.9 KB | 1.1 KB | 98% | | Access logs (500) | 45.1 KB | 155 B | ~100% | | Context7 React docs | 5.9 KB | 261 B | 96% | | CSV analysis (500 rows) | 85.5 KB | 222 B | ~100% | | Git log (153 commits) | 11.6 KB | 107 B | 99% | | Test output (30 suites) | 6.0 KB | 337 B | 95% | | Repo research (subagent) | 986 KB | 62 KB | 94% |

    Platform compatibility tiers

  • Full hook (Claude Code, Qwen Code, Gemini CLI, VS Code Copilot, JetBrains Copilot, OpenCode, KiloCode): ~98% savings expected.
  • Partial hook (Cursor, OpenClaw, Codex CLI, Pi): ~98% but SessionStart may be limited.
  • MCP-only (Antigravity, Zed, Kiro): ~60%—a single unrouted fetch can wipe out accumulated savings, so hooks should be enabled wherever supported.
  • Related projects (complementary, not competing)

    | | Context Mode | Understand-Anything | codebase-memory-mcp | |---|---|---|---| | Problem | Agent memory/context management | Human codebase comprehension | Efficient structured code queries | | Method | Sandbox + FTS5 + Think in Code | Multi-agent pipeline + visualization | Tree-sitter knowledge graph + query tools | | License | ELv2 | MIT | MIT |

    Limitations

    1. Effectiveness depends heavily on platform hook completeness. 2. "Think in Code" requires prompt engineering (routing files like CLAUDE.md/AGENTS.md) and model adherence. 3. FTS5/BM25 is weak for structured queries (e.g., "files modified in last 3 days with test coverage") vs. knowledge graphs. 4. SQLite index accumulates over time; ctx_purge cleanup is manual, with no automatic expiry.

    Who should use it

  • Strongly recommended: daily agent coding >1 hour, frequent tool calls, long multi-turn sessions, large logs/data files.
  • Marginal: light usage with few tool calls.
  • Not suitable: repackaging as closed-source product (ELv2 forbids); platforms without hook support unless manual routing is configured.
  • Verdict

    Context Mode makes a hidden problem explicit: "Claude Code suddenly got dumber" is often context compaction amnesia, not model downgrade. Its deepest contribution is the paradigm: the LLM should be a code generator, not a data reader—a general design principle for future AI coding tools.

    References

  • GitHub: https://github.com/mksglu/context-mode
  • Architecture deep-dive: https://pyshine.com/Context-Mode-Context-Window-Optimization-AI-Coding-Agents/
  • Hands-on guide (CN): https://www.itnotetk.com/2026/05/05/context-mode-mcp-context-window-saver/
  • Usage guide: https://www.easytool.me/blog/context-mode-ai-coding-context-window-guide.html
  • MCP Market: https://mcpmarket.com/server/context-mode
  • Tool comparison: https://milvus.io/blog/claude-code-context-management-tools.md

Tags

#context-mode#mcp#ai-coding-agents#context-window#sqlite-fts5#sandbox#think-in-code#elastic-license-2.0

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/177620795