lean-ctx
LeanCTX is the Context Gateway for AI Systems. Select task-relevant context, apply supported controls, connect local knowledge and inspect recorded evidence. Open-source Engine: CLI, MCP, hooks and supported proxy paths.
Install / Use
claude mcp add yvgude -- npx -y github:yvgude/lean-ctxIf the server publishes to npm under a different name, use that package instead — check the repo README.
MCP Server
Model Context Protocol server
Quality Score
Category
SecuritySupported Platforms
Our assessment of lean-ctx
lean-ctx scores 95/100 on our quality scale, 216th of 1,099 Security skills we index (top 20%).
Its MCP Server is 35 KB long, well organised into 45 sections with 22 code examples: a thorough specification that gives an agent plenty to work with.
With 3,928 GitHub stars, it is one of the more widely adopted skills in the catalogue.
Maintenance, license and trust
- The repository was last updated today, so lean-ctx is actively maintained.
- Our last check on 2026-10-21 found the source still online.
- It is released under the Apache-2.0 license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
Safety scan
No issues foundOur scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands (2 minor notes below). An AI review of the same text found nothing harmful.
- noteInstalls by piping a downloaded script into a shellline 279
curl -fsSL https://leanctx.com/install.sh | sh # universal (no Rust needed) - noteInstalls by piping a downloaded script into a shellline 705
curl -fsSL https://leanctx.com/install.sh | sh -s -- --uninstall
AI review by kimi-k2.7-code on 2026-09-24. Automated pattern scan on 2026-09-24. It catches known dangerous patterns, not every risk — read a skill before letting an agent act on it.
lean-ctx compared with similar skills
All 4 of these similar skills score higher than lean-ctx; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| lean-ctx (this skill)by yvgude | 95 | 3.9k | today | MCP Server |
| Agent-Reachby Panniantong | 100 | 109.2k | today | CLAUDE.md |
| headroomby headroomlabs-ai | 100 | 78.9k | today | CLAUDE.md |
| CowAgentby zhayujie | 100 | 47.8k | today | CLAUDE.md |
| Scraplingby D4Vinci | 100 | 97.9k | today | MCP Server |
Frequently asked questions
- How do I install lean-ctx?
- Run
claude mcp add yvgude -- npx -y github:yvgude/lean-ctx. The install tabs above show the steps for each supported agent. - Which AI agents does lean-ctx work with?
- It is written for Claude Code, Claude Desktop, Cursor, GitHub Copilot and Gemini CLI, as a MCP Server file. Other agents that read the same format can often use it too.
- Is lean-ctx safe to use?
- Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands (2 minor notes below). An AI review of the same text found nothing harmful. It is Apache-2.0-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is lean-ctx still maintained?
- The repository was last updated today, so lean-ctx is actively maintained.
Skill content
View source on GitHubControl what your AI can see.
LeanCTX — AI Value Gate for AI Coding Agents
LeanCTX — short for Lean Context — is an AI Value Gate and context engineering layer for AI coding agents. It runs locally alongside your coding agent, helping it read repositories, run development commands, and send focused context to the model: it understands the task, routes the right context, compresses what it sends, and tracks the cost and outcome of that work. Savings depend on the workload and enabled modes; the local savings ledger and Shadow Mode show the measured result against a comparable baseline. Zero config required. Local-first.
| Problem | With LeanCTX | |---------|-------------| | Repeated file reads resend unchanged content | Cached re-reads return a compact deterministic reference | | Raw development commands include repetitive noise | Command-specific compression preserves salient output | | Every turn re-sends the whole history | Proxy compresses each request, prompt-cache-safe | | Context resets every chat | Session memory persists across chats | | No visibility into context usage | Real-time dashboard + budget control |
<p> <a href="https://github.com/yvgude/lean-ctx/stargazers"><img src="https://img.shields.io/github/stars/yvgude/lean-ctx?style=social" alt="GitHub Stars"></a> <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-Apache%202.0-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> <img src="https://img.shields.io/badge/Telemetry-Opt--in%20Only-brightgreen?logo=shield&logoColor=white" alt="Opt-in Telemetry"> </p> <p> <a href="https://leanctx.com">Website</a> · <a href="https://leanctx.com/docs/getting-started">Docs</a> · <a href="#get-started-30-seconds">Install</a> · <a href="#real-world-scenarios">Scenarios</a> · <a href="#demo">Demo</a> · <a href="#benchmarks">Benchmarks</a> · <a href="cookbook/README.md">Cookbook</a> · <a href="SECURITY.md">Security</a> · <a href="CHANGELOG.md">Changelog</a> </p> </div>
Control what your AI can see — and what it costs. LeanCTX is an AI Value Gate for coding agents: it understands tasks, routes and compresses context, remembers what it learns, and measures cost against accepted outcomes.
<p align="center"><strong>See it in action:</strong></p> <table> <tr> <td align="center" width="33%"> <img src="assets/leanctx-demo.gif" width="320" alt="Map-mode file read + compressed git output demo"> <br/> <strong>Read + Shell</strong> <br/> Map-mode reads + compressed CLI output </td> <td align="center" width="33%"> <img src="assets/leanctx-gain.gif" width="320" alt="lean-ctx gain live dashboard demo"> <br/> <strong>Gain (live)</strong> <br/> Tokens + USD savings in real time </td> <td align="center" width="33%"> <img src="assets/leanctx-benchmark.gif" width="320" alt="lean-ctx benchmark report demo"> <br/> <strong>Benchmark proof</strong> <br/> Measure compression by language + mode </td> </tr> </table> <p align="center"><sub>All GIFs are generated from reproducible VHS tapes in <code>demo/</code>.</sub></p>Token savings are the receipt. Intelligence is the product. Works with Cursor, Claude Code, Copilot, Windsurf, Codex, Gemini and 30+ other agents — no config needed.
Why developers use LeanCTX
- Longer useful coding sessions — less context waste = more room for actual code reasoning
- Lower API costs — reduce repeated context on reads and shell output; inspect the local savings ledger and Shadow Mode baseline for your workload
- No more "I already showed you this file" — session memory persists across chats
- Works with your existing setup — one
lean-ctx setupcommand, no config changes needed - Full visibility — see exactly where your context window budget goes
- Model-agnostic & yours — swap OpenAI/Anthropic/Gemini freely; your context and memory stay local and portable, never locked in a vendor's black box
<p align="center"> <strong>Saves you tokens?</strong> <a href="https://github.com/yvgude/lean-ctx">Give it a star</a> — it helps others discover LeanCTX. </p>
Why now — own your context
Models are converging on commodity. The durable edge isn't which model you call — it's your context: what your agents read, what they remember, and what you can prove. And the layer that optimizes and owns that context can't come from the vendor that bills per token or keeps your memory in a black box — it has to sit on your side.
That's the shift behind "agent entities" that live in your chat and remember your company (Claude in Slack, ClickUp Brain): a context login, not a model login — you end up renting your own company knowledge back. LeanCTX is the opposite layer. It keeps the moat yours: local-first, portable (.ctxpkg), and model-agnostic — swap OpenAI, Anthropic or Gemini without losing context or cache. Own your context; don't rent it back.
What it does — five capabilities of an AI Value Gate
LeanCTX treats context and AI spend as managed resources, not afterthoughts. One binary covers the capabilities that decide how well an AI agent performs:
1. Context Compression — input efficiency
Your AI agent reads files and runs commands. LeanCTX compresses both automatically.
-
Workload-specific token reduction on eligible context, with recovery paths and a local Shadow Mode baseline for measurement
-
File reads: 10 read modes (
full,map,signatures,diff,lines:N-M,density:X, …) — cached re-reads cost ~13 tokens -
Target density (
density:0.4): SDE-style budget compression — keeps the highest-entropy lines until ~40% of the original tokens remain, deterministic -
JIT disclosure:
signaturescarries line spans and points atlines:N-Mfor targeted expansion — outline first, bodies on demand -
Shell output: 95+ shell-output patterns compress git, npm, cargo, docker, kubectl, terraform and more (270 passthrough rules)
-
Tree-sitter AST: structural understanding for 27 languages — not just text compression
-
Reversible by design (CCR): compression never discards content — pruned or truncated payloads move to a content-addressed store with a deterministic handle, so the model can pull the original bytes back on demand via
ctx_expand,ctx_retrieve, an in-band marker, orGET /v1/references/{id}. Five recovery paths →
2. Intelligent Triage — task understanding
Not every task or file needs the same depth. LeanCTX classifies the task, then sends the signal rather than the noise.
- 10 read modes: from full content down to AST signatures and entropy-filtered views
- Adaptive
ModePredictor: learns the optimal read mode per file type from past sessions IntentEngine: classifies query complexity so simple lookups stay cheap
3. Knowledge Routing — cross-source context
Relevant code, sessions, and connected sources become focused context instead of a larger prompt.
- Session memory (CCP): persist task/facts/decisions across chats — structured recovery queries survive compaction
- Knowledge graph: temporal facts with validity windows, episodic + procedural memory
- Property Graph: multi-edge code graph (imports, calls, exports, type_ref) powers impact analysis and search ranking
- Yours, not the vendor's: memory stays local and portable — export it as a
.ctxpkgpackage and move it across machines or models, instead of locking it in a vendor's black box
4. AI Value Gate — cost and outcome tracking
Performance is the cost of a useful result, not just speed. LeanCTX records costs and outcomes locally; CPAO (Cost per Accepted Outcome) is the north-star metric for comparing useful AI work.
- Context Manager: browser dashboard with real-time token tracking, compression stats, utilization gauge
- Budgets & SLOs: profiles, roles, per-agent budgets, and throttling policies
- Context Proof (
ctx_proof,ctx_verify): 4-layer verification engine with CI drift gates
5. Shadow Recommendations — savings proof
Shadow Mode compares LeanCTX treatment with a configured baseline without changing the active workflow. Its reports show cost, tokens, CPAO, and whether quality held, then recommend savings only when the comparison supports them.
Cost Intelligence
LeanCTX automatically tracks local cost and outcome signals; it does not add those reports to agent context. CPAO — cost per accepted outcome — is the north-star metric, while Shadow Mode provides a baseline comparison for savings.
lean-ctx savings --period week # costs, token savings, and CPAO
lean-ctx value-report --format markdown --last 20 # recent outcome quality
lean-ctx shadow --latest # latest baseline comparison
Quick start: value tracking
# Enable shadow mode for savings comparison
echo '[shadow]\nenabled = true' >> ~/.config/lean-ctx/config.toml
# After using LeanCTX for a while:
lean-ctx savings
lean-ctx shadow --latest
<details>
<summary><strong>Full feature list (complete MCP tool set)</strong></summary>
- Web & Research (
ctx_url_read): pull a public web page, PDF, or YouTube transcript into context as compressed, citation-backed text —facts/quotesreturn claims with a confidence score + source URL, relevance-ranked research-compression distils to a token budget, SSRF-guarded (http/https only) - Graph-Powered Intelligence: hybrid search (BM25 + embeddings + graph proximity via RRF), incremental git-diff updates
- LSP Refactoring (
ctx_refactor): language-server-powered rename, references, go-to-definition via rust-analyzer, typescript-language-server, pylsp, gopls - Multi-Agent (
ctx_agent,ctx_handoff): agent handoff with context transfer bundles, diary system, synchronized shared state - Archive Full-Text Search (
ctx_expand search_all): FTS5-powered cross-archive search over all previously archived tool outputs - PR Context Packs:
lean-ctx pack --prbuilds a PR-re
Truncated for display — read the full file on GitHub.
Related Skills
Agent-Reach
109.2kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
headroom
78.9kCompress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
CowAgent
47.8kOpen-source personal AI assistant & Agent Harness. Plans tasks, runs tools and skills, self-evolves with memory and knowledge. Multi-agent, multi-model, multi-channel. Lightweight, extensible, one-line install.
Scrapling
97.9k🕷️ The BEST Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
