compression-safety

compression-safety is a cursor rule for Cursor from yvgude/lean-ctx. It costs 399 tokens per session, scanned A, original, Apache-2.0.

A safety rule for agents working with a tool that shortens file contents when displaying them. It explains how to avoid saving those shortened markers instead of the original code.

In plain words
What is it for?
Use it when editing files in repositories that use lean-ctx compression, especially after a file unexpectedly becomes shorter or contains a marker such as '[lean-ctx: omitted'.
Why use it?
It helps prevent silent file corruption during edits and explains how to restore affected files safely from Git.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when editing files in repositories that use lean-ctx compression, especially after a file unexpectedly becomes shorter or contains a marker such as '[lean-ctx: omitted'.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/yvgude/lean-ctx/compression-safety
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,882 stars · on GitHub · leanctx.com

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.

Clone the repo
git clone --depth 1 https://github.com/yvgude/lean-ctx

Made for: Cursor.

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 compression-safety

README.md
[![agentmods](https://agentmods.dev/badge/rules/yvgude/lean-ctx/compression-safety/github.svg)](https://agentmods.dev/rules/yvgude/lean-ctx/compression-safety)
Your own site
<a href="https://agentmods.dev/rules/yvgude/lean-ctx/compression-safety"><img src="https://agentmods.dev/badge/rules/yvgude/lean-ctx/compression-safety/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.

agentmods 80×15 button for compression-safety

Your own site · 80×15
<a href="https://agentmods.dev/rules/yvgude/lean-ctx/compression-safety"><img src="https://agentmods.dev/badge/rules/yvgude/lean-ctx/compression-safety.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 399 This file is loaded in full into every session.
When invoked 399 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00399 $0.00399
Opus 5.5 $0.00160 $0.00160
Sonnet 5.5 $0.00080 $0.00080
Haiku 4.5 $0.00040 $0.00040

Measured 1mo ago against content hash bdd0c6cff805, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

compression-safety 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 1mo 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.

.cursor/rules/compression-safety.mdc · 48 lines

What it actually says

Compression Safety — Prevent lean-ctx Marker Corruption

The problem

lean-ctx shadow-mode hooks compress file reads. If an edit tool (StrReplace, Write) reads through the hook, it sees compressed content and writes markers like [lean-ctx: omitted N lines] back to disk. This silently destroys file content.

Rules for ALL agents

Never write compressed content to files

The pre-commit hook blocks commits containing [lean-ctx: omitted markers. If your commit is blocked, the file was corrupted. Fix:

LEAN_CTX_DISABLED=1 git restore --source=HEAD -- <file>

File restoration commands

Always use LEAN_CTX_DISABLED=1 when restoring files from git:

LEAN_CTX_DISABLED=1 git restore --source=<commit> -- <file>
LEAN_CTX_DISABLED=1 git checkout <commit> -- <file>

NEVER use git show commit:file > file — the shell redirect writes compressed output.

When StrReplace produces unexpected results

If a file shrinks after StrReplace or contains [lean-ctx: text:

  1. LEAN_CTX_DISABLED=1 git restore --source=HEAD -- <file>
  2. Use LEAN_CTX_DISABLED=1 sed -i '' 's/old/new/g' <file> for the edit
  3. Verify: wc -l + rg '[lean-ctx:' <file> must show 0

Environment variable: LEAN_CTX_DISABLED

Set LEAN_CTX_DISABLED=1 to bypass ALL lean-ctx compression for a command. This is the escape hatch for any compression-related issue.

NEVER do

  • Pipe git show output to a file without LEAN_CTX_DISABLED=1
  • Trust wc -l output that's significantly lower than expected
  • Commit files containing [lean-ctx: omitted or --- lean-ctx: text
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. 1mo ago First seen · 48 lines · 399 tokens per session scan A bdd0c6cff805

Subscribe to this mod's changes

compression-safety is a cursor rule published in the GitHub repository yvgude/lean-ctx (3,882 stars, last pushed today), licensed Apache-2.0. It adds 399 tokens to every session, about $0.0016 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.

Related

Other cursor rules, from other repositories