claude-code - 💡(How to fix) Fix Feature request: Let users disable prompt caching for prompt hooks, especially Stop hooks [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48240Fetched 2026-04-15 06:29:15
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×3renamed ×2

Root Cause

  • Cost: Cache writes cost 25% more than base input tokens. If the cache never gets a read hit, users pay more than without caching.
  • Latency: No benefit from caching if the cache always expires between invocations.
  • User control: Users know their hook invocation patterns better than the system — let them opt out when caching is counterproductive.

Code Example

{
  "hooks": {
    "Stop": [
      {
        "type": "prompt",
        "prompt": "Review the changes made...",
        "cache": false
      }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Feature Request

Problem

Prompt hooks (PreToolUse, PostToolUse, Stop) execute with unpredictable timing gaps. For hooks like Stop hooks, the interval between invocations can easily exceed the 5-minute prompt cache write TTL. This means:

  1. The prompt gets cached on first hook invocation (paying the cache write cost)
  2. By next invocation, the cache has expired
  3. The prompt gets re-cached again (paying the write cost again)
  4. Repeat — effectively paying cache write overhead every time with zero cache read benefit

Proposed Solution

Add a configuration option (per-hook or global) to disable prompt caching for prompt hooks. For example, in hook configuration:

{
  "hooks": {
    "Stop": [
      {
        "type": "prompt",
        "prompt": "Review the changes made...",
        "cache": false
      }
    ]
  }
}

Why This Matters

  • Cost: Cache writes cost 25% more than base input tokens. If the cache never gets a read hit, users pay more than without caching.
  • Latency: No benefit from caching if the cache always expires between invocations.
  • User control: Users know their hook invocation patterns better than the system — let them opt out when caching is counterproductive.

Additional Context

This is most relevant for:

  • Stop hooks (fire only when the agent stops, which can be minutes apart). Unused cache writes are especially expensive for Stop hooks that verify the whole session (e.g. check that outcome has been achieved, check that the whole plan has been executed correctly).
  • Any hook with prompts that are invoked infrequently relative to the 5-minute cache TTL

extent analysis

TL;DR

Disable prompt caching for prompt hooks with unpredictable timing gaps by adding a configuration option to prevent unnecessary cache writes.

Guidance

  • Identify hooks with invocation patterns that exceed the 5-minute prompt cache write TTL, such as Stop hooks or infrequently invoked hooks.
  • Consider adding a cache configuration option to hook configurations, set to false, to opt out of caching for specific hooks.
  • Evaluate the cost and latency benefits of disabling caching for these hooks, weighing the trade-offs between cache write overhead and potential read benefits.
  • Review hook invocation patterns and adjust caching configurations accordingly to minimize unnecessary cache writes.

Example

{
  "hooks": {
    "Stop": [
      {
        "type": "prompt",
        "prompt": "Review the changes made...",
        "cache": false
      }
    ]
  }
}

Notes

The proposed solution assumes that users have knowledge of their hook invocation patterns and can make informed decisions about caching. The effectiveness of this solution may vary depending on the specific use case and hook configuration.

Recommendation

Apply workaround: Add a cache configuration option to hook configurations to disable prompt caching for hooks with unpredictable timing gaps, as this allows users to opt out of caching when it is counterproductive.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING