Skip to content

user-prompt-hook's per-turn timestamp defeats prompt prefix caching — add a toggle or drop the clock #301

Closed

Description

@jackneil

Problem

scripts/user-prompt-hook.sh prints [$(date '+%H:%M %Z') — $(whoami)] (or the — ${CTX_PCT}% variant) to stdout on every UserPromptSubmit — currently lines ~156-158 at HEAD:

_REMEMBER_NOW=$(_remember_date '+%H:%M %Z')
TIMESTAMP="[$_REMEMBER_NOW — $_REMEMBER_WHO — ${CTX_PCT}%]"

Claude Code injects hook stdout into the model prompt as UserPromptSubmit hook success: [13:05 EDT — jack.neil]. Prompt prefix caches — Anthropic's server-side prompt caching and self-hosted gateways alike — match byte-for-byte from the front, so a wall-clock stamp inside the prompt forces re-prefill of everything positioned after it whenever the minute ticks over between turns or sessions.

Measured impact (2026-08-03, self-hosted DeepSeek-V4 gateway, ~62K-token Claude Code openers): this line was one of two volatile byte sources capping cross-session prefix reuse; on large local models the re-prefill it triggers costs real minutes per day. Because there's no config toggle, gateway operators end up regex-rewriting the line in flight, which is fragile for everyone.

Request

Any of these would fix it cleanly:

  1. A config toggle to suppress the stamp entirely, or
  2. Emit it without the clock — [$(whoami)] and the context-percentage warning are the useful parts and are byte-stable between turns (the CTX_PCT warning could stay threshold-gated as today, so it only appears when it changes behavior anyway), or
  3. Emit the clock only when it materially changes (e.g. hour granularity).

Happy to PR whichever shape you prefer.

Related: #227 touches the same hook for spawn-cost reasons; if that lands a rewrite, this would be a natural rider.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions