lean-ctx-session-metrics

lean-ctx-session-metrics is a cursor rule for coding agents from yvgude/lean-ctx. It costs 388 tokens per session, scanned A, original, Apache-2.0.

A reply rule that reports how many tokens the lean-ctx MCP service received and how many it saved through compression. MCP is a way for an agent to call connected tools.

In plain words
What is it for?
Adding the required lean-ctx metrics call and token-savings footer to agent replies.
Why use it?
It adds a consistent usage summary to substantive replies, so you can see the effect of lean-ctx during the session.

Cursor rule

About the project

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.

yvgude/lean-ctx · 3,696 stars · on GitHub

Install

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.

agentmods
npx agentmods add rules/yvgude/lean-ctx/lean-ctx-session-metrics
Clone the repo
git clone --depth 1 https://github.com/yvgude/lean-ctx

Wrote 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.

agentmods badge for lean-ctx-session-metrics

README.md
[![agentmods](https://agentmods.dev/badge/rules/yvgude/lean-ctx/lean-ctx-session-metrics.svg)](https://agentmods.dev/rules/yvgude/lean-ctx/lean-ctx-session-metrics)
Your own site
<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>
Per session 388 This file is loaded in full into every session.
When invoked 388 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce 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

Measured 5d ago against content hash 20df926870b8, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

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.

rust/examples/lean-ctx-session-metrics.mdc · 36 lines

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):

  1. Call the MCP tool ctx_metrics once (no arguments). That is the only allowed source for the footer numbers.
  2. 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_metrics may 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.

Changes

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.

  1. 5d ago First seen · 36 lines · 388 tokens per session scan A 20df926870b8

Subscribe to this mod's changes

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.