Skip to content
Agentmart
Submit a tool

Cursor rules · yvgude/lean-ctx

1 Cursor rule file from yvgude/lean-ctx: compression-safety.

Template by yvgude

IndexedApache-2.0★ 3,896
Write a review

Install

Works with Cursor. Read the repository before you give any tool access to your data.

curl -fsSL https://raw.githubusercontent.com/yvgude/lean-ctx/main/.cursor/rules -o rules

Read it and adapt it to your project before use.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

The .cursor/rules folder of yvgude/lean-ctx (3,896 stars): 1 rule files, 48 lines in all (compression-safety).

Use cases: code-generation

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

What's in it

Cursor project rules (.cursor/rules/*.mdc): instructions Cursor applies when it edits matching files.

For
Cursor
File
.cursor/rules/compression-safety.mdc

First lines (shown under the repo's Apache-2.0 license)

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

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

### File restoration commands

Always use `LEAN_CTX_DISABLED=1` when restoring files from git:

```bash
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

Signals

Stars
3,896
Forks
356
Open issues
9
Last commit (this folder)
Jul 28, 2026 (3 months ago)
Last release
Oct 11, 2026 (17 days ago)

From GitHub (fetched Oct 24, 2026).

Details

License
Apache-2.0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from yvgude

Cite this page

Cursor rules · yvgude/lean-ctx. Agent Mart. https://agentmart.dev/templates/yvgude-lean-ctx-cursor-rules (last updated 2026-10-24)