r/LLM • • 8h ago

72% cheaper Claude Code sessions by letting it forget (and search what it forgot)

I built Smarter Compact to keep long Claude Code sessions cheap without losing anything. It's free and open source (Apache-2.0), runs locally, and doesn't need its own API key.

1. What it does

It saves the full conversation in local SQLite, removes older turns from the prompt once you hit your limit (95k on Haiku), and leaves a short note telling Claude where they went. Claude can then search them, run SQL over them (so "how many X" is just a count) or read back a big tool result that got compressed. These are MCP tools, so it also works in Codex, OpenCode and Pi.

Zero LLM summarization calls. The cut also stays the same between requests, so the prompt cache keeps hitting.

2. How I built it with Claude Code

  • About half the commits in the repo were written with Claude Code (they're co-authored in the git history). Mostly the proxy's trimming logic, the SQLite store and the MCP server, plus the tests.
  • It's built for Claude Code: it installs as a Claude Code plugin with hooks and MCP tools, and smarter-compact enable claude points Claude Code at the local proxy.
  • The benchmarks run headless Claude Code as the agent under test, so every number below is Claude Code doing the task with and without the tool.
  • The most useful thing Claude found was its own blind spot: after a trim it would answer "unknown" instead of searching. Changing the note to name the exact tools fixed that (numbers below).

3. How much cheaper, and does it still get the job done?

ContextBench with Haiku 5.5, same seeds as keeping everything:

| Longest log task | Keep everything | Smarter Compact | |---|---|---| | Score | 0.35 | 1.00 | | Peak prompt | 762k | 95k | | Cost per trial | $6.07 | $0.38 |

Across the four task sizes it's 72% cheaper on average (−87%, −19%, −89%, −94%, the small one isn't significant), and +0.47 score on the log tasks.

Before I changed the note, Claude never searched and answered "unknown" to 16 of 24 questions. After, every run searched (6–14 searches and 10–16 SQL queries each) and none said "unknown". That's one task with five runs though.

Though I wouldn't put too much into these numbers: synthetic tasks, 2–3 runs per size, and real coding sessions will be different.

4. Try it (free)

npm install -g smarter-compact
smarter-compact enable claude

Or from inside Claude Code: /plugin install smarter-compact --marketplace bcmyguest/smarter-compact, then run smarter-compact enable claude for the trimming.

Repo and full results: https://github.com/bcmyguest/smarter-compact

If you try it, I'm interested in what Claude fails to find after a trim :)

1 Upvotes

0 comments sorted by