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.
npx agentmods add rules/yvgude/lean-ctx/lean-ctx-session-metricsgit 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-session-metrics)<a href="https://agentmods.dev/rules/yvgude/lean-ctx/lean-ctx-session-metrics"><img src="https://agentmods.dev/badge/rules/yvgude/lean-ctx/lean-ctx-session-metrics.svg" alt="Measured on agentmods" 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 | $0.00388 | $0.00388 |
| Opus 5 | $0.00194 | $0.00194 |
| Sonnet 5 | $0.00078 | $0.00078 |
| Haiku 4.5 | $0.00039 | $0.00039 |
Grade A, and why
lean-ctx-session-metrics 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 5d 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.
What it actually says
End of reply — LeanCTX metrics block
On every substantive reply (when you have addressed the user’s request—not for a bare “ok” or empty confirmation):
- Call the MCP tool
ctx_metricsonce (no arguments). That is the only allowed source for the footer numbers. - In the very last paragraph, after everything else in your reply, add exactly this structure (fill in values returned by
ctx_metrics; copy the numbers as given):
LeanCTX — MCP session (lean-ctx tools only)
| Tokens (tool-side input) | |
|---|---|
| Without lean-ctx (cumulative “original” volume from calls) | (“original” value / first column of the Input tokens line) |
| With lean-ctx (actually sent after compression) | (“sent” value) |
| Saved | (difference / “saved”) + percentage if shown |
(If the output includes a “Cost estimate” line, you may copy it verbatim below the table.)
Limits (do not over-interpret)
- These figures only cover tool calls tracked by the lean-ctx MCP server during this session, not total Cursor token usage (prompt, reasoning, model reply, non-lean-ctx tools).
- If you did not use any lean-ctx tool during the exchange,
ctx_metricsmay show 0 or little change: say so in one sentence instead of inventing savings.
If ctx_metrics is unavailable or empty
Write a single line: “LeanCTX: MCP metrics unavailable for this session.” — do not invent token comparisons.
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.
- 5d ago First seen · 36 lines · 388 tokens per session scan A 20df926870b8
lean-ctx-session-metrics is a cursor rule published in the GitHub repository yvgude/lean-ctx (3,696 stars, last pushed 2d ago), licensed Apache-2.0. It adds 388 tokens to every session, about $0.0019 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.
pytest-integration-tests
Below is an example test. Notice the following.
nauro-context
Writes durable shared context into Nauro's project store so other agents (a later session or a parallel one) can discover and pull it, finds and reads context another agent left, or captures a resumable brief so your own next session in this environment picks up cleanly. Three modes. Author writes a shared brief for…
python-app
Cursor rule "python-app" from iloveitaly/llm-ide-rules, covering python app, factories and database & orm.
react
Cursor rule "react" from iloveitaly/llm-ide-rules, covering react, mock data, react hook form and styling.
alembic-migrations
To add a non-nullable column and set a specific value for all existing rows without a persistent server default.