How we cut coding-agent tokens without breaking the prompt cache
Originally published at ReclaimLLM. How ReclaimLLM's prompt-cache-aware routing saves tokens and keeps coding agents fast. Coding agents burn tokens fast. A single task can produce 100,000+ tokens in prompts, tool call
Originally published at ReclaimLLM.
How ReclaimLLM's prompt-cache-aware routing saves tokens and keeps coding agents fast.
Coding agents burn tokens fast. A single task can produce 100,000+ tokens in prompts, tool calls, and repeated context. At that scale, small prompt changes create large cost differences. The biggest lever is not model price. It is cache hits. When a prompt prefix repeats, providers reuse cached tokens at a fraction of the price. But many teams break the cache by accident, with small dynamic changes at the start of every prompt. This post explains how ReclaimLLM routes requests to protect the cache, and what your team can change to cut token costs without slowing agents down.
Why the prompt cache matters
Most frontier providers cache prompt prefixes. If your prompt starts with the same tokens as the previous request, those tokens are read from cache at a steep discount. For coding agents, this matters because each turn usually re-sends the same system prompt, instructions, and file context. A cache hit can cut input costs by 80-90% for those repeated tokens. A cache miss means paying full price for every token, every turn. The difference is not small. For a team running hundreds of agent sessions per day, a broken cache can add thousands of dollars per month.
What breaks the cache
Cache invalidation usually comes from small, avoidable changes. Common causes include:
- Dynamic timestamps or request IDs at the start of the prompt
- User-specific data injected before the stable system prompt
- Tool outputs inserted before the cached prefix
- Per-request variations in formatting or whitespace
- Rotating model versions or providers mid-conversation
Each of these forces the provider to treat the prompt as new, even when 95% of the content is identical. The fix is to keep the stable prefix stable.
How ReclaimLLM protects the cache
ReclaimLLM sits between your coding agents and the model providers. It normalizes prompts before they reach the provider, so cacheable prefixes stay intact. In practice, that means:
- Stable ordering: System instructions and file context are sent first, in a consistent order, before any dynamic content.
- Dynamic content last: Timestamps, request IDs, and user-specific values are moved to the end of the prompt, where they cannot invalidate the cached prefix.
- Provider-aware routing: Requests are routed to the provider and model version that already holds the cached prefix, instead of spreading identical prompts across providers.
- Version pinning: Model versions are pinned per conversation, so a mid-conversation upgrade does not reset the cache.
These steps are transparent to the agent. Your code does not need to change.
What we measured
On a representative coding-agent workload, we compared token costs with and without cache-aware routing:
- Without cache protection: 100% of input tokens were billed at full price.
- With cache-aware routing: 70-80% of input tokens were served from cache, at roughly 10% of the full price.
That translates to a 50-60% reduction in total input token costs, depending on conversation length and provider pricing. Output tokens are unchanged, because the model still generates the same response. The savings come entirely from not re-paying for context you already sent.
What your team can do
You do not need ReclaimLLM to improve your cache hit rate. Start with these changes:
- Move dynamic values to the end: Keep timestamps, IDs, and user data after the stable system prompt and file context.
- Pin model versions per conversation: Do not upgrade the model mid-task.
- Keep formatting consistent: Avoid reformatting the same context on every turn.
- Batch similar requests: When possible, send related requests to the same provider and model.
- Measure cache hits: Most providers report cached vs. uncached tokens. Track that ratio, and treat a drop as a bug.
ReclaimLLM automates these steps, but the principles apply to any setup.
The bottom line
Coding-agent costs are mostly a caching problem. If your prompts repeat, your cache should hit. When it does not, you are paying to re-send the same context on every turn. Protect the prefix, keep dynamic content at the end, and route consistently. Your token bill will show the difference.
Originally published at ReclaimLLM.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.