ByteCosts
lean-ctx-review.mdx

AI Coding Agents

lean-ctx Review: A Context Gateway Whose Savings Failed Its Own Dashboard

lean-ctx (LeanCTX) is a Rust context gateway that sits between your coding agent and the data it reads: shell hooks compress command output, an MCP server offers cached file reads, and an optional proxy rewrites requests on the wire. In tokbench’s independent pilot (N=1 per arm), the lean-ctx MCP arm billed 38% more input tokens than the native arm, while lean-ctx’s dashboard reported zero tokens saved.

lean-ctx (the project styles itself LeanCTX) is a Rust context gateway that sits between your coding agent and the data it reads: shell hooks compress command output, an MCP server offers cached file reads and search, and an optional proxy rewrites requests on the wire. In tokbench’s independent pilot (N=1 per arm), the lean-ctx MCP arm billed 38% more input tokens than the native arm, while lean-ctx’s dashboard reported zero tokens saved. Whether it is worth installing depends on which of its four jobs you need.

What it is and which cost layer it targets

lean-ctx, published as yvgude/lean-ctx, calls itself a Context Gateway for AI systems. As of November 30, 2026 it had 3,968 stars and 363 forks on GitHub, with 14 open issues and an Apache-2.0 license. The repository was created in March 2026. Its latest listed release, v3.12.8, shipped on November 27, 2026.

The README organizes the product into four verbs: Select, Control, Learn and Prove. Mapped onto cost layers, that is:

  • Input tool output: shell hooks rewrite the output of git, npm, cargo, docker, kubectl, terraform and others, with the README claiming 85+ compression patterns and 250+ passthrough rules.
  • File reads: sixteen read modes (auto, full, map, signatures, diff, aggressive, entropy, task, reference, lines:N-M, plus variants like density:X and anchored), where eligible cached re-reads return a short reference instead of the content.
  • Wire-level history: an opt-in local proxy (lean-ctx proxy enable) can transform eligible prompt, history and tool-result content on supported requests.
  • Memory: session records, a knowledge graph and a multi-edge code property graph persist across chats.
  • Behavior and audit: PathJail filesystem scoping, content filters, context budgets, and a recorded evidence trail (ctx_proof, ctx_verify, the Cockpit dashboard).

That is a much wider remit than a compressor. lean-ctx wants to be the layer through which everything your agent reads passes.

How it works

The architecture runs on two planes, which the README calls the read path and the wire path:

read path:   AI tool  →  (MCP tools + shell)  →  lean-ctx  →  your repo + CLI
wire path:   AI tool  →  lean-ctx proxy        →  model provider

On the read path, an MCP server exposes ctx_* tools: ctx_read with its sixteen modes, ctx_shell, ctx_grep, ctx_find, ctx_ls, plus search, knowledge, graph and expansion tools. Tree-sitter AST parsing covers 27 languages, so map and signatures modes return structural views rather than chopped text. A density:0.4 mode keeps the highest-entropy lines until about 40% of the tokens remain, deterministic. Compact views keep source references so the original can be recovered through ctx_expand.

Two ideas carry the savings claim. First, the cached re-read: the README’s own demo advertises a map-mode re-read at roughly 13 tokens. Second, JIT disclosure: signatures returns an outline with line spans, and the agent pulls bodies on demand with lines:N-M.

On the wire path, the proxy is opt-in and narrower. The README notes that provider-specific effort mapping, verbosity controls and volatile-prefix handling have their own compatibility limits, and that recovery requires retained, authorized artifacts. For Claude Code specifically, lean-ctx wrap claude adds no proxy redirect at all when you are on a subscription: OAuth cannot use a custom ANTHROPIC_BASE_URL, so Claude Code users get the ctx_* tools and shell compression but no wire-level compression unless they use an API key.

The savings meter is also local. lean-ctx gain, lean-ctx savings and the Cockpit browser view track recorded calls, token estimates and calculated cost. Shadow Mode simulates what the same work would have cost without lean-ctx from uncompressed token counts; the README is careful to call this a simulated baseline, not a measured one.

Install and first run

The README offers four install routes. The universal one pipes a script from the project’s site, so read it before running it:

curl -fsSL https://leanctx.com/install.sh | sh      # universal (no Rust needed)
brew tap yvgude/lean-ctx && brew install lean-ctx    # macOS / Linux
npm install -g lean-ctx-bin                          # Node.js
cargo install lean-ctx                               # Rust

Setup for a supported agent is one command, and removal is symmetric:

lean-ctx wrap cursor      # or: wrap claude / wrap codex
lean-ctx unwrap cursor    # undo
lean-ctx cockpit          # local dashboard: Savings · Spend · Report · Proof
lean-ctx gain --terminal  # same numbers in the terminal

lean-ctx-off disables it for the current shell, lean-ctx -c --raw "git status" runs one command uncompressed, and shell_activation = "agents-only" in ~/.config/lean-ctx/config.toml restricts hooks to agent sessions. The compatibility matrix lists hybrid setup (MCP plus shell hooks) for more than twenty agents including Cursor, Claude Code, Codex and Gemini CLI, and MCP-only setup for another ten including Zed, JetBrains IDEs and VS Code.

What it saves: claims vs the independent result

The README’s marketing line, “Less context. More intelligence,” is explicitly hedged inside the README itself: “a stance, not a measured quality or savings promise, until a published cost-per-accepted-outcome (CPAO) study exists.” The compression numbers it does give, such as the ~13-token re-read, are per-feature demonstrations, and tokbench records the vendor-facing claim as “60–99% compression, ~13-token re-reads.”

The independent tokbench study (Entelligentsia/tokbench) includes a pilot with N=1 per arm and a 14-run replication matrix with three runs per middleware arm. The workload is a bug fix driven through an eight-phase SDLC pipeline on a request-metered provider. These are the pilot input totals.

lean-ctx configurationBilled input tokensvs native
native (no middleware)2.28M (pilot run)baseline
lean-ctx 3.7, MCP bridge config3.14M+38%
lean-ctx 3.7, as-shipped default3.62M+59%

In the 14-run matrix, the lean-ctx arm’s median billed input was +38.1% against the native median (native runs ranged 1,894,592 to 2,705,356 tokens, median 2,183,153). In the N=1-per-arm pilot, model time per turn was 2.8 seconds for native, 4.2 seconds with the MCP configuration, and 6.8 seconds with the as-shipped default.

The detail that stings most is self-reported: lean-ctx’s own gain meter for the pilot MCP run read “0 tokens saved · 0.0% compression · $-0.001 USD saved.” Zero compression, negative dollars, by its own accounting. A later exploratory arm with maximum routing steering produced the meter’s first nonzero reading, 921 tokens saved, while the run still billed 14.5% over native.

The mechanism analysis explains why. On that harness the middleware-addressable surface (file reads plus shell output) measured about 26% of context; everything else was system prompts, history and harness tool traffic that lean-ctx cannot see. The harness also isolates every phase into a fresh agent process, and lean-ctx’s session cache lives in memory per server process, so the flagship ~13-token re-read never got a second read to serve: every repeat read was cross-phase, and each new phase started a cold cache. Additive mode, the shipped default, added fourteen ctx_ tool definitions plus rules to every prompt (the commit phase’s final context nearly doubled, 38k vs 19.9k tokens), voluntary adoption of ctx_shell ran at about 11% of shell calls, and model typos of ctx_ arguments created a new error class whose retries billed at full-context prices. Under the default CLI path the cached re-read was structurally unreachable because each ctx_read spawned a one-shot subprocess.

To the maintainer’s credit, the response was fast and concrete: the benchmark’s review request (issue #361) produced confirmed-bug fixes in 3.7.4 and 3.7.5 within hours, including routing ctx_read through the bridge session and turning the embedded bridge on by default. Even after every fix, the phase-isolation finding stood: on a harness that already removes cross-context redundancy architecturally, there is nothing left for the cache to serve.

Prompt-cache and extra-turn risk

Tool definitions and rules can add input on every turn. Rewriting requests can affect provider prompt caching. A failed ctx_* call can add another model turn. Measure its cost using the fresh input, cache reads, cache writes, and output your provider reports.

What the GitHub issues show

Fourteen open issues and a long closed-issue list paint a project moving fast and fixing things, with real friction in the newest areas:

  • Issue #2279: on Linux, a hung ctx_shell handler leaks a spinning blocking-pool thread per call; the title says the MCP server can peg CPU for hours after traffic stops. Open as of November 30, 2026.
  • Issue #2277: the hook rewrite skips cd X && prefixes, sed -n ranges and cat | head, so per the title most agent Bash output goes uncompressed. Open.
  • Issue #2276: the shell gate blocks git fetch/worktree/commit/push as “changes lean-ctx’s own state,” and lean-ctx allow git has no effect. Open.
  • Issue #313: PreToolUse rewrite/redirect hooks corrupted interleaved-thinking blocks, causing recurring 400 errors in Claude Code. Closed.
  • Issue #256: Claude Code’s ANTHROPIC_BASE_URL was left pointing at an unconfigured lean-ctx proxy, producing 401 auth failures. Closed.
  • Issue #160: a request to clarify telemetry claims in the README and add an opt-out for the version check. Closed.

The pattern: real engineering velocity (the tokbench fixes shipped within hours of filing) alongside sharp edges in hook coverage, the shell gate and the newest subsystems.

A cost example (estimate)

For an input-only estimate, price the rounded counts from tokbench’s pilot (N=1 per arm) at Sonnet’s $2 per million fresh input tokens. See the AI provider pricing index for current rates.

  • Native: 2.28 million × $2 per million = $4.56
  • MCP configuration: 3.14 million × $2 per million = $6.28
  • As-shipped default: 3.62 million × $2 per million = $7.24

The pilot used GLM models on a request-metered provider. These estimates apply fresh Sonnet rates uniformly to illustrate the effect of the input counts.

Who should use it, who should skip it

Try it if you:

  • Run shell-heavy agent sessions (git, tests, builds) in medium or large repositories, which is exactly the profile the README names as a good fit
  • Want the non-compression features: PathJail access scoping, session memory, the knowledge graph, or the audit/proof trail, where the value proposition does not depend on the compression ratio
  • Are willing to measure: install it, run lean-ctx gain, and reconcile its numbers against provider-reported usage before trusting the dashboard

Skip it if you:

  • Work in small repos where the compressible surface is a minor share of context
  • Already run a context-frugal harness (fresh context per task, compact governed tools): the addressable surface for middleware may be near zero
  • Use Claude Code on a subscription and only wanted wire-level compression, which the OAuth path cannot do anyway

How to trial it safely

  1. Record a baseline week: provider-billed input tokens and cost for your normal sessions before installing anything.
  2. Install for one agent only (lean-ctx wrap <agent>), keep the default config, and work normally for a comparable week.
  3. Compare provider-billed totals with lean-ctx gain. The two diverged in the tokbench pilot (N=1 per arm).
  4. If the bill went up, try the MCP/hybrid path rather than CLI defaults, and check lean-ctx doctor --json for wiring problems before concluding.
  5. Remove it with lean-ctx unwrap <agent> if it does not pay.

The full measurement protocol is in how to measure coding agent token savings.

Alternatives and next reads

Sources

How this note was produced

Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.

lean-ctx Review: A Context Gateway Whose Savings Failed Its Own Dashboard. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/lean-ctx-review/

Sources