Conversation
…l CC shape) Official Claude Code ends requests on role=system turns (the live <total_tokens> counter) and replays historical system turns unchanged. liftTrailingSystemMessages moved that live block into system[], which sits before every message breakpoint, so any volatile text there invalidated the whole cached prefix. Keep the official shape on models that support mid-conversation-system, fall back to lift+pin on Haiku, and keep KIN_CLI_HOP_SYSTEM_MODE=lift|fold as an escape hatch.
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
role=systemturns intosystem[]on non-Haiku models. They stay at the tail ofmessages, which is the shape official Claude Code sends.system[]is processed before every message breakpoint. Moving per-turn text (not only<total_tokens>) there invalidates the whole cached prefix, so the live block belongs behind the read boundary: replayed history stays byte-stable and each turn reads the previous prefix.mid-conversation-systembeta and 400s onrole=system, so it keeps the existingliftTrailingSystemMessages+ pin path automatically.KIN_CLI_HOP_SYSTEM_MODE=liftrestores the old behavior;KIN_CLI_HOP_SYSTEM_MODE=foldkeeps the deterministic fold fallback.messagesshape changes. Breakpoints, TTLs, betas and identity handling are untouched.Official Claude Code 2.1.278 behavior
request_log_debug, 392 messages) cyclesuser, system, assistantand ends onrole=systemcarrying the live<total_tokens>N tokens left</total_tokens>. Historical system turns replay their old values (14971564 / 14950836 / … / 14909247).messages[].role=systemis accepted with themid-conversation-system-2026-04-07beta. vm2api already carries this constant (anthropic-policy.mjs) and uses the same mechanism on the unofficial persona path (insertMidConversationSystem).HAIKU_BETA_HEADERomits the beta and Anthropic returns400 role 'system' is not supported on this model.tools → system → messages(see [Bug] 入站带 ttl=1h 时 cli-hop 多轮请求 400(订阅客户端按入口默认 1h / API key 开 ENABLE_PROMPT_CACHING_1H),且 cli-hop 无法使用 1h 缓存 #46), so the volatile counter must sit after the read boundary instead of insystem[].Results
A/B on sonnet-5, replaying the official shape with a per-turn text tail:
lift(current)cache_creation=38231,cache_read=0(full rewrite)officialcache_creation=14841,cache_read=23391(reads the previous turn)Live replays of the same shape:
<total_tokens>tailcache_read23389 → 38228 → 53067; ordinary live-text tail 23391 → 38232; Haiku lift+pin path 8259 → 15874 → 23489.Test plan
node --test test/unit/cli-hop-body.test.mjs— 28/28 (5 new cases; two existing lift assertions now pinKIN_CLI_HOP_SYSTEM_MODE=lift, assertions unchanged)node scripts/run-isolated-tests.mjs test/unit .test.mjsKIN_CLI_HOP_SYSTEM_MODE=liftandofficial; confirmcache_readmoves from 0 to the previous turn's full prefixRelated: #46.