LeanCTX Cuts AI Coding Agent Token Costs by 90% as Open-Source Middleware
LeanCTX is a single Rust binary that sits between AI coding agents and your files, cutting token usage 60-90% via smart compression and caching.
Takeaways
- LeanCTX is an open-source Rust binary that cuts token usage 60-90% for AI coding agents via MCP
- Cached file re-reads drop from ~2000 to ~13 tokens using 10 read modes and tree-sitter AST
- Ships 77 MCP tools, 95+ shell compression patterns, and supports 30+ agents including Cursor and Claude Code
- Session memory and a property graph persist task state and enable impact analysis across chats
- Includes Python/JS/Rust SDKs with a drop-in compress() for any chat-completion pipeline
- Apache 2.0, local-first, no telemetry by default, with a signed SHA-256 savings ledger for verification
A new open-source tool called LeanCTX is picking up traction as a middleware layer for AI coding agents, targeting one of the messiest problems in agentic workflows: the sheer volume of tokens burned re-reading the same files, running verbose shell commands, and re-explaining the project after every context reset. It runs as a single local Rust binary between your agents and your code, shell, and data, and claims 60 to 90 percent token reduction as a side effect of smarter context routing.
The four-token problem it attacks
When agents like Cursor, Claude Code, or Codex work on a real repo, they re-read files constantly, spew raw git status and npm output into the window, and lose the plot between chats. LeanCTX quantifies that waste concretely: repeated file reads cost around 2000 tokens each versus about 13 tokens for cached re-reads, and raw git status runs about 800 tokens compressed down to roughly 120.
The tool is organized around four responsibilities:
- Compression of file reads and shell output
- Routing to the right fidelity per read (full text vs. AST signatures vs. diffs)
- Memory that persists task state and facts across chats
- Verification with a signed savings ledger and budget dashboard