Skip to content

cache-tax 1.0.2: price the carried summary after a compaction - #62

Merged
karanb192 merged 1 commit into
mainfrom
cache-tax-compact-boundary
Sep 15, 2026
Merged

karanb192 merged 1 commit into
mainfrom
cache-tax-compact-boundary

Conversation

@karanb192

Copy link
Copy Markdown
Owner

Summary

  • readLastUsage now notices a compact_boundary system row that is newer than the last usage block. Compaction writes that row and no usage row, so before this the status line, card, guard and resume fallback all kept pricing the pre-compaction context.
  • After a compaction the state is compacted: context is compactMetadata.postTokens, the cost is a floor at the 1h write rate, lapsed is false. Guard and resume stay silent; status line reads cache reset by /compact · 17k carried · next msg writes ≥ $0.34 (or auto-compact); the card explains the reset. A usage row newer than the boundary takes over, so the state heals on the first real turn.
  • Six new tests (32 in the file, 1928 repo-wide), version 1.0.2, README updated.

Details

On a real 562k session, /compact at 19:42 IST left the row at LAPSED 5h20m ago · next msg re-writes 562k = $11.23 while the context bar read 0%. The first message after that compaction wrote 39,967 tokens ($0.80) against a 30k cache read. Replaying 1.0.1 on that transcript truncated at the boundary row, in CACHE_TAX_BLOCK=1 mode, refuses the prompt with exit 2 for $11.23; 1.0.2 exits 0 and prints nothing.

parseBoundaryLine reads type: system, subtype: compact_boundary and its compactMetadata (trigger, preTokens, postTokens). All 91 boundary rows on this machine carry postTokens; 89 are manual, 2 auto. The block before the boundary is kept only for the model, so pricing still works. A boundary with no usage row before it renders next msg writes the summary fresh.

README: the slash-command paragraph now says what the row shows after a compaction; Limits gains two bullets, the floor (system prompt and tools are not in the transcript) and the fact that the compaction request itself re-sends the whole context and is not written to the transcript, so /clear plus a handoff note remains the cheap exit from a cold cache. The old "or a compaction" clause in the newest-turn bullet is gone because it is now handled.

Test plan

  • node --test plugins/cache-tax/tests/cache-tax.test.js 32/32
  • npm test 1928/1928
  • Real transcript truncated at its boundary row: 1.0.1 prints LAPSED ... 562k = $11.23 and blocks (exit 2); 1.0.2 prints cache reset by /compact · 17k carried · next msg writes ≥ $0.34 and exits 0
  • After merge: claude plugin update cache-tax@claude-code-hooks, then /compact in a live session and check the 🧊 row before the first new turn

@karanb192
karanb192 merged commit 218d76c into main Sep 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant