MCPHub LabRegistryyvgude/lean-ctx
yvgude

yvgude/lean ctx

Built by yvgude โ€ข 351 stars

What is yvgude/lean ctx?

Hybrid Context Optimizer โ€” Shell Hook + MCP Server. Reduces LLM token consumption by 89-99%. Single Rust binary, zero dependencies.

How to use yvgude/lean ctx?

1. Install a compatible MCP client (like Claude Desktop). 2. Open your configuration settings. 3. Add yvgude/lean ctx using the following command: npx @modelcontextprotocol/yvgude-lean-ctx 4. Restart the client and verify the new tools are active.
๐Ÿ›ก๏ธ Scoped (Restricted)
npx @modelcontextprotocol/yvgude-lean-ctx --scope restricted
๐Ÿ”“ Unrestricted Access
npx @modelcontextprotocol/yvgude-lean-ctx

Key Features

Native MCP Protocol Support
Real-time Tool Activation & Execution
Verified High-performance Implementation
Secure Resource & Context Handling

Optimized Use Cases

Extending AI models with custom local capabilities
Automating system workflows via natural language
Connecting external data sources to LLM context windows

yvgude/lean ctx FAQ

Q

Is yvgude/lean ctx safe?

Yes, yvgude/lean ctx follows the standardized Model Context Protocol security patterns and only executes tools with explicit user-granted permissions.

Q

Is yvgude/lean ctx up to date?

yvgude/lean ctx is currently active in the registry with 351 stars on GitHub, indicating its reliability and community support.

Q

Are there any limits for yvgude/lean ctx?

Usage limits depend on the specific implementation of the MCP server and your system resources. Refer to the official documentation below for technical details.

Official Documentation

View on GitHub
  โ–ˆโ–ˆโ•—     โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—     โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•—
  โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•‘    โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ•šโ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ•šโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•
  โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•‘    โ–ˆโ–ˆโ•‘        โ–ˆโ–ˆโ•‘    โ•šโ–ˆโ–ˆโ–ˆโ•”โ• 
  โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ•”โ•โ•โ•  โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘    โ–ˆโ–ˆโ•‘        โ–ˆโ–ˆโ•‘    โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•— 
  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘ โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ•‘    โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•”โ• โ–ˆโ–ˆโ•—
  โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•  โ•šโ•โ•โ•โ•     โ•šโ•โ•โ•โ•โ•โ•   โ•šโ•โ•   โ•šโ•โ•  โ•šโ•โ•
             The Intelligence Layer for AI Coding
<h3 align="center">The Intelligence Layer for AI Coding</h3> <p align="center"> <strong>Shell Hook + Context Server ยท 24 tools ยท 90+ patterns ยท Single Rust binary</strong> </p> <p align="center"> <a href="https://github.com/yvgude/lean-ctx/actions/workflows/ci.yml"><img src="https://github.com/yvgude/lean-ctx/actions/workflows/ci.yml/badge.svg" alt="CI"></a> <a href="https://github.com/yvgude/lean-ctx/actions/workflows/security-check.yml"><img src="https://github.com/yvgude/lean-ctx/actions/workflows/security-check.yml/badge.svg" alt="Security"></a> <a href="https://crates.io/crates/lean-ctx"><img src="https://img.shields.io/crates/v/lean-ctx?color=%23e6522c" alt="crates.io"></a> <a href="https://crates.io/crates/lean-ctx"><img src="https://img.shields.io/crates/d/lean-ctx?color=%23e6522c" alt="Downloads"></a> <a href="https://www.npmjs.com/package/lean-ctx-bin"><img src="https://img.shields.io/npm/v/lean-ctx-bin?label=npm&color=%23cb3837" alt="npm"></a> <a href="https://aur.archlinux.org/packages/lean-ctx"><img src="https://img.shields.io/aur/version/lean-ctx?color=%231793d1" alt="AUR"></a> <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License"></a> <a href="https://discord.gg/pTHkG9Hew9"><img src="https://img.shields.io/badge/Discord-Join-5865F2?logo=discord&logoColor=white" alt="Discord"></a> <a href="https://x.com/leanctx"><img src="https://img.shields.io/badge/๐•-Follow-000000?logo=x&logoColor=white" alt="X/Twitter"></a> </p> <p align="center"> <a href="https://leanctx.com">Website</a> ยท <a href="#-get-started-60-seconds">Install</a> ยท <a href="#-how-it-works">How It Works</a> ยท <a href="#-24-intelligent-tools">Tools</a> ยท <a href="#-shell-hook-patterns-90">Patterns</a> ยท <a href="CHANGELOG.md">Changelog</a> ยท <a href="https://discord.gg/pTHkG9Hew9">Discord</a> </p>
<br>

lean-ctx reduces LLM token consumption by up to 99% through three complementary strategies in a single binary โ€” making AI coding faster, cheaper, and more effective.

<br>

โšก What It Does

  Without lean-ctx:                              With lean-ctx:

  LLM โ”€โ”€"read auth.ts"โ”€โ”€โ–ถ Editor โ”€โ”€โ–ถ File       LLM โ”€โ”€"ctx_read auth.ts"โ”€โ”€โ–ถ lean-ctx โ”€โ”€โ–ถ File
    โ–ฒ                                  โ”‚           โ–ฒ                           โ”‚            โ”‚
    โ”‚      ~2,000 tokens (full file)   โ”‚           โ”‚   ~13 tokens (cached)     โ”‚ cache+hash โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ””โ”€โ”€โ”€โ”€โ”€โ”€ (compressed) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

  LLM โ”€โ”€"git status"โ”€โ”€โ–ถ  Shell  โ”€โ”€โ–ถ  git        LLM โ”€โ”€"git status"โ”€โ”€โ–ถ  lean-ctx  โ”€โ”€โ–ถ  git
    โ–ฒ                                 โ”‚            โ–ฒ                       โ”‚              โ”‚
    โ”‚     ~800 tokens (raw output)    โ”‚            โ”‚   ~150 tokens         โ”‚ compress     โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ””โ”€โ”€โ”€โ”€โ”€โ”€ (filtered) โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
StrategyHowImpact
Shell HookTransparently compresses CLI output (90+ patterns) before it reaches the LLM60-95% savings
Context Server24 MCP tools for cached reads, mode selection, deltas, dedup, memory74-99% savings
AI Tool HooksOne-command integration via lean-ctx init --agent <tool>Works everywhere
<br>

๐ŸŽฏ Token Savings โ€” Real Numbers

OperationFreqWithoutWith lean-ctxSaved
File reads (cached)15ร—30,00019599%
File reads (map mode)10ร—20,0002,00090%
ls / find8ร—6,4001,28080%
git status/log/diff10ร—8,0002,40070%
grep / rg5ร—8,0002,40070%
cargo/npm build5ร—5,0001,00080%
Test runners4ร—10,0001,00090%
curl (JSON)3ร—1,50016589%
docker ps/build3ร—90018080%
Session total~89,800~10,62088%

Based on typical Cursor/Claude Code sessions with medium TypeScript/Rust projects. Cached re-reads cost ~13 tokens.

<br>

๐Ÿš€ Get Started (60 seconds)

# 1. Install (pick one)
curl -fsSL https://leanctx.com/install.sh | sh     # universal, no Rust needed
brew tap yvgude/lean-ctx && brew install lean-ctx    # macOS / Linux
npm install -g lean-ctx-bin                          # Node.js
cargo install lean-ctx                               # Rust

# 2. Setup (auto-configures shell + ALL detected editors)
lean-ctx setup

# 3. Verify
lean-ctx doctor
<details> <summary><strong>Troubleshooting</strong></summary>
ProblemFix
Commands broken?Run lean-ctx-off (fixes current session)
Permanent fix?Run lean-ctx uninstall (removes all hooks)
Binary missing?Aliases auto-fallback to original commands (safe)
Manual fix?Edit ~/.zshrc, remove the lean-ctx shell hook block
Preview changes?lean-ctx init --global --dry-run
Diagnose?lean-ctx doctor

lean-ctx creates a backup of your shell config before modifying it (~/.zshrc.lean-ctx.bak).

</details> <details> <summary><strong>Supported editors (auto-detected by <code>lean-ctx setup</code>)</strong></summary>
EditorMethodStatus
CursorMCP (mcp.json)โœ… Auto
Claude Codeclaude mcp addโœ… Auto
GitHub CopilotMCP (.github/copilot/mcp.json)โœ… Auto
WindsurfMCP (mcp_config.json)โœ… Auto
VS CodeMCPโœ… Auto
ZedContext Server (settings.json)โœ… Auto
Codex CLIconfig.tomlโœ… Auto
Gemini CLImcp.jsonโœ… Auto
OpenCodeopencode.jsonโœ… Auto
Pilean-ctx init --agent piโœ… Auto
OpenClawShell hook + skill๐Ÿ“‹ Manual
Google AntigravityMCPโœ… Auto
</details> <br>

๐Ÿง  Three Intelligence Protocols

<table> <tr> <td width="33%">

CEP

Cognitive Efficiency Protocol

Adaptive LLM communication with compliance scoring (0-100), task complexity classification, quality scoring, auto-validation pipeline.

Measurable efficiency gains

</td> <td width="33%">

CCP

Context Continuity Protocol

Cross-session memory that persists tasks, findings, decisions across chats. LITM-aware positioning for optimal attention placement.

-99.2% cold-start tokens

</td> <td width="33%">

TDD

Token Dense Dialect

Symbol shorthand (ฮป ยง โˆ‚ ฯ„ ฮต) and ROI-based identifier mapping for compact LLM communication.

8-25% extra savings

</td> </tr> </table> <br>

๐Ÿ›  24 Intelligent Tools

Core

ToolPurposeSavings
ctx_readFile reads โ€” 7 modes + lines:N-M, caching, fresh=true74-99%
ctx_multi_readMultiple file reads in one round trip74-99%
ctx_treeDirectory listings (ls, find, Glob)34-60%
ctx_shellShell commands with 90+ compression patterns60-90%
ctx_searchCode search (Grep)50-80%
ctx_compressContext checkpoint for long conversations90-99%

Intelligence

ToolWhat it does
ctx_smart_readAdaptive mode โ€” auto-picks full/map/signatures/diff based on file type and cache
ctx_deltaIncremental updates โ€” only sends changed hunks via Myers diff
ctx_dedupCross-file deduplication โ€” finds shared imports and boilerplate
ctx_fillPriority-based context filling โ€” maximizes info within a token budget
ctx_intentSemantic intent detection โ€” classifies queries and auto-loads files
ctx_responseResponse compression โ€” removes filler, applies TDD
ctx_contextMulti-turn session overview โ€” tracks what the LLM already knows
ctx_graphProject intelligence graph โ€” dependency analysis + related file discovery
ctx_discoverShell history analysis โ€” finds missed compression opportunities

Memory & Multi-Agent

ToolWhat it does
ctx_sessionCross-session memory โ€” persist task, findings, decisions across chats
ctx_knowledgePersistent project knowledge โ€” remember facts, recall by query/category
ctx_agentMulti-agent sharing โ€” register agents, post/read scratchpad, coordinate sessions
ctx_wrappedShareable savings report โ€” "Spotify Wrapped" for your tokens

Analysis

ToolWhat it does
ctx_benchmarkSingle-file or project-wide benchmark with preservation scores
ctx_metricsSession statistics with USD cost estimates
ctx_analyzeShannon entropy analysis + mode recommendation
ctx_cacheCache management: status, clear, invalidate
<br>

๐Ÿ“– ctx_read Modes

ModeWhen to useToken cost
fullFiles you will edit (cached re-reads โ‰ˆ 13 tokens)100% first, ~0% cached
mapUnderstanding a file โ€” deps + exports + API~5-15%
signaturesAPI surface with more detail than map~10-20%
diffRe-reading files that changedchanged lines only
aggressiveLarge files with boilerplate~30-50%
entropyRepetitive patterns (Shannon + Jaccard filtering)~20-40%
lines:N-MSpecific ranges (e.g. lines:10-50,80-90)proportional
<br>

๐Ÿ”Œ Shell Hook Patterns (90+)

Pattern-based compression for 90+ commands across 34 categories:

<details> <summary><strong>View all 34 categories</strong></summary>
CategoryCommandsSavings
Git (19)status, log, diff, add, commit, push, pull, fetch, clone, branch, checkout, switch, merge, stash, tag, reset, remote, blame, cherry-pick70-95%
Docker (10)build, ps, images, logs, compose ps/up/down, exec, network, volume, inspect70-90%
npm/pnpm/yarn (6)install, test, run, list, outdated, audit70-90%
Cargo (3)build, test, clippy80%
GitHub CLI (9)pr list/view/create/merge, issue list/view/create, run list/view60-80%
Kubernetes (8)get pods/services/deployments, logs, describe, apply, delete, exec, top, rollout60-85%
Python (7)pip install/list/outdated/uninstall/check, ruff check/format60-80%
Ruby (4)rubocop, bundle install/update, rake test, rails test60-85%
Linters (4)eslint, biome, prettier, stylelint60-70%
Build Tools (3)tsc, next build, vite build60-80%
Test Runners (8)jest, vitest, pytest, go test, playwright, cypress, rspec, minitest90%
Terraforminit, plan, apply, destroy, validate, fmt, state, import, workspace60-85%
Makemake targets, parallel jobs, dry-run60-80%
Maven / Gradlecompile, test, package, install, clean, dependency trees60-85%
.NETdotnet build, test, restore, run, publish, pack60-85%
Flutter / Dartflutter pub, analyze, test, build; dart pub, analyze, test60-85%
Poetry / uvinstall, sync, lock, run, add, remove; uv pip/sync/run60-85%
AWS (7)s3, ec2, lambda, cloudformation, ecs, logs, sts60-80%
Databases (2)psql, mysql/mariadb50-80%
Prisma (6)generate, migrate, db push/pull, format, validate70-85%
Helm (5)list, install, upgrade, status, template60-80%
Bun (3)test, install, build60-85%
Deno (5)test, lint, check, fmt, task60-85%
Swift (3)test, build, package resolve60-80%
Zig (2)test, build60-80%
CMake (3)configure, build, ctest60-80%
Ansible (2)playbook recap, task summary60-80%
Composer (3)install, update, outdated60-80%
Mix (5)test, deps, compile, format, credo/dialyzer60-80%
Bazel (3)test, build, query60-80%
systemd (2)systemctl, journalctl50-80%
Utils (5)curl, grep/rg, find, ls, wget50-89%
Data (3)env (filtered), JSON schema extraction, log dedup50-80%
</details>

After lean-ctx init --global, 23 commands are transparently compressed via shell aliases:

git ยท npm ยท pnpm ยท yarn ยท cargo ยท docker ยท docker-compose ยท kubectl ยท k
gh ยท pip ยท pip3 ยท ruff ยท go ยท golangci-lint ยท eslint ยท prettier ยท tsc
ls ยท find ยท grep ยท curl ยท wget
<br>

๐Ÿ‘€ Examples

<details> <summary><strong>Directory listing</strong> โ€” 239 โ†’ 46 tokens (-81%)</summary>
# ls -la src/                               # lean-ctx -c "ls -la src/"
total 96                                     core/
drwxr-xr-x  4 user staff  128 ...           tools/
drwxr-xr-x  11 user staff 352 ...           cli.rs  9.0K
-rw-r--r--  1 user staff  9182 ...           main.rs  4.0K
-rw-r--r--  1 user staff  4096 ...           server.rs  11.9K
...                                          shell.rs  5.2K
                                             4 files, 2 dirs
                                             [lean-ctx: 239โ†’46 tok, -81%]
</details> <details> <summary><strong>File reading (map mode)</strong> โ€” 2,078 โ†’ ~30 tokens (-99%)</summary>
# Full read (284 lines, ~2078 tokens)       # lean-ctx read stats.rs -m map (~30 tokens)
use serde::{Deserialize, Serialize};         stats.rs [284L]
use std::collections::HashMap;                 deps: serde::
use std::path::PathBuf;                        exports: StatsStore, load, save, record, format_gain
                                               API:
#[derive(Serialize, Deserialize)]                cl โŠ› StatsStore
pub struct StatsStore {                          fn โŠ› load() โ†’ StatsStore
    pub total_commands: u64,                     fn โŠ› save(store:&StatsStore)
    pub total_input_tokens: u64,                 fn โŠ› record(command:s, input_tokens:n, output_tokens:n)
    ...                                          fn โŠ› format_gain() โ†’ String
(284 more lines)                             [2078 tok saved (100%)]
</details> <details> <summary><strong>curl (JSON)</strong> โ€” 127 โ†’ 14 tokens (-89%)</summary>
# curl -s httpbin.org/json                   # lean-ctx -c "curl -s httpbin.org/json"
{                                            JSON (428 bytes):
  "slideshow": {                             {
    "author": "Yours Truly",                   slideshow: {4K}
    "date": "date of publication",           }
    "slides": [                              [lean-ctx: 127โ†’14 tok, -89%]
      {
        "title": "Wake up to WonderWidgets!",
        ...
</details> <details> <summary><strong>Visual terminal dashboard</strong></summary>
$ lean-ctx gain

  โ—† lean-ctx  Token Savings Dashboard
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

   1.7M          76.8%         520          $33.71
   tokens saved   compression    commands       USD saved

  Cost Breakdown  (@ $2.50/M input, $10/M output)
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  Without lean-ctx    $44.75  ($5.79 input + $38.96 output)
  With lean-ctx       $11.04  ($1.76 input + $9.28 output)
  Saved               $33.71  ($4.03 input + $29.68 output)

  Top Commands
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  curl                48x  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ 728.1K  97%
  git commit          34x  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž          375.2K  50%
  ctx_read           103x  โ–ˆโ–Œ                    59.1K  38%
    ... +33 more commands

  lean-ctx v2.12.6  |  leanctx.com  |  lean-ctx dashboard
</details> <br>

๐Ÿ”ฌ Scientific Compression Engine

Built on information theory and attention modeling (v2.6):

FeatureWhat it doesImpact
Adaptive EntropyPer-language BPE entropy + Jaccard thresholds with Kolmogorov adjustment10-25%
Attention ModelHeuristic U-curve positional weighting + structural importance scoringโ†‘ comprehension
TF-IDF CodebookCross-file pattern dedup via cosine similarity5-15%
Feedback LoopLearns optimal thresholds per language/file type across sessionsauto-improving
Info BottleneckEntropy + task-relevance filtering (Tishby et al., 2000)20-40%
ctx_overviewMulti-resolution project map with graph-based relevance tiers90%+
<br>

๐ŸŒณ tree-sitter Signature Engine

AST-based signature extraction for 14 languages: TypeScript, JavaScript, Rust, Python, Go, Java, C, C++, Ruby, C#, Kotlin, Swift, PHP.

CapabilityRegex (old)tree-sitter
Multi-line signaturesโœ—โœ“
Arrow functionsโœ—โœ“
Nested classes/methodsHeuristicAST scope
Languages414

Build without tree-sitter for a smaller binary (~5.7 MB vs ~17 MB):

cargo install lean-ctx --no-default-features
<br>

๐Ÿ“Š CLI Commands

<details> <summary><strong>Shell Hook</strong></summary>
lean-ctx -c "git status"       # Execute + compress output
lean-ctx exec "cargo build"    # Same as -c
lean-ctx shell                 # Interactive REPL with compression
</details> <details> <summary><strong>File Operations</strong></summary>
lean-ctx read file.rs                         # Full content (structured header)
lean-ctx read file.rs -m map                  # Deps + API signatures (~10% tokens)
lean-ctx read file.rs -m signatures           # Function/class signatures only
lean-ctx read file.rs -m aggressive           # Syntax-stripped (~40% tokens)
lean-ctx read file.rs -m entropy              # Shannon entropy filtered (~30%)
lean-ctx read file.rs -m "lines:10-50,80-90"  # Specific line ranges
lean-ctx diff file1.rs file2.rs               # Compressed file diff
lean-ctx grep "pattern" src/                  # Grouped search results
lean-ctx find "*.rs" src/                     # Compact find results
lean-ctx ls src/                              # Token-optimized directory listing
lean-ctx deps .                               # Project dependencies summary
</details> <details> <summary><strong>Setup & Analytics</strong></summary>
lean-ctx setup                 # One-command setup: shell + editors + verify
lean-ctx init --global         # Install 23 shell aliases
lean-ctx init --agent claude   # Claude Code hook
lean-ctx init --agent cursor   # Cursor hooks.json
lean-ctx init --agent gemini   # Gemini CLI hook
lean-ctx init --agent codex    # Codex AGENTS.md
lean-ctx init --agent windsurf # .windsurfrules
lean-ctx init --agent cline    # .clinerules
lean-ctx init --agent pi       # Pi Coding Agent extension
lean-ctx gain                  # Visual terminal dashboard
lean-ctx gain --live           # Live auto-updating dashboard
lean-ctx gain --graph          # ASCII chart (30 days)
lean-ctx gain --daily          # Day-by-day breakdown
lean-ctx gain --json           # Raw JSON export
lean-ctx dashboard             # Web dashboard (localhost:3333)
lean-ctx cheatsheet            # Quick reference
lean-ctx discover              # Find uncompressed commands
lean-ctx doctor                # Diagnostics
lean-ctx update                # Self-update
lean-ctx wrapped               # Shareable savings report
lean-ctx benchmark run         # Real project benchmark
lean-ctx benchmark report      # Markdown report
</details> <details> <summary><strong>Multi-Agent Launcher</strong></summary>
lctx                              # Auto-detect agent, current dir
lctx --agent claude               # Launch Claude Code with lean-ctx
lctx --agent cursor               # Configure Cursor
lctx --agent gemini               # Launch Gemini CLI
lctx /path/to/project "prompt"    # Project + prompt
lctx --scan-only                  # Build project graph only
</details> <br>

โš™๏ธ Editor Configuration

lean-ctx setup handles this automatically. Manual config below is only needed for edge cases.

<details> <summary><strong>Cursor</strong></summary>

~/.cursor/mcp.json:

{
  "mcpServers": {
    "lean-ctx": { "command": "lean-ctx" }
  }
}
</details> <details> <summary><strong>GitHub Copilot</strong></summary>

.github/copilot/mcp.json:

{
  "servers": {
    "lean-ctx": { "command": "lean-ctx" }
  }
}
</details> <details> <summary><strong>Claude Code</strong></summary>
claude mcp add lean-ctx lean-ctx
</details> <details> <summary><strong>Windsurf</strong></summary>

~/.codeium/windsurf/mcp_config.json:

{
  "mcpServers": {
    "lean-ctx": { "command": "lean-ctx" }
  }
}

If tools don't load, use the full path (e.g., /Users/you/.cargo/bin/lean-ctx). Windsurf spawns MCP servers with a minimal PATH.

</details> <details> <summary><strong>Zed</strong></summary>

~/.config/zed/settings.json:

{
  "context_servers": {
    "lean-ctx": {
      "source": "custom",
      "command": "lean-ctx",
      "args": [],
      "env": {}
    }
  }
}
</details> <details> <summary><strong>OpenAI Codex</strong></summary>

~/.codex/config.toml:

[mcp_servers.lean-ctx]
command = "lean-ctx"
args = []
</details> <details> <summary><strong>Gemini CLI</strong></summary>

~/.gemini/settings/mcp.json:

{
  "mcpServers": {
    "lean-ctx": { "command": "lean-ctx" }
  }
}
</details> <details> <summary><strong>Pi Coding Agent</strong></summary>
lean-ctx init --agent pi
# Or: pi install npm:pi-lean-ctx

Pi's bash, read, grep, find, and ls tools are automatically routed through lean-ctx. Supports 55+ file extensions with auto mode selection.

</details> <details> <summary><strong>OpenCode</strong></summary>

~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "lean-ctx": {
      "type": "local",
      "command": ["lean-ctx"],
      "enabled": true
    }
  }
}
</details> <br>

๐Ÿ† lean-ctx vs RTK

FeatureRTKlean-ctx
ArchitectureShell hook onlyShell hook + MCP server
CLI patterns~5090+
File readingSignatures only7 modes (full, map, signatures, diff, aggressive, entropy, lines)
File cachingโœ—โœ“ (re-reads โ‰ˆ 13 tokens)
Signature engineRegex (4 langs)tree-sitter AST (14 langs)
Dependency mapsโœ—โœ“
Context checkpointsโœ—โœ“
Token countingEstimatedtiktoken-exact
Entropy analysisโœ—โœ“
Cost trackingโœ—โœ“ (USD estimates)
TDD modeโœ—โœ“ (8-25% extra)
Thinking reductionโœ—โœ“ (CRP v2)
Cross-session memoryโœ—โœ“ (CCP)
LITM positioningโœ—โœ“
Multi-agent sharingโœ—โœ“
Project knowledge storeโœ—โœ“
Web dashboardโœ—โœ“
Savings reportsโœ—โœ“ (wrapped)
Editor support3 editors12+ editors
<br>

๐Ÿ” Security

lean-ctx is local-only โ€” zero network requests, zero telemetry. See SECURITY.md.

Note on VirusTotal: Rust binaries are frequently flagged by ML-based heuristic scanners. This is a known issue. Build from source with cargo install lean-ctx to verify.

<br>

๐Ÿ—‘ Uninstall

lean-ctx init --global   # See what was added, then remove from shell profile
cargo uninstall lean-ctx # Remove binary
rm -rf ~/.lean-ctx       # Remove stats + config
<br>

๐Ÿค Contributing

Contributions welcome! Open an issue or PR on GitHub.

<p align="center"> <a href="https://discord.gg/pTHkG9Hew9">Discord</a> ยท <a href="https://x.com/leanctx">๐• / Twitter</a> ยท <a href="https://buymeacoffee.com/yvgude">Buy me a coffee โ˜•</a> </p> <br>

๐Ÿ“„ License

MIT โ€” see LICENSE.

<br> <p align="center"> <sub>Built with ๐Ÿฆ€ Rust ยท Made in Switzerland ๐Ÿ‡จ๐Ÿ‡ญ</sub> </p>

Global Ranking

8.5
Trust ScoreMCPHub Index

Based on codebase health & activity.

Manual Config

{ "mcpServers": { "yvgude-lean-ctx": { "command": "npx", "args": ["yvgude-lean-ctx"] } } }