lean-ctx: what it is, what problem it solves & why it's gaining traction
lean-ctx: what it is, what problem it solves & why it's gaining traction
What it solves
LeanCTX is a context engineering layer designed to reduce token waste and API costs for AI agents. It prevents agents from repeatedly reading the same files or sending redundant data to the model, which often leads to context window exhaustion and higher expenses. It also solves the the problem of "cold starts" where AI agents lose their memory and state between different chat sessions.
How it works
LeanCTX operates as a local Rust binary that sits between AI agents and their environment (code, shell, and the model). It manages context across two primary paths:
- Read Path: It uses an MCP server and shell hooks to compress file reads (using 10 different modes like
maporsignatures) and shell output (compressing patterns from git, npm, etc.) before the agent sees them. - Wire Path: An optional local proxy compresses every request sent to the model—including system prompts and history—while remaining prompt-cache-safe.
It utilizes a Tree-sitter AST for structural understanding of 18 languages and a multi-edge property graph to power impact analysis and search ranking. All compression is reversible, meaning the model can retrieve original bytes via content-addressed storage.
Who it’s for
Developers using AI agents such as Cursor, Claude Code, Copilot, Windsurf, and Gemini who want to lower their API costs, extend their coding sessions, and maintain persistent memory across chats.
Highlights
- Token Reduction: Claims 60–90% fewer tokens on reads and shell output.
- Reversible Compression: Pruned content is stored locally and can be pulled back by the model on demand.
- Persistent Memory: Session memory and a knowledge graph allow facts and decisions to persist across different chat sessions.
- Zero Config Onboarding: A single
lean-ctx onboardcommand auto-detects and configures most popular AI tools. - Observability: Includes a browser dashboard for real-time token tracking and a verifiable savings ledger.
- Multi-Agent Support: Provides tools for agent handoffs and shared state management.
Sources
- undefinedyvgude/lean-ctx