Airsc miễn phí cho tất cả. Nếu nó giúp bạn, hãy ủng hộ $2–$20.

Ủng hộ
PluginCẩn thậnQuy trình & bộ nhớ agentCần cài đặt chút

context-mode

mksglu · mksglu/context-mode

Context Mode là một máy chủ MCP tối ưu hóa cửa sổ ngữ cảnh của các AI agent lập trình bằng cách cô lập đầu ra của công cụ và duy trì bộ nhớ phiên, giảm đáng kể việc sử dụng token.

Tối ưu hóa cửa sổ context cho các AI coding agent. Cô lập đầu ra công cụ (giảm 98%), duy trì bộ nhớ phiên và thực thi định tuyến trên 17 nền tảng thông qua MCP + hooks.

30k sao2.1kGiấy phép: Không có giấy phépCập nhật 3 ngày trước0 lượt mở

Xem trước

▍

Bạn có thể làm gì với nó

  • Giảm 98% việc sử dụng token trong các AI agent lập trình bằng cách quản lý hiệu quả đầu ra của công cụ.
  • Duy trì tính liên tục của phiên làm việc cho các AI agent, cho phép chúng ghi nhớ các tác vụ và chỉnh sửa tệp trong các cuộc trò chuyện.
  • Dạy một AI agent tạo script để phân tích thay vì xử lý trực tiếp dữ liệu thô, giúp tiết kiệm ngữ cảnh.

Thử hỏi agent của bạn

  • “Refactor tệp `src/utils.js` để sử dụng async/await cho tất cả các hàm dựa trên promise, sau đó commit các thay đổi. Hãy nhớ chỉ xuất mã đã refactor.”
  • “Phân tích các tệp log trong `logs/server.log` để tìm lỗi nghiêm trọng từ 24 giờ qua. Viết một script để đếm chúng và cung cấp số lượng.”
  • “Xác định tất cả các lệnh gọi API đã lỗi thời trong thư mục `lib` và đề xuất các lựa chọn thay thế hiện đại. Xuất kết quả dưới dạng bảng markdown.”

Kiểm tra an toàn

Cẩn thận

Dùng được, nhưng nên đọc ghi chú trước.

  • ●Gói npm tự chạy script khi cài đặt.package.json
  • ●Không có giấy phép rõ ràng: hỏi tác giả trước khi dùng cho sản phẩm thương mại.

Quét tự động các file trong repo. Luôn xem lại code trước khi chạy.

Trích từ README

Context Mode

The other half of the context problem.

Used across teams at

The Problem

Every MCP tool call dumps raw data into your context window. A Playwright snapshot costs 56 KB. Twenty GitHub issues cost 59 KB. One access log — 45 KB. After 30 minutes, 40% of your context is gone. And when the agent compacts the conversation to free space, it forgets which files it was editing, what tasks are in progress, and what you last asked for. On top of that, the agent wastes output tokens on filler, pleasantries, and verbose explanations — burning context from both sides.

How Context Mode Solves It

Context Mode is an MCP server that solves all four sides of this problem:

  1. Context Saving — Sandbox tools keep raw data out of the context window. 315 KB becomes 5.4 KB. 98% reduction.

  2. Session Continuity — Every file edit, git operation, task, error, and user decision is tracked in SQLite. When the conversation compacts, context-mode doesn't dump this data back into context — it indexes events into FTS5 and retrieves only what's relevant via BM25 search. The model picks up exactly where you left off. If you don't --continue, previous session data is deleted immediately — a fresh session means a clean slate.

  3. Think in Code — The LLM should program the analysis, not compute it. Instead of reading 50 files into context to count functions, the agent writes a script that does the counting and console.log()s only the result. One script replaces ten tool calls and saves 100x context. This is a mandatory paradigm across all 17 supported clients, plus the OpenClaw gateway integration: stop treating the LLM as a data processor, treat it as a code generator.

    // Before: 47 × Read() = 700 KB.  After: 1 × ctx_execute() = 3.6 KB.
    ctx_execute("javascript", `
      const files = fs.readdirSync('src').filter(f => f.endsWith('.ts'));
      files.forEach(f => console.log(f + ': ' + fs.readFileSync('src/'+f,'utf8').split('\\n').length + ' lines'));
    `);
    
  4. No prose-style enforcement — context-mode keeps raw data out of context but never dictates how the model writes its final answer. Brevity, completeness, formatting — your model's call (or yours via your own CLAUDE.md / AGENTS.md). Aggressive brevity prompts have been shown to degrade coding/reasoning benchmarks (Moonshot AI on kimi-k2.5) — the routing block stays focused on where data goes, not on how the model talks.

Install

Platforms are grouped by install complexity. Hook-capable platforms get automatic routing enforcement. Non-hook platforms need a one-time routing file copy.

Claude Code — plugin marketplace, fully automatic

Prerequisites: Claude Code v1.0.33+ (claude --version). If /plugin is not recognized, update first: brew upgrade claude-code or npm update -g @anthropic-ai/claude-code.

Install:

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

Restart Claude Code (or run /reload-plugins).

Verify:

/context-mode:ctx-doctor

All checks should show [x]. The doctor validates runtimes, hooks, FTS5, and plugin registration.

Routing: Automatic. The SessionStart hook injects routing instructions at runtime — no file is written to your project. The plugin registers all hooks (PreToolUse, PostToolUse, UserPromptSubmit, PreCompact, SessionStart, Stop) and 11 MCP tools — six sandbox tools (ctx_batch_execute, ctx_execute, ctx_execute_file, ctx_index, ctx_search, ctx_fetch_and_index) plus five meta-tools (ctx_stats, ctx_doctor, ctx_upgrade, ctx_purge, ctx_insight).

Slash CommandWhat it does
/context-mode:ctx-statsContext savings — per-tool breakdown, tokens consumed, savings ratio.
/context-mode:ctx-doctorDiagnostics — runtimes, hooks, FTS5, plugin registration, versions.
/context-mode:ctx-indexIndex a local file or directory into the persistent FTS5 knowledge base.
/context-mode:ctx-searchSearch previously indexed content.
/context-mode:ctx-upgradePull latest, rebuild, migrate cache, fix hooks.
/context-mode:ctx-purgePermanently delete all indexed content from the knowledge base.
/context-mode:ctx-insightOpens the hosted Insight dashboard (context-mode.com/insight) in your browser — org analytics for AI-assisted engineering teams.

Note: Slash commands are a Claude Code plugin feature. On other platforms, type ctx stats, ctx doctor, ctx index, ctx search, ctx upgrade, or ctx insight in the chat — the model calls the MCP tool automatically. See Utility Commands.

Status line (optional): Claude Code's plugin manifest cannot declare a status line, so this is a one-time manual edit to ~/.claude/settings.json:

{
  "statusLine": {
    "type": "command",
    "command": "context-mode statusline"
  }
}

After saving, restart Claude Code. The bar shows $ saved this session · $ saved across sessions · % efficient so you can see savings accumulate in real time. The wiring is path-free — context-mode statusline resolves through the bundled CLI regardless of where the plugin cache lives.

Alternative — MCP-only install (no hooks or slash commands)

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

This gives you all 11 MCP tools without automatic routing. The model can still use them — it just won't be nudged to prefer them over raw Bash/Read/WebFetch. Good for trying it out before committing to the full plugin.

Gemini CLI — one config file, hooks included

Prerequisites: Node.js >= 22.5 (or Bun), Gemini CLI installed.

Install:

  1. Install context-mode globally:

    npm install -g context-mode
    
  2. Add the following to ~/.gemini/settings.json. This single file registe

Xem mã nguồn trên GitHub