/ 目錄 / 演練場 / lean-ctx
● 社群 yvgude ⚡ 即開即用

lean-ctx

作者 yvgude · yvgude/lean-ctx

一個積極修剪上下文的 Rust 工具——在傳送給 agent 前,刪除無用匯入、精簡注釋、壓縮日誌。

lean-ctx 面向注重成本的使用者:它位於你和 agent 執行環境之間,對外送上下文套用節省 token 的轉換。支援 Claude Code、Codex、Cursor。

為什麼要用

核心特性

即時演示

實際使用效果

就緒

安裝

選擇你的客戶端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "lean-ctx-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/yvgude/lean-ctx"
      ],
      "_inferred": true
    }
  }
}

開啟 Claude Desktop → Settings → Developer → Edit Config。儲存後重啟應用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "lean-ctx-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/yvgude/lean-ctx"
      ],
      "_inferred": true
    }
  }
}

Cursor 使用與 Claude Desktop 相同的 mcpServers 格式。專案級設定優先於全域。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "lean-ctx-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/yvgude/lean-ctx"
      ],
      "_inferred": true
    }
  }
}

點擊 Cline 側欄中的 MCP Servers 圖示,然後選 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "lean-ctx-skill": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/yvgude/lean-ctx"
      ],
      "_inferred": true
    }
  }
}

格式與 Claude Desktop 相同。重啟 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "lean-ctx-skill",
      "command": "git",
      "args": [
        "clone",
        "https://github.com/yvgude/lean-ctx"
      ]
    }
  ]
}

Continue 使用伺服器物件陣列,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "lean-ctx-skill": {
      "command": {
        "path": "git",
        "args": [
          "clone",
          "https://github.com/yvgude/lean-ctx"
        ]
      }
    }
  }
}

加入 context_servers。Zed 儲存後熱重載。

claude mcp add lean-ctx-skill -- git clone https://github.com/yvgude/lean-ctx

一行命令搞定。用 claude mcp list 驗證,claude mcp remove 移除。

使用場景

實戰用法: lean-ctx

將 session token 使用量削減 40-70%

👤 Claude Code 使用者 ⏱ ~15 min intermediate

何時使用: 你的費用不斷攀升,懷疑是上下文膨脹所致。

步驟
  1. 安裝
    將 lean-ctx 接入你的執行環境。✓ 已複製
    → 預篩選器啟用
  2. 測量
    比較前後的 token 數。✓ 已複製
    → 大幅下降
  3. 調整
    若準確性下降則放寬設定。✓ 已複製
    → 穩定的平衡

結果: 在相同任務成功率下降低費用。

組合

與其他 MCP 搭配,撬動十倍槓桿

lean-ctx-skill + cmux-skill

在 lean-ctx 修剪時觀察 token 圖表

結合 lean-ctx-skill 與 cmux-skill:在 lean-ctx 修剪時觀察 token 圖表✓ 已複製

工具

此 MCP 暴露的能力

工具輸入參數何時呼叫成本
prefilter (詳見文件) 在外送上下文上執行 1 次呼叫

成本與限制

運行它的成本

API 配額
不適用
每次呼叫 Token 數
節省 token
費用
免費開源
提示
測量品質退化;積極模式可能丟棄重要上下文

安全

權限、密鑰、影響範圍

憑證儲存:
資料出站:

故障排查

常見錯誤與修復

agent 缺少上下文

降低積極程度;將重要檔案加入白名單

替代方案

lean-ctx 對比其他方案

替代方案何時用它替代權衡
context-mode你需要沙盒化的工具輸出不同的層級

更多

資源

📖 閱讀 GitHub 上的官方 README

🐙 查看未解決的 issue

🔍 瀏覽全部 400+ MCP 伺服器和 Skills