AI Skill Hub 强烈推荐:Claude代码缓存修复工具 是一款优质的AI工具。AI 综合评分 8.2 分,在同类工具中表现稳健。如果你正在寻找可靠的AI工具解决方案,这是一个值得深入了解的选择。
针对Claude Code提示词缓存回归问题的开源修复方案,可降低API成本20倍。通过API代理机制优化缓存策略,适合使用Claude Code进行开发的工程师和企业降低成本。
Claude代码缓存修复工具 是一款基于 JavaScript 开发的开源工具,专注于 缓存优化、成本控制、Claude API 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
针对Claude Code提示词缓存回归问题的开源修复方案,可降低API成本20倍。通过API代理机制优化缓存策略,适合使用Claude Code进行开发的工程师和企业降低成本。
Claude代码缓存修复工具 是一款基于 JavaScript 开发的开源工具,专注于 缓存优化、成本控制、Claude API 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 方式一:npm 全局安装 npm install -g claude-code-cache-fix # 方式二:npx 直接运行(无需安装) npx claude-code-cache-fix --help # 方式三:项目依赖安装 npm install claude-code-cache-fix # 方式四:从源码运行 git clone https://github.com/cnighswonger/claude-code-cache-fix cd claude-code-cache-fix npm install npm start
# 命令行使用
claude-code-cache-fix --help
# 基本用法
claude-code-cache-fix [options] <input>
# Node.js 代码中使用
const claude_code_cache_fix = require('claude-code-cache-fix');
const result = await claude_code_cache_fix.run(options);
console.log(result);
# claude-code-cache-fix 配置说明 # 查看配置选项 claude-code-cache-fix --config-example > config.yml # 常见配置项 # output_dir: ./output # log_level: info # workers: 4 # 环境变量(覆盖配置文件) export CLAUDE_CODE_CACHE_FIX_CONFIG="/path/to/config.yml"
English | 中文 | 한국어 | Português
Cache optimization proxy for Claude Code. Fixes prompt cache bugs that cause excessive quota burn, stabilizes the request prefix, and monitors for silent regressions. Works with all CC versions including the v2.1.113+ Bun binary.
v3.0.3 — Local HTTP proxy with 7 hot-reloadable extensions. A/B tested on v2.1.117: 95.5% cache hit rate through proxy vs 82.3% direct on first warm turn. Full release notes →
Opus 4.7 advisory: Metered data shows 4.7 burns Q5h quota at ~2.4x the rate of 4.6 for equivalent visible token counts (independently confirmed by @ArkNill). Two factors: a new tokenizer (up to 35% more tokens, documented) and adaptive thinking overhead (~105%, not documented in usage response). The Q5h impact compounds into Q7d — the weekly quota ceiling that most heavy users will hit first. Workaround: CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1 reduces burn by ~3.3x but may reduce quality on complex tasks. See Discussion #25 (initial observation) and Discussion #42 (controlled A/B data + Q7d analysis).
npm install -g claude-code-cache-fix
A multi-arch (amd64, arm64) container image is published to GitHub Container Registry on every release tag.
```bash docker run -d --name cache-fix-proxy \ --restart=always \ -p 9801:9801 \ ghcr.io/cnighswonger/claude-code-cache-fix:latest
mkdir -p ~/.claude/hooks
cp "$(npm root -g)/claude-code-cache-fix/tools/quota-statusline.sh" ~/.claude/hooks/
chmod +x ~/.claude/hooks/quota-statusline.sh
Add to ~/.claude/settings.json:
{
"statusLine": {
"type": "command",
"command": "~/.claude/hooks/quota-statusline.sh"
}
}
The proxy works with any CC version — Node.js or Bun binary. It sits between Claude Code and the Anthropic API, applying cache fixes as hot-reloadable extensions.
```bash
If you're on a Node.js-based CC version (v2.1.112 or earlier), the preload interceptor works without a proxy:
npm install -g claude-code-cache-fix
NODE_OPTIONS="--import claude-code-cache-fix" claude
Note: The preload does NOT work on CC v2.1.113+ (Bun binary). Use the proxy above.
See docs/preload-setup.md for wrapper scripts, shell aliases, Windows instructions, and VS Code preload-mode integration.
All proxy settings are controlled via environment variables. Set them before starting the proxy server.
| Variable | Default | Description |
|---|---|---|
CACHE_FIX_PROXY_PORT | 9801 | Listen port |
CACHE_FIX_PROXY_BIND | 127.0.0.1 | Bind address |
CACHE_FIX_PROXY_UPSTREAM | https://api.anthropic.com | Upstream URL. Change to chain another proxy (e.g. http://localhost:8080) |
CACHE_FIX_PROXY_TIMEOUT | 600000 | Request timeout in milliseconds |
CACHE_FIX_EXTENSIONS_DIR | proxy/extensions/ | Directory for extension .mjs files |
CACHE_FIX_EXTENSIONS_CONFIG | proxy/extensions.json | Extension configuration file |
CACHE_FIX_DEBUG | 0 | Enable debug logging |
The proxy honors the following environment variables when forwarding to api.anthropic.com. Behind Zscaler / Netskope / Forcepoint / Bluecoat / corporate squid, set these in the proxy's environment.
| Variable | Effect |
|---|---|
HTTPS_PROXY / HTTP_PROXY (and lowercase variants) | Routes upstream requests through the corporate HTTP CONNECT proxy. |
NO_PROXY | Comma-separated host list to bypass the proxy. Supports * and .suffix.example.com. |
CACHE_FIX_PROXY_CA_FILE | Path to a PEM file with one or more extra CA certificates (for SSL-inspecting proxies). |
NODE_EXTRA_CA_CERTS | Standard Node mechanism — also honored. |
CACHE_FIX_PROXY_REJECT_UNAUTHORIZED=0 | **Insecure escape hatch.** Disables TLS verification. Use only as a last resort while you wait for IT to provide the corp CA bundle. |
Example (Windows PowerShell):
$env:HTTPS_PROXY = 'http://proxy.corp.example:8080'
$env:NO_PROXY = 'localhost,127.0.0.1,.corp.example'
$env:CACHE_FIX_PROXY_CA_FILE = 'C:\corp\zscaler-root.pem'
node "$(npm root -g)\claude-code-cache-fix\proxy\server.mjs"
Stderr will print [upstream] using proxy http://proxy.corp.example:8080 ... on first request when the agent is wired correctly. With no proxy/CA env vars set, behavior is unchanged from earlier versions (Node default agent, system trust store).
The proxy fixes what it can fix at the request layer. A handful of CC client-side env vars and ~/.claude/settings.json knobs solve adjacent problems the proxy can't reach — silent model swaps on CC update, ambiguous model fallback, schema-strip side effects. Surfacing these here as a recommendation; users decide their own config.
These findings come from @fgrosswig's binary analysis of CC v2.1.91. Methodology is public PowerShell + ASCII string extraction; he shared the resulting punch list privately as a courtesy.
The model IDs below are illustrative — replace with your preferred main and small-fast models. The point is that pinning something explicit beats relying on CC's defaults.
{
"env": {
"CLAUDE_CODE_DISABLE_LEGACY_MODEL_REMAP": "1",
"ANTHROPIC_MODEL": "claude-opus-4-7",
"ANTHROPIC_SMALL_FAST_MODEL": "claude-haiku-4-5-20251001"
}
}
CLAUDE_CODE_DISABLE_LEGACY_MODEL_REMAP=1 — single most impactful flag. CC has a legacy code path that silently remaps your pinned model to a different one after certain version updates. Setting this to 1 disables the remap; the model you pin is the model you get. (If you don't pin, CC's defaults apply as usual.)
ANTHROPIC_MODEL — pins the primary model. Keeping this explicit means the cache prefix hash stays stable across CC version bumps that would otherwise swap your default. Adjust to whichever model you actually want.
ANTHROPIC_SMALL_FAST_MODEL — pins the side-channel "fast" model CC uses for short auxiliary calls (e.g., title generation, classification). Without an explicit pin, this can silently fall back to a different family on update.
The interceptor can rewrite Claude Code's # Output efficiency system-prompt section. Disabled by default. Enable with CACHE_FIX_OUTPUT_EFFICIENCY_REPLACEMENT. See docs/output-efficiency-prompts.md for the three known prompt variants and usage instructions.
A conditional pipeline that mirrors Anthropic's actual rules. Strictly opt-in via a single env var:
export CACHE_FIX_IMAGE_GUARD=1
When enabled, the proxy runs:
| Pass | Trigger | Action |
|---|---|---|
| **Pass 0** (legacy) | CACHE_FIX_IMAGE_KEEP_LAST=N set | Strip tool_result images from user messages older than N most recent |
| **Pass 3** | CACHE_FIX_IMAGE_PRESERVE_DETAIL=1 AND image long edge > model native cap | Lanczos resize via sharp to native cap (2576 px for Opus 4.7, 1568 px otherwise), preserve aspect ratio and media type |
| **Pass 1** | image long edge > active rejection cap | Strip and replace with forensic placeholder. Active cap = MAX_DIM if set, else 2000 px (when count > 20) or 8000 px (count ≤ 20) |
| **Pass 2** | request body exceeds CACHE_FIX_IMAGE_REQUEST_SIZE_MAX (default 30 MB) | Drop oldest images until under budget |
| **Count cap** | surviving image count > CACHE_FIX_IMAGE_COUNT_MAX (default 100) | Drop oldest images down to the cap |
Execution order: Pass 0 → Pass 3 → Pass 1 → Pass 2 → count cap. Each pass is independent — Pass 1 never resizes; Pass 3 never strips.
sharp dependencyPass 3 requires sharp for Lanczos resize. It's declared as an optional peer dependency — install separately if you want Pass 3:
npm install sharp
If sharp is missing, Pass 3 skips cleanly (telemetry records library_missing: true); Pass 1 + Pass 2 + the count cap still run.
| Env var combination | Behavior |
|---|---|
| Nothing set | No image processing (back-compat default; the extension short-circuits). |
KEEP_LAST=N only | Existing v3.2.1: count cap on tool_result images in user messages, runs first. No pipeline. |
MAX_DIM=N only | Existing v3.2.1: hard size cap, strip-only. No pipeline. |
KEEP_LAST=N + MAX_DIM=N | Existing v3.2.1 composition: KEEP_LAST runs first (drops count), then MAX_DIM runs on survivors (caps size). No pipeline, no Pass 2, no Pass 3. |
IMAGE_GUARD=1 | New pipeline: Pass 1 (conditional cap) + Pass 2 (request-size guard) + image-count cap. |
IMAGE_GUARD=1 + MAX_DIM=N | MAX_DIM overrides Pass 1's conditional cap (acts as the cap value); Pass 2 still runs. |
IMAGE_GUARD=1 + PRESERVE_DETAIL=1 | Adds Pass 3 (Lanczos resize via sharp). When sharp unavailable, falls back to strip behavior. |
IMAGE_GUARD=1 + KEEP_LAST=N | KEEP_LAST runs first as count cap (Pass 0); pipeline runs on remainder. |
IMAGE_GUARD=1 + KEEP_LAST=N + MAX_DIM=N | Three-way: KEEP_LAST runs first; pipeline runs on remainder, but MAX_DIM overrides Pass 1's conditional cap; Pass 2 still runs. |
PRESERVE_DETAIL=1 without IMAGE_GUARD=1 | Logs warning, treats as no-op. PRESERVE_DETAIL is meaningless without the pipeline running. |
| Env var | Default | Purpose |
|---|---|---|
CACHE_FIX_IMAGE_GUARD | unset | Top-level pipeline gate (=1 enables). |
CACHE_FIX_IMAGE_PRESERVE_DETAIL | unset | Enable Pass 3 Lanczos resize via sharp. |
CACHE_FIX_IMAGE_REQUEST_SIZE_MAX | 31457280 (30 MB) | Pass 2 byte budget. 2 MB headroom from Anthropic's 32 MB ceiling. |
CACHE_FIX_IMAGE_COUNT_MAX | 100 | Hard image-count cap. Set to 600 for legacy Claude 1/2.x/Instant if needed. |
export CACHE_FIX_THINKING_DISPLAY=disabled ```
The extension is default-on as of v3.6.1. The cache-prefix test measured 0% absolute drop in steady-state cache_read ratio when injection is active on Opus 4.7 (5 sequential claude -p calls per window, baseline vs injected — both windows held 1.000 cache_read ratio from call 2 onward). Adding thinking.display to the request body changes the bytes Anthropic hashes, but Anthropic's cache layer accepts and indexes the injected-prefix the same way it does any other prefix. Users who want the older "no injection" behavior (e.g. to avoid any request-body mutation at all) explicitly set CACHE_FIX_THINKING_DISPLAY=disabled.
Scoping rules baked into the extension:
model matches /^claude-opus-4-7/ — covers claude-opus-4-7 and claude-opus-4-7-1m. Sonnet 4.7 needs separate verification (the API default-flip may differ); future versions (4.8+) require an explicit cache-fix bump rather than auto-applying unverified behavior.thinking.display set (either "summarized" or "omitted"), the extension never overwrites. Explicit user choice always wins.thinking.type ∈ { "enabled", "adaptive" } — the two active modes that produce thinking blocks on Opus 4.7. Other values ("disabled", future modes) are skipped. Conservative: if Anthropic ships a new thinking type with different display semantics, we'd rather miss the fix than auto-apply incorrect behavior.| Env var | Default | Purpose |
|---|---|---|
CACHE_FIX_THINKING_DISPLAY | summarized (built-in) | One of summarized / omitted / disabled. summarized restores thinking summaries (default). omitted force-suppresses thinking blocks. disabled opts the extension out entirely. |
The VS Code extension (v0.5.0) supports both proxy and preload modes:
Proxy mode (recommended): 1. Start the proxy (see above) 2. In VS Code command palette: Claude Code Cache Fix: Enable Proxy Mode 3. Restart any active Claude Code session
Preload mode (CC ≤v2.1.112): 1. npm install -g claude-code-cache-fix 2. Download the VSIX from GitHub Releases 3. Install: code --install-extension claude-code-cache-fix-0.5.0.vsix 4. Command palette: Claude Code Cache Fix: Enable
For manual VS Code wrapper setup (without the VSIX), see docs/preload-setup.md.
实用的成本优化工具,针对Claude API缓存问题提供直接解决方案。代码质量良好,社区关注度适中,适合有Claude API成本压力的开发者。
该工具使用 NOASSERTION 协议,商用场景请仔细阅读协议条款,必要时咨询法律意见。
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
📄 NOASSERTION — 请查阅原始协议条款了解具体使用限制。
总体来看,Claude代码缓存修复工具 是一款质量优秀的AI工具,在同类工具中具备一定竞争力。AI Skill Hub 将持续追踪其更新动态,建议收藏备用,结合自身场景选择合适时机引入使用。
| 原始名称 | claude-code-cache-fix |
| Topics | 缓存优化成本控制Claude API代理工具 |
| GitHub | https://github.com/cnighswonger/claude-code-cache-fix |
| License | NOASSERTION |
| 语言 | JavaScript |
收录时间:2026-06-04 · 更新时间:2026-06-04 · License:NOASSERTION · AI Skill Hub 不对第三方内容的准确性作法律背书。