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.
npx agentmods add rules/yvgude/lean-ctx/lean-ctxgit clone --depth 1 https://github.com/yvgude/lean-ctxWhat 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 | $0.00969 | $0.00969 |
| Opus 5 | $0.00485 | $0.00485 |
| Sonnet 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 yesterday.
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, 6 compression modes, re-reads cost ~13 tokens |
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
Re-reads cost ~13 tokens. 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 → just call
fullagain (cache returns ~13 tokens)
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.
- yesterday 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,681 stars, last pushed yesterday), licensed Apache-2.0. It adds 969 tokens to every session, about $0.0048 per session on Opus 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.
codesynapse-cli
Use this rule to answer codebase architecture questions, trace dependencies, find callers/callees, calculate blast radius, and explore the code graph. Triggers on: "how does X work", "what handles Y", "where is Z defined", "explain the mechanism", "who calls", "blast radius", "shortest path", "trace request flow"…
cursor
You are working on the checkout service. Preserve transaction integrity and auditability.
beanstalk-deploy
Robust deployment patterns for Elastic Beanstalk with GitHub Actions, Pulumi, and edge case handling.
archcore-files
Enforce MCP-only operations when working with .archcore/ files.
dev_workflow
Guide for using Taskmaster to manage task-driven development workflows.