cnighswonger/claude-code-cache-fix
Fixes prompt cache regression in Claude Code that causes up to 20x cost increase on resumed sessions
What it solves
This project addresses prompt cache bugs in Claude Code that lead to excessive token usage (quota burn) and unstable cache-read ratios. It specifically fixes issues where resumed or long-running sessions experience repeated spikes in cache creation tokens, preventing unnecessary costs and stabilizing the request prefix.
How it works
It operates as a local HTTP proxy that sits between Claude Code and the Anthropic API. The proxy intercepts and rewrites POST /v1/messages requests to normalize request structures (such as block order, fingerprints, and TTL) to ensure prompt caching works efficiently.
It offers two primary modes of operation:
- Reverse-Proxy Mode: The user points Claude Code's
ANTHROPIC_BASE_URLto the proxy. - Forward-Proxy Mode: The proxy acts as an
HTTPS_PROXY, terminating TLS forapi.anthropic.comusing a locally generated CA to allow request transformation while keeping Claude Code's internal features (like Remote Control) active.
Who it’s for
Developers using Claude Code who are experiencing high token costs, low cache-hit rates in long sessions, or those who are under strict API quota pressure.
Highlights
- Cache Optimization: Increases cache hit rates (e.g., from 82.3% to 95.5% in some tests).
- Transparent Integration: Works with all Claude Code versions, including the Bun binary.
- Remote Control Support: Forward-proxy mode allows the use of advanced Claude Code features that are otherwise disabled by custom base URLs.
- Observability: Includes tools to measure cache health via session transcripts before installation.
- ListNode: Idempotent transformations that do not modify the actual conversation content.
Related
- Dispatch
- Project
- Dispatch
- Project
- Project