將 session token 使用量削減 40-70%
何時使用: 你的費用不斷攀升,懷疑是上下文膨脹所致。
步驟
-
安裝將 lean-ctx 接入你的執行環境。✓ 已複製→ 預篩選器啟用
-
測量比較前後的 token 數。✓ 已複製→ 大幅下降
-
調整若準確性下降則放寬設定。✓ 已複製→ 穩定的平衡
結果: 在相同任務成功率下降低費用。
作者 yvgude · yvgude/lean-ctx
一個積極修剪上下文的 Rust 工具——在傳送給 agent 前,刪除無用匯入、精簡注釋、壓縮日誌。
lean-ctx 面向注重成本的使用者:它位於你和 agent 執行環境之間,對外送上下文套用節省 token 的轉換。支援 Claude Code、Codex、Cursor。
%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。儲存後重啟應用。
{
"mcpServers": {
"lean-ctx-skill": {
"command": "git",
"args": [
"clone",
"https://github.com/yvgude/lean-ctx"
],
"_inferred": true
}
}
}
Cursor 使用與 Claude Desktop 相同的 mcpServers 格式。專案級設定優先於全域。
{
"mcpServers": {
"lean-ctx-skill": {
"command": "git",
"args": [
"clone",
"https://github.com/yvgude/lean-ctx"
],
"_inferred": true
}
}
}
點擊 Cline 側欄中的 MCP Servers 圖示,然後選 "Edit Configuration"。
{
"mcpServers": {
"lean-ctx-skill": {
"command": "git",
"args": [
"clone",
"https://github.com/yvgude/lean-ctx"
],
"_inferred": true
}
}
}
格式與 Claude Desktop 相同。重啟 Windsurf 生效。
{
"mcpServers": [
{
"name": "lean-ctx-skill",
"command": "git",
"args": [
"clone",
"https://github.com/yvgude/lean-ctx"
]
}
]
}
Continue 使用伺服器物件陣列,而非映射。
{
"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 圖表
| 工具 | 輸入參數 | 何時呼叫 | 成本 |
|---|---|---|---|
| prefilter | (詳見文件) | 在外送上下文上執行 | 1 次呼叫 |
agent 缺少上下文降低積極程度;將重要檔案加入白名單
| 替代方案 | 何時用它替代 | 權衡 |
|---|---|---|
| context-mode | 你需要沙盒化的工具輸出 | 不同的層級 |