Claude Code 2.1.181: Prompt Caching Restored on Custom Gateways and Foundry — What Operators Must Know

Claude Code 2.1.181 fixes a silent prompt-caching regression that was inflating costs for every team running a custom ANTHROPIC_BASE_URL or Microsoft Foundry endpoint. It also enforces the five-level subagent depth cap for foreground agents.

TheRouter Newsroomvia Anthropic
Abstract routing diagram showing a cache layer correctly intercepting repeated API calls through a custom gateway endpoint

If your team routes Claude Code through a custom ANTHROPIC_BASE_URL, a self-hosted AI gateway, or Microsoft Azure Foundry, you were losing prompt-cache hits on every turn — and probably hadn't realized it. Claude Code 2.1.181, released June 17 2026, fixes that silently expensive regression and closes a subagent governance gap that background agents already respected but foreground agents did not.

What happened

The 2.1.181 release ships one critical bug fix and several operator-relevant improvements:

Prompt caching broken on custom base URLs and Foundry. Per-request attestation tokens — used by custom endpoints and Foundry to verify each call — were changing on every turn, causing Claude Code to see a different request fingerprint and bypass the cache entirely. Operators running against ANTHROPIC_BASE_URL or Foundry had zero effective prompt-cache hits. At typical system-prompt sizes (~2,000–8,000 tokens), every missed cache read means the full context is re-billed at non-cached input rates. For teams running dozens of parallel coding sessions, this could add 40–60% to effective per-session costs.

Foreground subagents now respect the five-level depth limit. Background subagents have been depth-capped since 2.1.175. Foreground (interactive) subagents were not, meaning an unconstrained foreground agent could spawn recursive chains beyond the intended governance boundary. 2.1.181 applies the same five-level cap to both, closing the inconsistency.

/config key=value prompt syntax. Teams can now set any configuration key inline from the prompt — including in headless -p mode and Remote Control sessions. This matters for operators running programmatic Claude Code invocations where interactive config menus are unavailable.

AWS credential refresh loop fixed. awsCredentialExport credentials with a short remaining lifetime were triggering a refresh cycle every minute. This caused repeated AssumeRole calls against Bedrock and intermittent rate-limit errors in high-throughput pipelines.

Additional fixes include stable long-session history (another process's cleanup no longer purges an active session's transcript), startup latency reduction (~120ms per launch on fresh environments), and macOS-specific reliability patches.

Why it matters for AI engineering teams

The prompt-caching regression is the highest-impact item for teams using custom routing infrastructure. Prompt caching is load-bearing for Claude Code's cost model: Anthropic's own documentation describes cache hit rates above 80% as the norm in steady-state coding sessions. A full-session cache miss means every turn re-tokens the system prompt, project context, and accumulated conversation history at standard input pricing.

For teams that deployed Claude Code through a managed AI gateway or Microsoft Foundry specifically to get centralized billing, rate-limit management, and provider switching, the irony is that the very infrastructure they added to improve cost control was silently bypassing the cache that would have reduced it.

The five-level subagent depth enforcement matters for operator governance. Before 2.1.181, a foreground agent could escape the depth limit that the -p / headless pipeline already enforced on background agents. In multi-tier architectures — orchestrator → planner → executor sub-agents — this inconsistency created a gap where interactive sessions could run deeper delegation chains than programmatic ones, making fleet-wide governance rules harder to enforce uniformly.

The router and operator angle

Several changes in 2.1.181 map directly to routing-layer concerns:

Prompt cache validation. Teams running a reverse-proxy or gateway in front of the Anthropic API should audit their attestation token behavior. If your gateway adds a per-request signature or tracking header that changes on every call — even if the underlying prompt does not change — you may be generating the same cache-miss pattern that Foundry had. The fix in Claude Code adjusts how it reads cache headers, but the behavior of intermediate proxies that modify request fingerprints is still in your hands.

Subagent depth as a routing policy. The five-level cap is now consistently enforced regardless of whether a subagent is launched interactively or programmatically. Operators who want tighter limits should use Tool(param:value) permission rules (introduced in 2.1.178) to restrict subagent model access by tier before the depth cap kicks in.

Headless /config for fleet automation. The new /config key=value syntax makes it practical to script configuration changes in -p mode, meaning operators can now set per-invocation model, effort level, or sandbox policy without interactive setup. This reduces friction for CI/CD pipelines that spin up Claude Code tasks with custom routing targets.

Bedrock rate-limit protection. The AWS credential refresh fix reduces spurious STS calls that were hitting Bedrock's AssumeRole rate limits in high-concurrency environments. Teams with multiple parallel Claude Code sessions against Bedrock should see fewer intermittent 429s tied to credential churn.

What TheRouter users should watch or try

If you run Claude Code through TheRouter or any OpenAI-compatible gateway, verify that your proxy layer does not inject per-request tokens that change on every call. Consistent request fingerprinting is what makes prompt caching work — upstream fixes in Claude Code won't help if the intermediate gateway transforms the request in a way that defeats the cache key.

Operators managing Claude Code fleets across multiple backend providers can also use the new /config prompt syntax to inject provider-specific settings (model name, base URL, effort level) in per-session automation scripts without relying on environment-variable configuration baked into the container image.

For governance, the uniform five-level subagent cap removes one variable from fleet policy reasoning: interactive and headless agents now behave identically under depth pressure. If your cost model or security policy requires tighter limits, configure model-tier blocks through Tool(model:tier) permission rules rather than relying on depth alone.

See TheRouter docs for current guidance on connecting Claude Code to a custom API endpoint.

Customer Support