Skip to content

Remember across sessions whether a fork's change of effort keeps the prompt cache #5906

Closed

Description

@max-sixty

What happens

Leaf learns whether a fork at another effort than the session's keeps the
prompt cache from each process's first turn-end check: once one writes more
than it reads, later forks run at the session's effort (runFork in
hooks/claude-code.ts). The answer is lost when the process ends. So on a
backend without per-message effort, such as Vertex, every start or resume of a
session pays one rewrite of the conversation to learn it again: at 300k tokens,
$3.00 on Fable 5.2 and $1.50 on Opus 5.5.

Nothing tells a plugin the answer ahead of the fork. Claude Code 2.1.321's
plugin API has no query for it: the doc on ModelForkRequest.effort says only
that a level other than the session's costs a cache write of the whole
conversation where the model doesn't take effort per message. Reading the
provider variables (CLAUDE_CODE_USE_VERTEX and the like) to decide would copy
Claude Code's own gate, and can't see a proxy that drops per-message effort or
a model without it. The fork's usage shows every cause, which is why the
check reads it.

What I'd like

Keep the answer the usage gave in $.store, so it is learned once per
backend rather than once per process:

  • Key it by what the answer depends on: the model, and the variables that pick
    the route (CLAUDE_CODE_USE_*, ANTHROPIC_BASE_URL,
    ANTHROPIC_VERTEX_BASE_URL, CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS). They
    are read through $.env.get to name the backend, not to decide for it.
  • Where the stored answer is that a change of effort costs the cache, fork at
    the session's effort from the first fork.
  • Let the answer lapse after some days, and ask at low again while a new
    session's conversation is still small, so a backend that gains per-message
    effort is found again for cents.
  • Count a check as a rewrite only when the main thread's last request began
    within the cache's lifetime. An entry that expired reads the same in usage,
    and a stored answer would hold that mistake for days.

Seen on leaf c0ff621.

This was written by Claude Code on behalf of max-sixty

Activity

  1. added
    enhancement
    on Nov 12, 2026
  2. leaf-agent commented on Nov 12, 2026

    @leaf-agent
    Collaborator

    I've opened #5907 to do this. It isn't merged yet; its CI and landing are left to tend-land.

    A turn-end check's usage now stores the answer in $.store. The key is the model plus the route variables listed in the issue (and the other CLAUDE_CODE_USE_* and ANTHROPIC_*_BASE_URL names Claude Code reads), and those variables only name the backend. Once a rewrite is stored, every fork on that backend goes at the session's effort from its first.

    After seven days the stored answer lapses, and a check in a conversation of at most 20 messages asks at low again; if the cache held, the answer is dropped. A check counts only when the main thread's last request began within five minutes. The tests cover a later session, a different route, a fresh answer, a lapsed one in a small and a large conversation, and a cold cache. Four of these five cases fail on the old module.

    #5905 merged while this was in progress, so #5907 also removes its gate on CLAUDE_CODE_USE_VERTEX and CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS, as this issue asks. On Vertex, the first session's first check now asks at low once more before the answer is stored. The seven-day, 20-message and five-minute thresholds are my choices, and the PR description says why. Message count stands in for conversation size because the module sees no token count before it forks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions