lean-ctx for Lower AI Token Usage
At work I hit 100% of quota and had to find a way to cut usage without slowing down. I started using lean-ctx — a context layer that sits between AI coding tool and the codebase.
Instead of sending raw file contents and full shell output straight to the model, lean-ctx intercepts those reads and commands, compresses them, and caches repeats.It uses MCP server for that and prompt in Agents.md to use its tools instead of default ones. File reads go through MCP tools like ctx_read and ctx_search. Terminal output gets compressed via shell hooks. Re-reading a cached file costs far fewer tokens than sending the whole file again.
After 7 days (since 2026-05-18), the stats looked like this:

- 7.2M tokens saved across 2,466 commands (~80% compression)
- Most savings came from MCP tools (
ctx_read,ctx_search); shell hooks added another chunk - Estimated $19.42 saved on input/output token costs. Not sure how correct the pricing calculations though :)
Not a magic fix, but worth trying if you are burning through tokens on file reads and long command output.
In May, it did not help me much — GitHub Copilot limits were based on request quotas, not tokens. That changed in June when Microsoft switched to token-based quotas, and lean-ctx became much more useful.