Agent SDK subagents have prompt caching disabled by default (enablePromptCaching: false)

Open 💬 5 comments Opened Mar 2, 2026 by KevinZhao

Summary

Subagent requests spawned via the Agent tool have enablePromptCaching hardcoded to false, causing all subagent API calls to miss prompt caching entirely. This results in significant unnecessary cost for tools, system prompts, and conversation history being sent as uncached input on every request.

Root Cause

In the CLI bundle, the main REPL query path correctly defaults to enabling prompt caching:

// Main REPL path (line ~6108 in cli.js):
let S = w.enablePromptCaching ?? YWq(w.model)  // YWq() returns true unless env var disabled

However, subagent internal queries explicitly default to false:

// Subagent path:
enablePromptCaching: z.enablePromptCaching ?? false  // hardcoded false

This means:

  • Main CLI (Opus): enablePromptCachingundefined → falls through to YWq()true
  • Subagent (Sonnet/etc): enablePromptCachingundefined → falls through to false

Impact

From real proxy logs analyzing 104 requests in a single session:

| Request Type | Count | Cache Behavior |
|-------------|-------|---------------|
| Main CLI (Opus) | 50 | ✅ Cache breakpoints injected, cache hits observed |
| Subagent (Sonnet) | 54 | ❌ Zero cache breakpoints, all input uncached |

Subagent requests typically carry ~7,000+ tokens of tools and system prompt that are identical across requests. Without caching, these are billed as full uncached input every time.

Cost example: 54 subagent requests × 7,013 uncached tokens each = ~378,000 wasted uncached input tokens per session.

Proposed Fix

Change the subagent default from false to use the same YWq() check as the main REPL:

// Before:
enablePromptCaching: z.enablePromptCaching ?? false

// After:
enablePromptCaching: z.enablePromptCaching ?? YWq(model)

This would make subagents respect the same environment variable controls (DISABLE_PROMPT_CACHING, DISABLE_PROMPT_CACHING_SONNET, etc.) while enabling caching by default — consistent with the main CLI behavior.

Environment

  • Claude Code version: 2.1.63
  • Agent SDK version: 0.2.63
  • Provider: AWS Bedrock (but issue applies to all providers)
  • Analysis method: Reverse proxy intercepting API requests, confirmed zero cache_control blocks in subagent request bodies

Workaround

Currently using a local reverse proxy that injects cache_control breakpoints into subagent requests that lack them. This works but adds operational complexity. A one-line fix in the CLI would eliminate the need for this workaround.

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗