/ Diretório / Playground / lean-ctx
● Comunidade yvgude ⚡ Instantâneo

lean-ctx

por yvgude · yvgude/lean-ctx

Cut AI coding token costs by up to 99% — Rust MCP server with 42 tools for cached reads, context compression, and smart file modes.

lean-ctx is a single Rust binary that reduces AI coding costs through two mechanisms: a shell hook that compresses CLI output (60-95% savings) and an MCP server with 42 tools for cached file reads, context optimization, and multi-agent coordination. Supports 24 AI coding tools (Cursor, Claude Code, Copilot, Windsurf, etc.) with zero telemetry.

Por que usar

Principais recursos

Demo ao vivo

Como fica na prática

lean-ctx.replay ▶ pronto
0/0

Instalar

Escolha seu cliente

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

Abra Claude Desktop → Settings → Developer → Edit Config. Reinicie após salvar.

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

Cursor usa o mesmo esquema mcpServers que o Claude Desktop. Config de projeto vence a global.

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

Clique no ícone MCP Servers na barra lateral do Cline, depois "Edit Configuration".

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

Mesmo formato do Claude Desktop. Reinicie o Windsurf para aplicar.

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

O Continue usa um array de objetos de servidor em vez de um map.

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

Adicione em context_servers. Zed recarrega automaticamente ao salvar.

claude mcp add lean-ctx -- TODO 'See README: https://github.com/yvgude/lean-ctx'

Uma linha só. Verifique com claude mcp list. Remova com claude mcp remove.

Casos de uso

Usos do mundo real: lean-ctx

How to cut your AI coding costs by 80%+ with lean-ctx

👤 Developers paying for Claude, Cursor, or Copilot API tokens ⏱ ~10 min beginner

Quando usar: Your monthly AI coding bill is growing and you want to reduce it without changing your workflow.

Pré-requisitos
  • lean-ctx installed — brew install lean-ctx or curl -fsSL https://leanctx.com/install.sh | sh
Fluxo
  1. One-command setup
    Run: lean-ctx setup✓ Copiado
    → Shell hooks installed, all detected editors configured automatically
  2. Code normally for a day
    Use your AI coding tool as usual — lean-ctx works transparently in the background.✓ Copiado
    → No workflow change; compression happens silently
  3. Check savings
    Run: lean-ctx gain✓ Copiado
    → Dashboard showing token savings per category (file reads, git, shell, etc.)

Resultado: Measurable token reduction (typically 60-90%) with zero workflow friction.

Armadilhas
  • Compressed output confuses some edge-case prompts — Use lean-ctx-off to temporarily disable, or use ctx_read with 'full' mode for specific files

Read large codebases efficiently with 8 file modes

👤 AI coding tool users working on large repos ⏱ ~5 min beginner

Quando usar: Your AI assistant wastes tokens reading entire files when it only needs the structure or signature.

Fluxo
  1. Use map mode for overview
    lean-ctx read src/main.rs -m map✓ Copiado
    → File structure at ~10% of full token cost
  2. Use signatures mode for API
    lean-ctx read src/lib.rs -m signatures✓ Copiado
    → Just function/type signatures, no bodies
  3. Use diff mode for changes
    lean-ctx read src/main.rs -m diff✓ Copiado
    → Only lines changed since last read — minimal tokens

Resultado: The AI gets exactly the context it needs at a fraction of the token cost.

Armadilhas
  • Aggressive mode strips too much for complex refactoring — Use 'task' mode instead — it preserves context relevant to the current task
Combine com: filesystem

Share context between AI agents without re-reading everything

👤 Power users running multiple AI agents on the same project ⏱ ~15 min intermediate

Quando usar: You're using Claude Code for architecture and Cursor for implementation, and they keep re-reading the same files.

Fluxo
  1. Build context in agent A
    In Claude Code: analyze the architecture of this project using ctx_overview.✓ Copiado
    → Context built and cached by lean-ctx
  2. Share to agent B
    In Cursor: use ctx_share to pull the architecture context from the last session.✓ Copiado
    → Cursor gets the architecture map without re-reading all files
  3. Track costs across agents
    lean-ctx gain --all-sessions✓ Copiado
    → Combined savings across both agents

Resultado: Multiple agents share a cached context layer, avoiding redundant file reads.

Armadilhas
  • Stale cache after file changes — lean-ctx tracks file modification times — cache invalidates automatically on change

Combinações

Combine com outros MCPs para 10× de alavancagem

lean-ctx + filesystem

Use lean-ctx for token-efficient reads and filesystem MCP for writes — best of both worlds

Use ctx_read to analyze the codebase structure efficiently, then use filesystem MCP to apply the refactoring changes.✓ Copiado
lean-ctx + github

lean-ctx compresses local context, GitHub MCP handles remote operations — minimizing total tokens

Use ctx_overview to understand the project, then use GitHub MCP to create a well-informed PR description.✓ Copiado

Ferramentas

O que este MCP expõe

FerramentaEntradasQuando chamarCusto
ctx_read file: str, mode: full|map|signatures|diff|aggressive|entropy|task|lines Read a file with controlled verbosity 0 — local cached read
ctx_multi_read files: str[], mode?: str Read multiple files in one call 0
ctx_tree path: str Get project structure 0
ctx_search query: str, path?: str Find patterns in code 0
ctx_smart_read file: str, intent: str Read with task-aware filtering 0
ctx_shell command: str Run shell commands with output compression 0
ctx_overview path: str Get a high-level project overview 0
ctx_session - Manage context across conversation turns 0
ctx_cost - Track how much you've saved 0

Custo e limites

O que custa rodar

Cota de API
No external API — everything runs locally.
Tokens por chamada
That's the point: ctx_read in map mode uses ~10% of the tokens a full read would. Shell compression saves 60-95%.
Monetário
Free and open-source (MIT). Saves $30-100+/month on AI coding API costs for active developers.
Dica
Use 'map' mode as default for exploration, 'full' only when you need every line. The savings compound fast.

Segurança

Permissões, segredos, alcance

Armazenamento de credenciais: No credentials needed. Purely local tool.
Saída de dados: Zero. No telemetry, no analytics, no network requests. Everything stays on your machine.

Solução de problemas

Erros comuns e correções

Shell commands produce garbled output

Run lean-ctx setup to update hooks to the latest version. If persists, run lean-ctx-off to disable temporarily.

Verificar: lean-ctx doctor
MCP server not detected by editor

Run lean-ctx setup again — it auto-configures all detected editors. For manual setup: claude mcp add lean-ctx lean-ctx

Verificar: lean-ctx doctor
Binary not found after install

Shell aliases auto-fallback safely. Re-run the install script or brew reinstall lean-ctx.

Verificar: which lean-ctx
ctx_read returns stale content

lean-ctx tracks file mtime for cache invalidation. If you edited outside the normal flow, touch the file to reset the mtime.

Verificar: lean-ctx cache --status

Alternativas

lean-ctx vs. outros

AlternativaQuando usarTroca
Rust Token KillerYou want a similar concept with different tradeoffsFewer tools (~50 patterns vs 42 tools), 3 editor support vs 24, has default-on telemetry with PII
Manual .cursorrules / CLAUDE.md context managementYou prefer manual context curationNo automatic compression; no caching; more work

Mais

Recursos

📖 Leia o README oficial no GitHub

🐙 Ver issues abertas

🔍 Ver todos os 400+ servidores MCP e Skills