claude-code-cache-fix 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/preload.mjs +8 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-cache-fix",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Fixes prompt cache regression in Claude Code that causes up to 20x cost increase on resumed sessions",
5
5
  "type": "module",
6
6
  "exports": "./preload.mjs",
package/preload.mjs CHANGED
@@ -752,9 +752,10 @@ function normalizeToolUseInputsInBody(body) {
752
752
  //
753
753
  // This sticky extension maintains per-session state tracking where markers
754
754
  // have appeared in prior turns, and reinstates them on future turns as
755
- // additive preservation. Up to 3 historical message-level markers are
755
+ // additive preservation. Up to 2 historical message-level markers are
756
756
  // tracked (Anthropic's hard limit is 4 cache_control markers total — 1 for
757
- // system[2] + 3 for message-level breakpoints). When a historical position
757
+ // system[2] + 1 canonical from cache_control_normalize + 2 historical from
758
+ // sticky = 4). When a historical position
758
759
  // would exceed the cap, the oldest tracked entry is dropped (LRU).
759
760
  //
760
761
  // Messages are identified by a stable hash so that compaction rewrites /
@@ -772,7 +773,10 @@ function normalizeToolUseInputsInBody(body) {
772
773
  // --------------------------------------------------------------------------
773
774
 
774
775
  const CACHE_CONTROL_STICKY_DIR = join(homedir(), ".claude", "cache-fix-state");
775
- const CACHE_CONTROL_STICKY_MAX_POSITIONS = 3;
776
+ // Anthropic hard limit: 4 cache_control markers total per request.
777
+ // CC uses 1 on system[2] + cache_control_normalize places 1 on last user msg = 2 reserved.
778
+ // Sticky can use at most 2 historical positions to stay within the 4-marker cap.
779
+ const CACHE_CONTROL_STICKY_MAX_POSITIONS = 2;
776
780
  const CACHE_CONTROL_STICKY_DEFAULT_MARKER = { type: "ephemeral", ttl: "1h" };
777
781
 
778
782
  /**
@@ -2354,7 +2358,7 @@ globalThis.fetch = async function (url, options) {
2354
2358
  // the tail of each new user turn, the previous position loses the ~43
2355
2359
  // bytes of cache_control framing — a tail-of-message byte drift that
2356
2360
  // breaks every downstream cached block. This extension tracks marker
2357
- // positions by stable message-hash across turns (up to 3) and re-adds
2361
+ // positions by stable message-hash across turns (up to 2) and re-adds
2358
2362
  // them on future bodies. Runs AFTER cache_control_normalize (when
2359
2363
  // present) so normalize pins the canonical tail-marker first and
2360
2364
  // sticky re-adds the historical ones. State file is per-project at