Skip to content

Claude PR reviewer reloads the full coding-standards ruleset every run instead of caching it #93665

Description

@kacper-mikolajczak

Problem

The Claude PR reviewer dispatches a code-inline-reviewer subagent whose definition tells it to Glob and Read every coding-standards rule file (~25K tokens across 28 files) on every run. Those reads land in the conversation (message) layer, beneath a system prompt that embeds per-checkout sections (cwd, git state, OS).

Prompt-cache hits require a byte-identical prefix, and the message layer sits below that ever-changing prefix, so the ruleset is never a stable cacheable prefix. As a result it is re-paid at the cache-write rate (1.25x) on every PR run rather than read from cache (0.1x), and ~29 extra tool round-trips are spent each run just loading the rules.

Solution

Move the ruleset into the reviewer's system prompt as a deterministic, byte-stable prefix:

  • A small deterministic script concatenates the reviewer instructions and every rule file into one system-prompt file (stable order, fixed separators - so identical bytes across runs, which is what prompt-cache prefix hits require), supplied to the reviewer via --append-system-prompt-file.
  • Add --exclude-dynamic-system-prompt-sections so the per-checkout system-prompt sections (cwd, git, OS) stop invalidating the prefix.
  • Run the reviewer as a single agent so the rules sit in its own system prompt.

Net effect: the rules load once per run instead of via ~29 tool calls, and the now byte-stable prefix becomes eligible for cross-run cache reads (0.1x) instead of writes (1.25x) when runs fall within the cache TTL. Reviewer behavior is unchanged - the same rules are enforced.

Implemented in #93661.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions