LeanCTX is a local Rust program that controls the repository context an AI coding agent receives, including selecting, compressing, remembering, and tracking information. Developers use it alongside coding agents to reduce repeated context and manage what those agents read and execute, while the catalogue entries provide related rules, skills, and instructions.
Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
git clone --depth 1 https://github.com/yvgude/lean-ctxWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/rules/yvgude/lean-ctx/lean-ctx)<a href="https://agentmods.dev/rules/yvgude/lean-ctx/lean-ctx"><img src="https://agentmods.dev/badge/rules/yvgude/lean-ctx/lean-ctx/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/rules/yvgude/lean-ctx/lean-ctx"><img src="https://agentmods.dev/badge/rules/yvgude/lean-ctx/lean-ctx.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00969 | $0.00969 |
| Opus 5.5 | $0.00388 | $0.00388 |
| Sonnet 5.5 | $0.00194 | $0.00194 |
| Haiku 4.5 | $0.00097 | $0.00097 |
Grade A, and why
lean-ctx scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 100 lines — stays where its author put it; the contents beside it link to each section on GitHub.
lean-ctx MCP Tools
Always use lean-ctx MCP tools. Never use the standard equivalents.
Tool Mapping
| Instead of | Use | Why |
|---|---|---|
Read |
ctx_read |
Session caching, read modes, compact references for eligible re-reads |
Shell |
ctx_shell |
Pattern-based compression for git, npm, cargo, docker, tsc |
Grep |
ctx_search |
Compact context, token-efficient results |
ls, find |
ctx_tree |
Compact directory maps with file counts |
ctx_read Modes
full— default, cached read (use for files you will edit)map— dependency graph + exports + API signatures (use for context-only files)signatures— API surface only (tree-sitter AST for 26 languages)diff— changed lines only (use after edits)aggressive— syntax strippedentropy— Shannon + Jaccard filtering
Eligible unchanged re-reads return compact references. File refs F1, F2.. persist across the session.
Set fresh=true on ctx_read to bypass cache. Use when: spawned as a subagent, after context compaction, or if you see a [cached] response but do not have the file content in your context.
Default Strategy
- Reading for context →
map - Reading to understand API →
signatures - Reading to edit →
full - Re-reading → call
fullagain (eligible cache hits return a compact reference)
v2.3.0 Scientific Features (automatic)
- Auto-Delta — re-reading a changed file sends only the diff (98.9% savings)
- Bayesian Mode Selection — learns optimal mode per file type over time
- BPE Entropy — entropy filtering uses LLM tokenizer for precision
- Cross-File Dedup —
ctx_dedupwithaction=applyreplaces shared blocks with references - Boltzmann Cache — evicts least-valuable entries when token budget exceeded
- LITM Profiles — context positioned optimally per LLM model (Claude/GPT/Gemini)
Session Management
ctx_compressat >10 turns — creates memory checkpointctx_metrics— hard numbers on what was savedctx_benchmark— find optimal mode for a filectx_session load— on new chat, restore previous sessionctx_dedup— analyze or apply cross-file deduplication
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 12d ago Changed ec44e4751380
- 1mo ago First seen · 100 lines · 969 tokens per session scan A d0ca03df266e
lean-ctx is a cursor rule published in the GitHub repository yvgude/lean-ctx (3,879 stars, last pushed yesterday), licensed Apache-2.0. It adds 969 tokens to every session, about $0.0039 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other cursor rules, from other repositories
greedy-token
Greedy token — MCP greedy-token before Grep/Shell.
alembic-migrations
To add a non-nullable column and set a specific value for all existing rows without a persistent server default.
nauro-ship-task
Run the full planner -> executor -> reviewer -> tech-lead -> direct-user-confirm -> push chain through Cursor's native project workflow agents. Requires the four bundled .cursor/agents/nauro-.md definitions and fails closed without native dispatch.
roslyn-mcp-overview
RoslynMcpServer — architecture, layout, version, DI.
roslyn-mcp-pitfalls
Known pitfalls and regression lessons from production use.
roslyn-mcp-docs-agents
Docs sync AGENTS/README, agent conventions, PowerShell, secrets.