lean-ctx
LeanCTX — Context Intelligence for AI systems.
Install / Use
npx skills add yvgude/lean-ctxInstalls into whichever agent you are using.
CLAUDE.md
Claude Code project instructions
Quality Score
Category
AI & Machine LearningSupported Platforms
Skill content
View source on GitHubControl what your AI can see.
LeanCTX — Context Engineering Layer for AI Coding Agents
LeanCTX — short for Lean Context — is the 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 decides what agents read, compresses what they send (an optional local proxy shrinks every request — system prompt, history and tool results — prompt-cache-safe), remembers what they learn, guards what they touch — and proves what they save with a signed, verifiable savings ledger. The result: 60–90% fewer tokens. Zero config required. Local-first.
| Problem | With LeanCTX |
|---------|-------------|
| Repeated file reads: ~2000 tokens each | Cached re-reads: ~13 tokens |
| Raw git status: ~800 tokens | Compressed: ~120 tokens |
| 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="https://pi.dev/packages/pi-lean-ctx"><img src="https://img.shields.io/badge/Pi.dev-pi--lean--ctx-6366f1?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJ3aGl0ZSI+PHRleHQgeD0iNCIgeT0iMTgiIGZvbnQtc2l6ZT0iMTYiIGZvbnQtZmFtaWx5PSJzZXJpZiI+z4A8L3RleHQ+PC9zdmc+" alt="Pi.dev"></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-60-seconds">Install</a> · <a href="#use-it-from-your-own-code-sdks">SDKs</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. LeanCTX — short for Lean Context — is the context engineering layer for AI coding agents: one local Rust binary that helps agents read repositories, run development commands, compress context sent to the model, remember what they learn, guard what they touch — and prove what they save.
<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 — 60–90% fewer tokens on reads and shell output, cached re-reads cost ~13 tokens
- 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 — the four dimensions of context
LeanCTX treats context as a managed resource, not an afterthought. One binary covers the four dimensions that decide how well an AI agent actually performs:
1. Compression — input efficiency
Your AI agent reads files and runs commands. LeanCTX compresses both automatically.
- 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. Routing — the right fidelity per read
Not every file needs the same depth. LeanCTX sends the signal, not 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. Memory — context that persists
Context doesn't disappear between chats anymore.
- 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. Verification — control what reaches the model
Performance is accuracy, not just speed. You stay in control of the window.
- 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
- 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-ready context pack (changed files, related tests, impact, artifacts) - Context Packages:
lean-ctx pack createbundles Knowledge + Graph + Session into portable.ctxpkgfiles with SHA-256 integrity - Context Time Machine:
lean-ctx snapshot create|list|show|verify|restore|publish|import— git-anchored, ed25519-signed snapshots of the layer state (lineage, ledger Φ, ROI, session) on an append-only timeline; replay them in the dashboard,restoreto resume a session (and--gitto check out the commit), orpublish/importa signed snapshot to share it (concept →) - Observability:
lean-ctx gain --livefor real-time savings,lean-ctx wrappedfor weekly/monthly summaries (gain --svg/--sharefor a shareable card or self-hostable page),lean-ctx watchfor TUI monitoring - Verified savings:
lean-ctx savingsis an auditable,
Truncated for display — read the full file on GitHub.
Related Skills
caveman
107.1k🪨 why use many token when few token do trick. Viral skill + proxy for coding agents that cuts 65% of tokens by talking like a caveman.
claude-mem
94.4kPersistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More
Agent-Reach
84.2kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
Understand-Anything
83.5kGraphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.
