Disclosure: I'm the author of leanprompt, the free, Apache-2.0 tool I used for this. There's no paid version, no hosted service, no account.
Every LLM call resends the system prompt, the tool list and the history. Providers cache the part that didn't change, but only if it didn't change byte for byte, from the first token. I ran audits on open-source LLM apps (gpt-researcher, anything-llm, bilingual_book_maker, better-chatbot and others) and kept seeing the same few mistakes.
- Something volatile at the top of the prompt.
- A timestamp to the second on the first line of the system prompt means no call can ever reuse what follows it. In our example app that was an estimated 6.7M tokens per 1,000 calls the cache could have served.
- A history window that shifts every turn.
- Trimming the oldest message each turn changes the prefix, so every turn re-reads the whole conversation.
- No cache marks on Anthropic.
- Anthropic caches only where the client asks. On replayed coding-agent sessions, a client sending no marks got 0 tokens from cache over 29 turns. A client sending 3 marks got 92% of prompt tokens from cache on a single session.
- Caching that's off by default in a gateway.
- One app's default model ran through a gateway where caching has to be switched on explicitly.
- Cost meters that ignore cache fields.
- 3 of the first 4 apps metered their own spend from `input_tokens` and never read the cached-token fields, so their dashboards were wrong in either direction.
- Paying twice for output.
- Retrying a truncated answer from scratch, or sending a batch that the limit cuts off, re-buys tokens you already paid for. One of these fixes was merged upstream (bilingual_book_maker #590).
And one that went the other way. Moving the date to the end of the prompt, to protect the cache, cut correct date answers from 10/12 to 1/12 and didn't help the cache. So the rule isn't "move everything dynamic down"; meaning comes first, then cache.
Two smaller things: on a hybrid-thinking model, toggling thinking on and off between turns lost 47% of the reusable prefix. Tools built from an unsorted dict also change order between calls.
How it works: leanprompt is a set of skills for your coding agent (Claude Code, Codex, Cursor, OpenCode, anything that reads AGENTS.md). `/leanprompt audit` finds every LLM call in your app and ranks where it loses tokens. `fix` shows a diff and applies it on your yes. `measure` proves the change with a before-and-after number. The audit numbers are estimates from reading the code; `measure` is what turns them into measurements. Every figure in this post has a row in the evidence table with its source and limits.
npx leanprompt install
Repo: https://github.com/Podwarden/leanprompt
Audit logs - what we found in multi-star github projects: https://lmwarden.com/leanprompt/audits/
What I'm asking for: feedback. The rules are the part that matters, and they only get better from cases I haven't seen. The skills, rules and provider tables are CC BY 4.0, so whatever you teach them goes back to everyone who uses them, with credit if you want it. Most useful:
- a rule that's wrong or missing for your provider or engine (self-hosted vLLM or SGLang, Gemini, Bedrock, OpenRouter...)
- a finding that turned out to be a false positive on your code
- a cache or cost mistake you've hit that isn't on this list
- an audit that missed an LLM call, or ranked a small problem above a big one
Reply here, open an issue, or use the "lesson learned" form in the repo. It's fine in general terms, without sharing your code. Every report I can verify becomes a rule or a fix to one.