Claude Code with Open-Source Models: Why Cache Misses Happen and How to Fix Them

Why Claude Code cache misses happen with open-source models and how to fix them with proxy layers.
Claude Code's cache_control mechanism is tightly coupled to Anthropic's own API, so routing open-source models like DeepSeek or MiniMax through compatibility layers typically causes cache misses, multiplying API costs. This article explains the KV Cache mechanics behind Prompt Cache, why prefix stability is critical, and how protocol-translating proxy layers can map Anthropic cache semantics to each model's native caching system.
Why Developers Prefer Claude Code
As competition among AI coding assistants heats up, developers have never had more tools to choose from: OpenCode, Codex, Pi, Reasonix, OMP, and Anthropic's own Claude Code. Yet in practice, many developers report that Claude Code consistently delivers a superior interaction experience and deeper code comprehension.
Claude Code is Anthropic's command-line AI coding Agent. Its design philosophy fundamentally differs from IDE plugins like Copilot — it operates in the terminal, directly reading and writing to the filesystem, executing shell commands, and running Git operations. At its core, it's an autonomous Agent with codebase-level context awareness. This means every conversation requires stuffing large amounts of project context into each request, with single requests potentially consuming tens or even hundreds of thousands of tokens. Cache hit performance therefore has a far more dramatic impact on costs than in typical chat scenarios.
Recently, a Reddit user raised a highly representative question: after trying several AI coding Agents on the market, he concluded that Claude Code best fit his workflow. But when he tried connecting Claude Code to open-source or third-party models like DeepSeek, MiniMax, and MiMo, he ran into a frustrating technical obstacle — cache misses.
What seems like a minor detail is actually central to controlling LLM inference costs, and reflects a real challenge in the emerging trend of "unified Agent interface + multi-model backend."

What Is Prompt Cache and Why Does It Matter
The Value of Cache Hits
Prompt Cache refers to the mechanism by which model providers cache and reuse repeated context in requests — system prompts, codebase background, conversation history. AI coding scenarios depend on this heavily: every request carries large amounts of repeated content, such as project file structures, coding conventions, and previous conversation turns.
Technically, Prompt Cache is a server-side extension of the KV Cache (Key-Value Cache) mechanism in LLM inference architectures. In the Transformer architecture, each token generates corresponding Key and Value matrices during attention computation — these intermediate results can be cached and reused. When the prefix of a new request exactly matches a historical request, the server doesn't need to recompute those KV matrices and can read them directly from cache. OpenAI first introduced this mechanism in commercial form in late 2023, and Anthropic subsequently opened it up for fine-grained developer control in the Claude 3 series via an explicit cache_control field.
Once a cache hit occurs, repeated tokens require no recomputation, yielding two direct benefits:
- Dramatic cost reduction: Under Anthropic's official pricing, cached input tokens are typically billed at roughly one-tenth the rate of regular input tokens.
- Faster response times: Skipping redundant computation significantly reduces Time to First Token (TTFT).
Time to First Token (TTFT) is one of the core metrics for measuring LLM interaction experience — it measures the time from sending a request to receiving the first output token. The improvement from cache hits is significant: on a miss, the model must perform a full forward pass over the entire context (the prefill stage), with latency growing linearly with context length. On a hit, the prefill stage can skip already-cached portions, compressing TTFT from several seconds down to milliseconds. For developers accustomed to rapid iteration, this difference in response speed often affects workflow choices more directly than cost savings alone.
For developers who use AI coding tools frequently, the difference between a cache hit and miss can mean an API bill several times higher.
Why Open-Source Models Experience "Cache Failures"
Claude Code is natively optimized for Anthropic's own API protocol, and its cache_control marking mechanism is tightly coupled to Claude model backends on the server side. When developers route DeepSeek, MiniMax, or similar models through a compatibility layer, problems emerge:
Third-party model APIs typically use OpenAI-compatible formats, or have their own independent cache implementations. They either cannot recognize Anthropic-style cache control fields, or their cache granularity and trigger conditions don't align with what Claude Code expects — resulting in every request being treated as entirely new, rendering the cache completely ineffective.
Existing Solutions and Workarounds
Official Runtimes and Third-Party Extensions
One common approach is to use the model's official runtime harness or rely on third-party extensions. For example, MiniMax can be accessed through tools like Pi, enabling cache optimization within its native environment.
But the tradeoff is clear: developers are forced to switch between different tool interfaces for different models, unable to do all their work within their preferred Claude Code environment — directly at odds with the goal of having one reliable Agent for everything.
Protocol Translation via an API Proxy Layer
A more engineering-focused approach is to set up a proxy translation layer between Claude Code and open-source models. Several open-source community projects (such as various claude-code-router and anthropic-proxy tools) handle the following responsibilities:
- Receive Anthropic-format requests from Claude Code;
- Convert them to the format required by the target model (e.g., DeepSeek);
- During conversion, map Anthropic's
cache_controlfields to the corresponding cache parameters for the target model.
Building a reliable Anthropic-to-OpenAI protocol proxy is far more complex than it appears on the surface. Beyond basic field mapping (such as max_tokens vs. max_completion_tokens), the real challenges lie in handling differences in tool call (Tool Use/Function Calling) formats, streaming response (SSE) event format conversion, and most critically, cache semantics alignment. Anthropic's cache_control supports marking cache breakpoints at arbitrary positions in the message list, while the OpenAI-compatible format has no equivalent field. This requires the proxy layer to "understand" caching intent during conversion rather than simply discarding the field — otherwise, you end up with the complete cache failure described in this problem.
Step three is the key. Take DeepSeek as an example: its API uses a "context disk cache" mechanism — the server computes a hash of each request's prompt prefix and persists the corresponding KV Cache to high-speed storage. When subsequent requests produce a matching prefix hash, a cache hit occurs automatically, with no need to explicitly declare cache fields. This "zero-intrusion" design is developer-friendly, but it also means cache behavior is entirely determined by prefix consistency — any subtle format change (including JSON field ordering or whitespace differences) will cause a hash mismatch and completely invalidate the cache. The proxy layer must therefore ensure that converted requests maintain stable prefixes, avoiding prefix "breaks" caused by field ordering or formatting differences.
Stable Prefixes Are the Key to Cache Hits
Regardless of which model you're connecting to, the universal principle for achieving cache hits is: keep the prefix of the request context as stable as possible. Specifically:
- System prompts, tool definitions, and other fixed content should always appear at the very beginning of the request, in a completely consistent format;
- Per-turn user input should be appended at the end.
If the proxy layer changes the JSON serialization order, injects dynamic timestamps, or modifies the message structure during conversion, it can break prefix consistency and completely invalidate the cache.
A Realistic Assessment: There's No Silver Bullet
It's important to be clear-eyed here: the community currently has no out-of-the-box, officially supported solution that perfectly handles caching for all open-source models. The root cause is that cache implementations vary significantly across providers:
- DeepSeek: Automatic prefix caching, no explicit marking required, relies on hash matching;
- MiniMax: Has its own caching strategy and integration requirements;
- Anthropic: Relies on explicit
cache_controlmarkers, supports fine-grained cache breakpoint control.
This fragmented landscape means any intermediary layer can only adapt to specific models on a case-by-case basis. Developers pursuing cache hits typically need to:
- Choose a mature proxy tool that supports cache field mapping;
- Consult the specific model's cache documentation to understand prefix matching rules;
- Empirically verify whether cache hits are actually occurring (this can be confirmed via fields like
cache_hit_tokensin the API response).
The Long-Term Tension Between Unified Interface and Heterogeneous Backends
At its core, this issue represents a fundamental tension between "unified Agent experience" and "heterogeneous multi-model backends." Developers want to use their preferred interface (Claude Code) to drive the most cost-effective models (DeepSeek, MiniMax, etc.), but the lack of standardization in underlying protocols and caching mechanisms makes this vision full of friction.
In the short term, using a mature proxy translation layer combined with targeted cache parameter mapping is a relatively viable path. In the long run, as the AI coding tool ecosystem continues to mature, a truly standardized caching protocol may emerge — one that makes "one interface, any model, seamless cache hits" the norm. Until then, developers will continue to navigate tradeoffs between convenience and cost optimization through careful experimentation.
Key Takeaways
Related articles

The Truth Behind Codex 'Build a Website in 5 Minutes': AI Isn't Creating Sites—It's Helping You Copy Them
Exposing the truth behind viral Codex 5-minute website videos: creators aren't building original sites with AI—they're copying shared prompts or scraping others' work. Learn AI coding tools' real limits.

Getting Started with AI Agent Development: A Complete Guide from Concept to Practice
A comprehensive guide to AI Agent architecture and development, covering automated marketing, intelligent customer service, and investment analysis scenarios with single and multi-agent collaboration.

The Truth Behind Codex 'Build a Website in 5 Minutes': AI Isn't Creating Sites — It's Helping You Copy Them
Exposing the truth behind viral Codex 5-minute website videos: creators aren't building original sites with AI — they're copying shared prompts or scraping others' work.