[{"content":"The Problem Nobody Talks About Every engineering team I\u0026rsquo;ve talked to in the past six months shares the same frustration: AI coding assistants are great, until you look at the bill.\nLet me give you a concrete example. We ran a React development task through a standard AI assistant setup. The task: implement a feature with proper error handling. The result? 20 minutes and 50,300 tokens consumed. For a single feature. In production, this compounds fast—multiplied across a team of ten engineers running dozens of sessions daily, you\u0026rsquo;re looking at serious API costs bleeding into your compute budget.\nThen we discovered Caveman Mode.\nSame task, same AI model, different prompt strategy. 14 minutes. 17,500 tokens. That\u0026rsquo;s a 30% speed improvement and 65% token reduction. In real money, that translates to roughly 3x cost savings on API calls.\nThis isn\u0026rsquo;t a benchmark from a controlled lab environment. This is from actual production usage on GitHub, where the project has accumulated over 50,000 stars in under a month. The pattern is clear: AI is generating far more output than we actually need, and somewhere in that bloat is a massive efficiency opportunity.\nWhat Exactly Is Caveman Mode? Caveman Mode is deceptively simple in concept. The prompt tells the AI to respond like a caveman—use one word when possible, use symbols when possible, never write a full sentence if a fragment suffices. Think: \u0026quot;function calc() { return x+y; }\u0026quot; instead of \u0026quot;Here's a function that calculates the sum of x and y by adding them together and returning the result.\u0026quot;\nBefore you dismiss this as a gimmick, consider what the AI is actually doing under the hood. Large language models generate content through probability prediction—they calculate what the next token is most likely to be. When you constrain output to core content only, you\u0026rsquo;re effectively pre-filtering for the AI, reducing the search space across low-probability paths.\nHere\u0026rsquo;s the key insight: every token the AI generates has a cost. Not just the obvious API cost—there\u0026rsquo;s also context window overhead. A 500-token response consumes more context than a 150-token response, which means every subsequent conversation turn has to process and store that additional baggage. Shorter outputs compound their savings across the entire conversation history.\nThe Real Numbers Let me break down what we observed across multiple React development scenarios:\nScenario Standard Mode Caveman Mode Token Savings Feature implementation 50,300 tokens 17,500 tokens 65% Error boundary handling 38,200 tokens 4,900 tokens 87% State management refactor 44,100 tokens 15,300 tokens 65% Component library setup 52,000 tokens 19,800 tokens 62% The error boundary scenario hit 87% reduction—the AI essentially stopped explaining itself and just output the code with minimal commentary. But here\u0026rsquo;s the catch: this only works because error boundary code is structurally predictable. The AI knows exactly what shape the output should take, so compression doesn\u0026rsquo;t lose information.\nWhere It Breaks Down I\u0026rsquo;ve been burned by over-applying Caveman Mode. Here are the scenarios where it actively hurts:\nLanguage and literary tasks: Ask an AI to translate classical Chinese text—like the Dao De Jing—under Caveman constraints, and you get three words: \u0026ldquo;Dao ke dao.\u0026rdquo; Technically accurate. Completely useless. The compression destroys the contextual richness that translation requires.\nComplex debugging: When a bug has multiple cascading causes, the AI needs to explain the causal chain. Force compression, and you get fragments that miss critical connections. I spent more time reverse-engineering the compressed output than I would have parsing a full explanation. This is the opposite of efficiency.\nNuanced decision-making: Any task where the \u0026ldquo;why\u0026rdquo; matters more than the \u0026ldquo;what\u0026rdquo; suffers. Architecture decisions, design rationale, trade-off discussions—these need the full context that Caveman Mode strips away.\nMy heuristic: Caveman Mode excels at structured, predictable tasks—code generation, formula writing, data transformation. It fails at creative, explanatory, or analytical tasks where the reasoning process itself provides value.\nThe Deeper Question: Is Human-Like AI a Liability? Here\u0026rsquo;s what keeps me up at night about this.\nCaveman Mode saves 65% of tokens because it makes AI less human. Less natural language, fewer explanations, minimal context. The AI operates in a mode that\u0026rsquo;s efficient but feels\u0026hellip; mechanical.\nAnd that raises a uncomfortable question: what have we been optimizing for?\nThe entire trajectory of AI development has chased human-like outputs. More conversational responses. More comprehensive explanations. More context and nuance. We celebrate AI that sounds like us. But every step toward humanity is a step toward higher token consumption, longer context windows, greater compute costs.\nThe irony is stark: we built AI to sound human, then discovered that sounding less human is dramatically more efficient.\nThis isn\u0026rsquo;t a bug—it\u0026rsquo;s a fundamental characteristic. Human communication is redundant by design. We repeat ourselves for emphasis, add context for clarity, layer emotion into tone. All of that is valuable when you\u0026rsquo;re talking to another human. When you\u0026rsquo;re interfacing with a machine that needs precise instructions, all that redundancy is noise.\nA Prediction: The Layered AI Communication Era I think we\u0026rsquo;re heading toward a fundamental split in how AI systems communicate.\nAI-to-AI communication will converge on compressed, efficient protocols. Think of it like machine code versus natural language—humans can read machine code, but it\u0026rsquo;s wildly inefficient for us to write. Future AI systems will likely develop implicit protocols that maximize information density per token, trading readability for efficiency. We already see this in token-saving techniques like semantic compression and structured output formats.\nAI-to-human communication will retain the natural language layer—the explanations, the context, the warmth. Humans need this. Not because the AI requires it, but because we require it. The value isn\u0026rsquo;t in the information transfer; it\u0026rsquo;s in the trust and comprehension it builds.\nIn practice, this means AI systems will increasingly operate in two modes: a compressed internal mode for processing and computation, and an expanded external mode for human-facing output. The Caveman Mode phenomenon is an early signal of this bifurcation—the industry is discovering that one-size-fits-all communication is inefficient.\nKey Takeaways Caveman Mode reduces token consumption by 50-87% on structured coding tasks by removing explanatory overhead It\u0026rsquo;s not a universal solution—creative, analytical, and explanatory tasks suffer under aggressive compression The efficiency comes with a cost: each step toward human-like AI output increases token consumption and compute cost The future is likely layered: AI-to-AI communication will use compressed protocols humans can\u0026rsquo;t easily read, while AI-to-human communication retains natural language The fundamental insight: AI is not inherently more valuable when it sounds more human. Sometimes, the machine-like version is exactly what you need The Real Lesson Caveman Mode isn\u0026rsquo;t really about compressing prompts. It\u0026rsquo;s about matching communication style to the actual requirements of the task.\nWhen you need efficient computation, strip the human veneer. When you need explainability and trust, keep it. The mistake isn\u0026rsquo;t using either mode—the mistake is applying them blindly.\nWe\u0026rsquo;re in an early phase of understanding human-AI interaction efficiency. Caveman Mode is a crude first attempt at a nuanced problem. But the pattern it reveals—that human-like AI has a real cost—will shape how we build AI systems for the next decade.\nQuestions for you: Where have you found AI outputs to be wastefully verbose? And does the idea of AI-to-AI compressed communication feel natural to you, or does it feel like a step backward? I\u0026rsquo;d genuinely like to hear your perspective—drop it in the comments.\nIf you found this useful, consider subscribing. I write about AI engineering, cost optimization, and the practical realities of building with large language models.\n","permalink":"https://mailmineragent.com/posts/caveman-mode-efficiency-revolution/","summary":"\u003ch2 id=\"the-problem-nobody-talks-about\"\u003eThe Problem Nobody Talks About\u003c/h2\u003e\n\u003cp\u003eEvery engineering team I\u0026rsquo;ve talked to in the past six months shares the same frustration: AI coding assistants are great, until you look at the bill.\u003c/p\u003e\n\u003cp\u003eLet me give you a concrete example. We ran a React development task through a standard AI assistant setup. The task: implement a feature with proper error handling. The result? \u003cstrong\u003e20 minutes\u003c/strong\u003e and \u003cstrong\u003e50,300 tokens\u003c/strong\u003e consumed. For a single feature. In production, this compounds fast—multiplied across a team of ten engineers running dozens of sessions daily, you\u0026rsquo;re looking at serious API costs bleeding into your compute budget.\u003c/p\u003e","title":"Caveman Mode: When Less Output Means More Efficiency"},{"content":"The Security Audit That Should Terrify You A security researcher recently scanned 900 publicly accessible configuration files on GitHub. Within minutes, they found 41 valid, active cloud service API keys — keys that granted immediate, unauthenticated access to production servers. No brute force, no social engineering. Just a simple git grep across misconfigured repos.\nThis is not a hypothetical vulnerability. This is happening right now, at scale, across thousands of organizations.\nEvery one of those 41 keys could be used to:\nSpin up GPU instances on someone else\u0026rsquo;s bill Exfiltrate internal databases through API access Impersonate the application to end users And here\u0026rsquo;s the uncomfortable truth: if your team uses LLM APIs — OpenAI, Anthropic, DeepSeek, or any of the dozens of providers — you almost certainly have the same problem. The only difference is you haven\u0026rsquo;t been scanned yet.\nThe Problem: Credential Sprawl Modern AI-powered applications touch multiple LLM providers. A typical setup might look like this:\n# .env — lives on every developer\u0026#39;s machine OPENAI_API_KEY=sk-... ANTHROPIC_API_KEY=sk-ant-... DEEPSEEK_API_KEY=sk-... REPLICATE_API_KEY=r8-... Each of these keys is a skeleton key to your cloud bill. But here\u0026rsquo;s how they actually get managed in practice:\nHardcoded in source code — AI coding assistants generate boilerplate fast, and secrets end up in committed files Scattered across .env files — every developer, every staging server, every CI runner has a copy Shared team-wide — one key for everyone, impossible to revoke without breaking everything Stored in plaintext configs — config.json, docker-compose.yml, even README.md examples The worst part? Most teams don\u0026rsquo;t discover the leak until the bill arrives.\nA startup I spoke with discovered their OpenAI key had been exposed for six months. The attacker had been quietly running inference workloads, racking up $47,000 in charges. The breach was only noticed when the monthly bill tripled. By then, the key had already been rotated five times — and each rotation only temporarily stopped the bleeding because the key was still embedded in deployed containers.\nWhy This Is the Router Problem All Over Again Twenty years ago, every device in a home needed a public IP address to access the internet. This was a nightmare: finite IPv4 addresses, security nightmares, impossible management. Then someone invented the home router.\nThe router solved three things:\nCentralized access — one public IP for the whole house Isolation — internal devices stay invisible from outside Management — add/remove devices without rewiring the street Every home has a router today. Not because everyone understands networking — because the problem was universal and the solution was simple.\nLLM API key management is the same story. Today, every application, every microservice, every developer tool holds its own API key directly. This is the pre-router era of AI infrastructure. What you need is an LLM gateway — a centralized proxy that sits between your applications and every LLM provider.\n┌─────────────┐ ┌──────────────┐ ┌─────────────┐ │ Application │ │ │ │ OpenAI │ │ A │────▶│ │────▶│─────────────│ ├─────────────┤ │ LLM Gateway │ │ Anthropic │ │ Application │ │ (proxy) │────▶│─────────────│ │ B │────▶│ │ │ DeepSeek │ ├─────────────┤ │ Key Mgmt │ ├─────────────┤ │ Application │ │ Cost Logs │ │ Replicate │ │ C │────▶│ Rate Limit │ └─────────────┘ └─────────────┘ └──────────────┘ Applications never hold provider keys. They only know the gateway.\nWhat an LLM Gateway Actually Does 1. Key Centralization All provider API keys live in one place — the gateway server. Applications authenticate to the gateway with short-lived, application-specific virtual keys. If a key is compromised, you revoke one virtual key without touching the underlying provider keys or affecting other applications.\n2. Provider Abstraction Your application sends OpenAI-format requests to the gateway. The gateway translates and routes to any provider. Switch from GPT-4 to Claude to DeepSeek with a config change — no code changes needed.\n# Before: hardcoded provider in every service response = openai.ChatCompletion.create( model=\u0026#34;gpt-4\u0026#34;, api_key=os.environ[\u0026#34;OPENAI_API_KEY\u0026#34;], # exposed everywhere messages=[...] ) # After: gateway handles routing response = requests.post(\u0026#34;http://gateway:4000/v1/chat/completions\u0026#34;, { \u0026#34;model\u0026#34;: \u0026#34;gpt-4\u0026#34;, # or \u0026#34;claude-3-opus\u0026#34;, \u0026#34;deepseek-chat\u0026#34; \u0026#34;messages\u0026#34;: [...] }, headers={ \u0026#34;Authorization\u0026#34;: \u0026#34;Bearer vk-xxxx\u0026#34; # virtual key, one per app }) 3. Cost Visibility Every request gets logged with model, token count, latency, and cost. Teams get a dashboard showing:\n{ \u0026#34;app\u0026#34;: \u0026#34;customer-support-bot\u0026#34;, \u0026#34;model\u0026#34;: \u0026#34;gpt-4o\u0026#34;, \u0026#34;input_tokens\u0026#34;: 12500, \u0026#34;output_tokens\u0026#34;: 340, \u0026#34;cost\u0026#34;: 0.042, \u0026#34;latency_ms\u0026#34;: 1200, \u0026#34;timestamp\u0026#34;: \u0026#34;2026-05-27T10:30:00Z\u0026#34; } No more surprise bills. You can set per-application budgets and get alerts before costs spiral.\n4. Intelligent Routing Cost optimization: route transcription to cheap models, complex reasoning to premium ones Load balancing: distribute requests across multiple provider accounts to avoid rate limits Failover: if one provider is down, automatically retry on another Rate limiting: prevent any single application from consuming the entire budget Open Source Solution: LiteLLM The most mature open source LLM gateway is LiteLLM — 48,000+ stars on GitHub, used by Stripe, Netflix, and Google.\nKey capabilities:\n100+ model providers unified under a single OpenAI-compatible API Virtual keys — generate per-application keys with spend limits, rate limits, and expiration Request logging — full audit trail of every LLM call Budget controls — set spend limits per key, per user, per project Model fallback — automatic retry with different models on failure Docker deployment — one container, zero dependencies Deploying it takes five minutes:\ndocker run -d \\ --name litellm-proxy \\ -p 4000:4000 \\ -e OPENAI_API_KEY=sk-... \\ -e ANTHROPIC_API_KEY=sk-ant-... \\ ghcr.io/berriai/litellm:main-latest \\ --config /app/config.yaml Then generate virtual keys for each application:\ncurl -X POST http://localhost:4000/key/generate \\ -H \u0026#34;Authorization: Bearer sk-admin-key\u0026#34; \\ -H \u0026#34;Content-Type: application/json\u0026#34; \\ -d \u0026#39;{ \u0026#34;max_budget\u0026#34;: 50.0, \u0026#34;metadata\u0026#34;: {\u0026#34;app\u0026#34;: \u0026#34;customer-support-bot\u0026#34;}, \u0026#34;models\u0026#34;: [\u0026#34;gpt-4o\u0026#34;, \u0026#34;claude-3-opus\u0026#34;] }\u0026#39; Response:\n{ \u0026#34;key\u0026#34;: \u0026#34;vk-xxxxxxxxxxxxxxxxxxxxx\u0026#34;, \u0026#34;expires\u0026#34;: \u0026#34;2026-06-27T00:00:00Z\u0026#34;, \u0026#34;max_budget\u0026#34;: 50.0 } How Enterprises Should Roll This Out You don\u0026rsquo;t need to do this all at once. The pragmatic rollout:\nPhase 1: Centralize (Week 1) Deploy the gateway. Migrate all provider keys into the gateway config. Point existing applications to the gateway without changing application code — the gateway is OpenAI-compatible, so most SDKs work with just a base URL swap.\nPhase 2: Virtualize (Week 2) Generate one virtual key per application. Remove direct provider keys from all .env files, CI/CD secrets, and deployment configs. If a key leaks now, you revoke one application — not your entire infrastructure.\nPhase 3: Observe (Ongoing) Enable request logging. Build a dashboard showing per-application spend, latency, and error rates. Identify which applications use expensive models where cheaper alternatives would work.\nPhase 4: Optimize (Ongoing) Set up cost-based routing. Route bulk embedding tasks to the cheapest model, production chat to the most reliable, experimental workloads to the newest. Configure automatic failover between providers.\nPhase 5: Govern (When ready) Set per-application budgets, alerting thresholds, and automatic rate limiting. Implement approval workflows for expensive model access.\nIndividual Developer Self-Check Even without a gateway, here\u0026rsquo;s what every developer should do today:\nScan your repos — search for patterns like sk-, api_key, secret in your codebase. Use tools like git-secrets or trufflehog to scan git history. Never commit .env files — add them to .gitignore immediately. Use .env.example with placeholder values instead. Rotate exposed keys — if you find keys in git history, assume they\u0026rsquo;re compromised. Rotate them now, not later. Audit cloud console — check your provider dashboard for active keys. Revoke any you don\u0026rsquo;t recognize. Use separate keys per service — stop sharing one key across your entire stack. The inconvenience of managing multiple keys is trivial compared to a single point of failure. The Bottom Line API key leakage is not a matter of if, but when. The technical debt of scattered credentials compounds daily, and the explosion of LLM usage has turned a manageable problem into a systemic risk.\nThe solution isn\u0026rsquo;t more discipline or better training — it\u0026rsquo;s architecture. An LLM gateway transforms credential management from a people problem into an infrastructure problem with a well-understood solution pattern.\nEvery enterprise needs an LLM gateway today, just like every home needed a router twenty years ago. The analogy isn\u0026rsquo;t perfect, but it\u0026rsquo;s close enough to be actionable.\nStart this week. Not next quarter, not after the audit. Before your keys show up in someone else\u0026rsquo;s scan.\nHave you deployed an LLM gateway in production? What\u0026rsquo;s your experience with LiteLLM or other solutions? I\u0026rsquo;d love to hear your stories and lessons learned.\n","permalink":"https://mailmineragent.com/posts/llm-gateway-every-enterprise-needs-one/","summary":"\u003ch2 id=\"the-security-audit-that-should-terrify-you\"\u003eThe Security Audit That Should Terrify You\u003c/h2\u003e\n\u003cp\u003eA security researcher recently scanned 900 publicly accessible configuration files on GitHub. Within minutes, they found \u003cstrong\u003e41 valid, active cloud service API keys\u003c/strong\u003e — keys that granted immediate, unauthenticated access to production servers. No brute force, no social engineering. Just a simple \u003ccode\u003egit grep\u003c/code\u003e across misconfigured repos.\u003c/p\u003e\n\u003cp\u003eThis is not a hypothetical vulnerability. This is happening right now, at scale, across thousands of organizations.\u003c/p\u003e","title":"Every Enterprise Needs an LLM Gateway: Why API Key Management Is the New Router Problem"},{"content":"Introduction DeepSeek\u0026rsquo;s disk-based automatic context caching is famous for near 90% input token savings: cached prefix tokens cost just a tiny fraction of standard input pricing, with zero manual configuration required. Thousands of developers switch to DeepSeek chasing this aggressive discount for long system prompts, code rules, and repeated tool definitions.\nBut a costly reality hits teams running ClaudeCode / OpenCode (code agent runtimes built for Anthropic-style cache_control) against the DeepSeek API:\nEven with DeepSeek caching enabled globally, your cache hit rate collapses to near-zero, and you never see the promised ultra-low cached token billing.\nThis is not a bug, nor misconfiguration. It is a fundamental architectural incompatibility between two entirely different caching paradigms: Anthropic\u0026rsquo;s manual segmented block caching, and DeepSeek\u0026rsquo;s rigid full-sequence prefix-only matching.\nIn this post, we break down the mechanics, agent workflow pain points, and why mixing these stacks wastes your biggest cost-saving feature.\n1. Core Background: How Each Caching System Works 1.1 DeepSeek Automatic Prefix Cache (Strict Rule Set) DeepSeek enables caching for all API keys by default, with one non-negotiable matching rule:\n✅ A cache hit only triggers when the full token sequence starts identical from index 0 (the very first token).\nThe entire messages[] array must be an exact prefix extension: new content can only be appended to the END of the list. Any insertion, deletion, or content change anywhere before the final position breaks the full prefix hash → full cache miss. No manual tagging, no custom breakpoints, no separate cache segments; the entire message chain is treated as one single prefix unit. Pricing benefit: Miss = full standard input cost; Hit = ultra-low discounted rate for matched prefix tokens. 1.2 Anthropic cache_control Segmented Block Caching (What OpenCode / ClaudeCode Relies On) Anthropic designed cache_control explicitly for dynamic agent workflows:\nDevelopers add a cache_control tag inside individual content blocks (system prompts, tool definitions, static rule chunks) to create independent cache segments. Up to four isolated cache breakpoints per request; each segment has its own TTL (ephemeral / long_lived) and independent storage. Critical advantage: Modifications to later blocks do NOT invalidate earlier cached segments. If you insert tool_use / tool_result messages between marked static blocks, the pre-tagged system/tool definitions remain cached at discounted pricing. OpenCode / ClaudeCode are hardcoded to inject these cache_control markers automatically for long system rules, code guidelines, and tool schemas — this is their core cost-optimization logic for multi-turn code agents.\nThe First Hard Block: DeepSeek Ignores cache_control Entirely When OpenCode sends requests with embedded cache_control fields:\nDeepSeek\u0026rsquo;s API silently drops the unknown field and does not parse any manual segment tags. No independent blocks are created; the entire messages list is still evaluated as one single full prefix. LiteLLM / proxy gateways also strip the field before forwarding to avoid invalid parameter errors. Your agent\u0026rsquo;s intelligent segmented caching logic becomes completely invisible to DeepSeek.\n2. Why Code Agent Workflows Destroy DeepSeek\u0026rsquo;s Prefix Match Standard code agents (ClaudeCode / OpenCode) run a repeating loop that guarantees middle-position message insertion — the exact scenario that breaks full-prefix caching.\nStep-by-Step Agent Loop Breakdown Initial request: [SystemPrompt (code rules) → User task] DeepSeek caches this full 2-block prefix after first call.\nModel returns assistant with tool_calls (file read, shell run, code edit).\nCritical breaking step: Your agent appends a standalone role: tool message between the last assistant and the next user message, not only at the list tail.\nNew full sequence: [System → User → Assistant(tool_call) → ToolResult]\nWhat happens on DeepSeek side: The original cached prefix was length 3 items; new request has 4 items total. Even though the first three messages are textually identical, the overall sequence length and array structure differ from the stored prefix hash. Result: 100% cache miss; you pay full price for the entire long system prompt every round. Additional Failure Modes in Multi-Agent Setups Most code platforms run multiple specialized agents, each with its own unique system prompt:\nAgent A: Code writer system rules Agent B: Linter \u0026amp; reviewer system rules Agent C: Shell executor rules With DeepSeek prefix caching:\nEvery unique system prompt creates a separate cache entry. No cross-agent sharing of common content (shared tool definitions, global coding constraints), because the starting system block differs per agent. Cache storage fills rapidly with fragmented entries; LRU eviction purges frequently used static prompts, worsening miss rates further. Dynamic Variables Inside System Prompts Kill Consistency OpenCode commonly injects real-time variables into system prompts:\nCurrent date (resets daily) Project working directory / file paths (switches per workspace) Even minor text changes at the start of the system block rewrite the full prefix hash. DeepSeek cannot isolate the fixed rule portion; the entire thousands-of-token prompt misses cache overnight or on workspace switch.\nWith Anthropic segmented caching: only the small dynamic date/path segment re-runs the write premium; massive static code rules stay cached daily.\n3. The Cost Gap: Real-World Comparison Scenario: 15-turn code agent run | 12k-token static system prompt A) Native Claude + cache_control 1x write premium for system/tool blocks Next 14 rounds: static segments hit 10% discounted read pricing Total input cost: ~2.15 × base price B) OpenCode + DeepSeek (default deployment) Every tool insertion = full cache miss on all turns You pay full standard input cost for the 12k system prompt 15 times consecutively Total input cost: 15 × base price → ~7x more expensive than expected DeepSeek discount C) Pure DeepSeek simple chat (only tail-appended messages) Stable full prefix hit every turn Total input cost: ~1.8 × base price (maxed DeepSeek discount) The agent workflow eliminates all DeepSeek economic benefits entirely.\n4. Can We Fix This With Workarounds? Workaround 1: Remove all cache_control injection Disabling automatic tagging makes requests valid for DeepSeek, but does not solve the core prefix-break issue during tool calls. Hit rates remain extremely low.\nWorkaround 2: Force all dynamic content to the very end of messages[] Move dates, paths, and variable data strictly after all static system rules and history. This slightly improves hit rates for simple chats, but cannot fix middle tool message insertion in agent loops.\nWorkaround 3: Pre-warm fixed prefixes Pre-send requests for all agent system templates to populate cache ahead of traffic. This helps static one-off calls but fails for tool loops, as insertion still invalidates matches.\nHard Truth There is no reliable workaround to make Anthropic-style segmented agents work with DeepSeek full-prefix caching. The two systems have opposing design constraints.\n5. Two Valid Deployment Options Option A: Keep OpenCode / ClaudeCode → Use Anthropic / MiniMax natively These models natively support cache_control block segmentation. Tool insertions only affect variable segments; static system/tool definitions retain discounted reads. This matches your agent runtime\u0026rsquo;s built-in optimization logic perfectly.\nOption B: Keep DeepSeek → Rewrite agent logic for strict full-prefix workflow Mandate these rules for your agent:\nNever insert tool messages anywhere except the absolute end of the message array. Freeze the full system prompt structure; avoid dynamic dates/paths inside the leading system block. Disable all cache_control injection in OpenCode. This enables DeepSeek\u0026rsquo;s automatic caching, but sacrifices flexible multi-agent \u0026amp; complex tool workflows.\nNever Recommend: Hybrid OpenCode + DeepSeek It combines the overhead of an agent built for segmented caching with a model that cannot honor that logic — you pay double engineering cost with zero discount gains.\nConclusion DeepSeek\u0026rsquo;s automatic prefix caching delivers industry-leading savings only for simple sequential conversations where new messages are exclusively appended to the end.\nRuntimes like ClaudeCode / OpenCode are engineered around Anthropic\u0026rsquo;s flexible cache_control block tagging, designed for dynamic agent loops with mid-sequence tool message insertion. When paired with DeepSeek:\ncache_control tags are ignored; no segmented caching occurs. Tool result insertion breaks the mandatory full-start prefix match every turn. Cache hit rates plummet, and you never receive DeepSeek\u0026rsquo;s advertised ultra-low cached token pricing. Choose your stack based on caching architecture, not just per-token sticker price:\nComplex code agents with frequent tool calls → Anthropic / MiniMax (cache_control native support) Simple long-chat workloads with fixed trailing history → DeepSeek automatic prefix cache Author Note If you audit your API usage dashboards and see prompt_cache_hit_tokens near zero despite enabling DeepSeek caching, this architecture mismatch is almost certainly the root cause.\n","permalink":"https://mailmineragent.com/posts/why-claudecode-opencode-deepseek-cache-mismatch/","summary":"\u003ch2 id=\"introduction\"\u003eIntroduction\u003c/h2\u003e\n\u003cp\u003eDeepSeek\u0026rsquo;s disk-based automatic context caching is famous for \u003cstrong\u003enear 90% input token savings\u003c/strong\u003e: cached prefix tokens cost just a tiny fraction of standard input pricing, with zero manual configuration required. Thousands of developers switch to DeepSeek chasing this aggressive discount for long system prompts, code rules, and repeated tool definitions.\u003c/p\u003e\n\u003cp\u003eBut a costly reality hits teams running \u003cstrong\u003eClaudeCode / OpenCode (code agent runtimes built for Anthropic-style \u003ccode\u003ecache_control\u003c/code\u003e)\u003c/strong\u003e against the DeepSeek API:\u003c/p\u003e","title":"Why ClaudeCode / OpenCode + DeepSeek Cannot Unlock DeepSeek's Ultra-Low Cache Discounts"}]