/ 目录 / 演练场 / 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

将会话 token 用量削减 40–70%

👤 Claude Code 用户 ⏱ ~15 min intermediate

何时使用: 账单节节攀升,你怀疑是上下文膨胀导致的。

步骤
  1. 安装
    Wire lean-ctx into your harness.✓ 已复制
    → 预过滤器激活
  2. 度量
    Compare token counts before/after.✓ 已复制
    → 大幅下降
  3. 调优
    Loosen if accuracy slips.✓ 已复制
    → 找到稳定平衡点

结果: 账单降低,任务成功率不变。

组合

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

lean-ctx-skill + cmux-skill

lean-ctx 裁剪的同时,用 cmux 观察 token 变化图表

Combine lean-ctx-skill with cmux-skill: Watch token graphs while lean-ctx prunes✓ 已复制

工具

此 MCP 暴露的能力

工具输入参数何时调用成本
prefilter (见文档) 在出口上下文上运行 1 次调用

成本与限制

运行它的成本

API 配额
不适用
每次调用 Token 数
节省 token
费用
免费开源
提示
度量质量回归;激进模式可能丢失重要上下文

安全

权限、密钥、影响范围

凭据存储:
数据出站:

故障排查

常见错误与修复

agent 上下文不足

降低激进程度;将重要文件加入白名单

替代方案

lean-ctx 对比其他方案

替代方案何时用它替代权衡
context-mode你需要沙箱化 tool 输出作用于不同层级

更多

资源

📖 阅读 GitHub 上的官方 README

🐙 查看未解决的 issue

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