Lean Context Intelligence

Control what
your AI can see.

One local binary between your agents and your code, shell and data. It decides what they read, remembers what they learn, guards what they touch, and signs the proof.

60–90% fewer tokens. And that's just the receipt.

Open source · Local-first · Zero telemetry · One Rust binary · 30+ AI tools

115,633 installs
2,705 GitHub stars
1.8 MWh saved energy
lean-ctx session
$ lean-ctx read src/lib/auth.ts -m map
exports: authenticate(), validateToken(), refreshSession()
4,200 → 920 tokens (78% saved)
cached: 13 tokens on re-read
$ lean-ctx grep "authenticate" src/
3 matches in 0.8ms
auth.ts:14, middleware.ts:8, routes.ts:23
$ lean-ctx -c "cargo build --release"
Compiling LeanCTX in 3.2s
compressed: 847 → 42 tokens
savings ledger: signed ✓

A 2,000-token file. Re-read for 13.

curl -fsSL https://leanctx.com/install.sh | sh
60–90% fewer tokens per read
~13 tokens per cached re-read
30+ AI tools, auto-detected
18 languages parsed via AST
01 What context intelligence means

Reads less. Remembers more. Proves it.

Four things change the moment LeanCTX sits between your agents and your code, shell and data.

Without LeanCTX, your agent… With LeanCTX… The receipt
reads everything reads what matters 60–90% less per read
forgets everything remembers across sessions re-reads cost ~13 tokens
touches anything touches only what's allowed PathJail · redaction · budgets
proves nothing proves every saving Ed25519-signed ledger

Compression makes context smaller. Intelligence makes it right. Five subsystems do the work; compression is one of them.

02 Why now

The agentic era has a context problem.

2026

Every developer runs coding agents. Token spend is a top-3 engineering cost.

2027

Fleets: 5–10 agents per developer (background, CI, review) talking to each other.

2028+

Agents in every department. Regulated, audited, budgeted.

More context makes models worse.

Context-rot research shows accuracy falling from 98% to 64% as noise fills the window. Trim the noise and accuracy climbs back. Cheaper is the side effect.

Every provider earns per token.

The layer that minimizes tokens can't come from the people who sell them. It has to sit on your side. This one does.

03 In → out

Stop feeding your agents noise.

Code, shell output, search results, web pages, documents: whatever your agents take in, LeanCTX turns into compact, model-ready context. Each kind gets its own strategy.

What your AI does What LeanCTX does What reaches the model Typical savings
Source file read AST signatures + delta-loading Function & type skeleton, bodies on demand 75–90%
Cached re-read Returns the cached delta, not the file ~13 tokens, regardless of file size ~95%
Shell output 95+ pattern modules (git, cargo, npm, docker…) Status + the lines that matter 70–90%
Code search BM25 + dense ranking, deduplicated Top hits with exact locations 60–85%
Directory scan Depth-limited structural map The tree, without the clutter 50–80%
API response Schema-aware field extraction Useful fields, not payload soup 60–90%
Scraped page Boilerplate stripped, deduplicated Clean, model-ready content 70–95%
PDFs & docs Extracted into facts and quotes Citation-backed essentials 80–95%

Never a dead end. Every original stays locally retrievable, one ctx_retrieve away. LeanCTX tells your AI exactly when to ask for it.

04 Live demo

Watch it decide.

The same file. Three intents. Three different views: exploring gets a map, API work gets signatures, editing gets full code. You don't pick the mode. The intelligence does.

src/lib/auth.ts
import { verify, sign } from 'jsonwebtoken';
import { Redis } from 'ioredis';

const redis = new Redis(process.env.REDIS_URL);
const JWT_SECRET = process.env.JWT_SECRET!;

export async function authenticate(token: string) {
  const payload = verify(token, JWT_SECRET);
  const session = await redis.get(`session:${payload.sub}`);
  if (!session) throw new Error('Session expired');
  return JSON.parse(session);
}

export function refreshSession(userId: string) {
  return sign({ sub: userId }, JWT_SECRET, { expiresIn: '1h' });
}
lean-ctx map mode
ctx_read output
exports: authenticate(token), refreshSession(userId)
deps: jsonwebtoken, ioredis
types: string → Promise<object>, string → string
lines: 17  size: 4,200 → 180 tokens
cached: 13 tokens on re-read
05 Benchmark

Same model. Fraction of the tokens.

Measured on real repo operations, reproducible end to end. Don't trust our numbers: run lean-ctx benchmark report . on your own repo.

Compression modes: tokens vs. information

40%50%60%70%80%90%100% 0%20%40%60%80%100% Tokens consumed % Information preserved % BEST ↗ full 100% tok · 100% info map 25% tok · 85% info auto 18% tok · 82% info entropy 12% tok · 72% info signatures 7% tok · 55% info aggressive 4% tok · 40% info

Where the savings come from

Source file → map mode -75%
3,000 tok
750 tok
Source file → auto mode -82%
3,000 tok
540 tok
Shell: git diff -75%
2,000 tok
500 tok
Shell: cargo test -88%
2,500 tok
300 tok
Typical session: ~10,500 → ~2,090 tokens 80% saved

Provable savings.

Every saving lands in an Ed25519-signed, hash-chained ledger on your machine. Export it for your CFO, or verify it against us.

How the ledger works
06 Universal

Built for every agent. Including yours.

30+ AI tools

Cursor, Claude Code, Codex, Copilot, Windsurf, Cline and more. Auto-detected, zero config per tool.

Any language

Embed it in your own agent via lean-ctx serve: a versioned /v1 API with Python, TypeScript and Rust SDKs.

Any domain

Context personas reshape the layer for coding, research, support or data analysis. Or define your own.

Any data

Universal intake: code, HTML, PDF, CSV, email, RSS, even YouTube transcripts, compressed into facts and quotes.

IDE & Editor

Cursor CLI-Redirect
VS Code MCP
Windsurf MCP
JetBrains MCP
Zed MCP
Sublime Text MCP
Emacs MCP
Neovim MCP
Continue MCP
Trae MCP

CLI Agent

Claude Code CLI-Redirect
GitHub Copilot MCP
Codex CLI CLI-Redirect
Gemini CLI CLI-Redirect
Cline MCP
Roo Code MCP
OpenCode MCP
Aider Shell Hook
Amp Shell Hook

Platform

Amazon Q MCP
AWS Kiro MCP
Antigravity MCP
Pi MCP
Qwen Code MCP
Verdent MCP
Hermes MCP
Crush MCP
07 Security

Local by default. Provable by design.

Everything runs on your machine. PathJail confines file access, the shell allowlist blocks dangerous commands, secrets are redacted before they reach the model. The audit trail records it all.

Local-firstZero telemetryPathJailShell allowlistSecret redactionAudit trail
Read the security model
09 FAQ

Questions, answered.

What is LeanCTX?

LeanCTX (short for Lean Context) is the open-source context intelligence layer for AI agents. One local Rust binary decides what your agents read, remembers what they learn, guards what they touch, and proves what they save in a signed ledger. It works with 30+ AI coding tools (Cursor, Claude Code, OpenAI Codex, GitHub Copilot and any MCP-capable client) and embeds in any agent via a versioned /v1 API.

Does compressing context hurt answer quality?

No. It usually improves it. Context-rot research shows model accuracy falling from 98% to 64% as windows fill with noise. LeanCTX removes redundancy while preserving meaning: AST-aware maps keep signatures and structure, shell patterns keep errors and results. Nothing is lost, either. Every original stays locally retrievable via ctx_retrieve.

How do I install it?

One command, then one setup. Install via the script, Homebrew, npm, or cargo and run `lean-ctx setup`. LeanCTX auto-detects your editors and wires up the right hooks and MCP server for each. Upgrades are a single `lean-ctx update`.

Is any of my code or data sent to a server?

No. Compression, caching, the savings ledger, and project memory all run locally on your machine; nothing is uploaded. The only network features (the Wrapped share card and the public leaderboard) are strictly opt-in and publish just an anonymous, whitelisted aggregate: a token count and a display name you choose.

Which AI tools does it work with?

30+ and growing: Cursor, Claude Code, OpenAI Codex, GitHub Copilot, Zed, Windsurf, Cline, Roo Code, Gemini CLI, OpenCode, JetBrains IDEs, and any MCP-capable client. Run lean-ctx setup once and every installed tool is auto-detected and configured.

What does LeanCTX stand for?

Lean Context. The name describes the job: lean, precise context for AI agents instead of raw, noisy input. LeanCTX is the brand and project name; lean-ctx is the binary, the package and the CLI command. (Not "Lean Cortex", a misspelling that appeared in early coverage.)

How is LeanCTX different from compression tools like Headroom?

Compression tools shrink what your agent has already read. LeanCTX works one layer deeper, at the source: it decides what gets read in the first place (10 read modes, ~13-token cached re-reads), remembers knowledge across sessions, guards file and shell access, and signs every saving in a verifiable ledger. Compression is one of its five subsystems. And it's fully reversible: every original stays one ctx_retrieve away.

The one-paragraph definition

LeanCTX (short for Lean Context) is the open-source context intelligence layer for AI agents. One local Rust binary decides what agents read (10 read modes, 60–90% fewer tokens, ~13-token cached re-reads), remembers what they learn (persistent sessions, knowledge graph), guards what they touch (PathJail, secret redaction, budgets, injection detection) and proves what they save (Ed25519-signed ledger, reproducible benchmark). Compression is one of five subsystems, and every original stays locally retrievable. Works with 30+ AI coding tools via MCP and shell hooks; embeds in any agent via a versioned /v1 API with Python, TypeScript and Rust SDKs. Local use is free forever, enforced by CI.

Read the full story

Take back control of your context.

Start by saving tokens. Stay because everything your agents learn, touch and save is finally under your control. Free for local use, forever. A CI gate makes sure it stays that way.