/ 目录 / 演练场 / Context Mode
● 社区 mksglu ⚡ 即开即用

Context Mode

作者 mksglu · mksglu/context-mode

Sandbox tool output and persist session state in SQLite — 98% less token waste, no more compaction amnesia.

Context Mode solves the "LLM forgot what it was doing" problem two ways. First, sandbox tools capture raw data out of the context window (playwright snapshot: 56KB → indexed, agent searches what it needs). Second, a per-session SQLite event log survives context compaction — the model picks up exactly where it was. Ships as plugin + MCP for 12 platforms.

为什么要用

核心特性

实时演示

实际使用效果

context-mode-mcp.replay ▶ 就绪
0/0

安装

选择你的客户端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "context-mode-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "context-mode"
      ]
    }
  }
}

打开 Claude Desktop → Settings → Developer → Edit Config。保存后重启应用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "context-mode-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "context-mode"
      ]
    }
  }
}

Cursor 使用与 Claude Desktop 相同的 mcpServers 格式。项目级配置优先于全局。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "context-mode-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "context-mode"
      ]
    }
  }
}

点击 Cline 侧栏中的 MCP Servers 图标,然后选 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "context-mode-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "context-mode"
      ]
    }
  }
}

格式与 Claude Desktop 相同。重启 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "context-mode-mcp",
      "command": "npx",
      "args": [
        "-y",
        "context-mode"
      ]
    }
  ]
}

Continue 使用服务器对象数组,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "context-mode-mcp": {
      "command": {
        "path": "npx",
        "args": [
          "-y",
          "context-mode"
        ]
      }
    }
  }
}

加入 context_servers。Zed 保存后热重载。

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

一行命令搞定。用 claude mcp list 验证,claude mcp remove 卸载。

使用场景

实战用法: Context Mode

Stop wasting context on raw tool output

👤 Heavy Claude Code users who hit compaction mid-session ⏱ ~15 min intermediate

何时使用: You feel your agent "forget" after 30 minutes and burn $$ on re-reads.

前置条件
  • Claude Code v1.0.33+brew upgrade claude-code or npm update -g @anthropic-ai/claude-code
步骤
  1. Install
    /plugin marketplace add mksglu/context-mode
    /plugin install context-mode@context-mode✓ 已复制
    → Plugin registers hooks + 6 sandbox tools
  2. Verify
    /context-mode:ctx-doctor✓ 已复制
    → All checks [x]
  3. Use normally
    Now do a big task that would normally blow context — e.g. analyze all .log files under /var/log✓ 已复制
    → ctx_execute used instead of raw Read; output indexed not dumped
  4. Check savings
    /context-mode:ctx-stats✓ 已复制
    → Per-tool reduction ratio reported

结果: Same task, 10x longer before compaction, and the agent remembers.

注意事项
  • Other MCPs bypass the routing — Pass their tool calls through ctx_batch_execute for consistent accounting
搭配使用: serena

Resume a long task seamlessly after the model compacts

👤 Devs on multi-hour agent sessions ⏱ ~5 min beginner

何时使用: Your task is too big to fit in one context window.

步骤
  1. Start with --continue
    [CLI flag] claude --continue✓ 已复制
    → Prior session's SQLite loaded
  2. Observe
    What did I last ask you about? What tasks are in progress?✓ 已复制
    → Accurate recap from FTS5 index, not hallucinated

结果: A genuinely resumable workflow.

注意事项
  • Forgetting --continue starts fresh — Persistence requires --continue; absence means deliberate fresh start

组合

与其他 MCP 搭配,撬动十倍杠杆

context-mode-mcp + serena

Serena for semantic code nav, context-mode for keeping its output out of context

Use serena for the lookup, ctx_execute to post-process the results.✓ 已复制
context-mode-mcp + playwright

Page snapshot output stays sandboxed

Snapshot the page via playwright, let context-mode hold it — search it instead of dumping.✓ 已复制

工具

此 MCP 暴露的能力

工具输入参数何时调用成本
ctx_execute code: str (js/python) Run a script to process data; output only what's needed free
ctx_batch_execute ops: [{tool, args}] Wrap multiple tool calls through the sandbox free
ctx_index content: str, tags?: [] Stash data for later retrieval free
ctx_search query: str Retrieve from session index free
ctx_fetch_and_index url: str Pull a URL, keep it out of context but searchable free
ctx_stats none See how much context was saved free

成本与限制

运行它的成本

API 配额
Local
每次调用 Token 数
Dramatic reduction — quoted 98% on real sessions
费用
Free (ELv2 license)
提示
The bigger the session, the bigger the win — use on long tasks

安全

权限、密钥、影响范围

凭据存储: Session SQLite in ~/.context-mode/
数据出站: None

故障排查

常见错误与修复

ctx-doctor shows missing hooks

Restart Claude Code fully after install; hooks register at startup

验证: Re-run /context-mode:ctx-doctor
Sandbox won't execute code

Node/Python runtime missing. Doctor tells you which. Install with brew/asdf.

Search returns nothing

Verify FTS5 built: sqlite3 ~/.context-mode/session.db "SELECT name FROM sqlite_master". Reinstall if broken.

替代方案

Context Mode 对比其他方案

替代方案何时用它替代权衡
Raw Claude Code (no plugin)Short sessions that never hit compactionNo context saving
claude-memYou want the memory layer without the sandbox-tool paradigmDifferent tradeoff — memory only, no tool output sandbox

更多

资源

📖 阅读 GitHub 上的官方 README

🐙 查看未解决的 issue

🔍 浏览全部 400+ MCP 服务器和 Skills