Repository navigation
prompt_stamp: make the injected UserPromptSubmit line the user's choice - #304
Merged
Merged
Conversation
…hoice (#301) user-prompt-hook.sh has always printed [14:30 CEST — jack — 45%] into the model's context on every UserPromptSubmit, with no way to turn it down. The reporter's workaround is rewriting this hook's stdout in flight with a regex. Three modes, default byte-for-byte unchanged: full (default) [14:30 CEST — jack — 45%] stable [jack] + the >=95 context warning off nothing, warning included An unrecognised value reads as full. The issue's option 2 (drop the clock, keep user + percentage) does not fix the reported problem: the percentage climbs on every prompt for anyone running the status line, which the hook's own comment records as the common case. stable drops both volatile fields. Hour granularity is declined — still volatile, plus a third timestamp format to hold byte-identical across bash 3.2's date and 4.2's printf '%(...)T'. No process added. Resolved by log.sh off the already-built config table and replayed by lib-env-cache.sh, the #227 design. Measured on /bin/bash 3.2.57, warm run x5: full 1 spawn (unchanged), stable and off 0. A cache written before the key existed is refused rather than defaulted — the env cache is invalidated by config mtime, never by plugin version. The reporter's prefix-cache measurement is theirs and is not claimed here. Co-Authored-By: Max <noreply>
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.
Closes #301.
user-prompt-hook.shprints[HH:MM TZ — user — 45%]to stdout on everyUserPromptSubmit, and Claude Code injects that into the model's context. The reporter asked for a way to stop emitting bytes that change between turns for reasons unrelated to what was typed.What ships
A
prompt_stampconfig key, three values:full[14:30 CEST — jack — 45%]stable[jack]>= 95context warningoffAn unrecognised value reads as
full: a typo must not silently delete the clock.Resolved in
log.shbesideREMEMBER_TZ, off the already-built config table, carried on the env cache and replayed by the hook — the #227 design, so the hook still resolves nothing itself.Why not just drop the clock
The issue proposes keeping
[$(whoami)]and the context percentage, on the grounds that both are byte-stable between turns. The username is; the percentage is not.CTX_PCTclimbs on every prompt for anyone running the status line — which the hook's own comment at line 141 records as the common case, not the rare one. Dropping only the clock would ship the same defect under a shorter name.stabledrops both.Hour granularity (the issue's option 3) was declined for the same reason — still volatile, just slower — and because it would introduce a third timestamp format that has to stay byte-identical across bash 3.2's
dateand 4.2'sprintf '%(...)T', a cost #227 already paid once.Why
stablekeeps the warning andoffdoes notThat is the entire difference between the two modes. The
>= 95warning is threshold-gated, so it changes bytes only when it changes behaviour, and it is the only line here anybody acts on. Butoffhas to mean off: a user who asked for silence and got a surprise line near the context limit is a user back to filtering our stdout, which is what this option exists to retire.On the reported mechanism
The measurement in the issue is the reporter's, from a self-hosted gateway, and this PR does not rest on it.
UserPromptSubmitoutput lands at the tail of the prompt and is frozen into history once emitted; whether that defeats a given gateway's prefix cache is a property of that gateway. The argument for shipping is the interface one: a hook should not force operators to regex-rewrite its stdout in flight.Cost
No fork added; two removed. Measured under
/bin/bash3.2.57 with PATH-shim spawn counting, warm ×5:fulland default = 1 (date, unchanged),stableandoff= 0. Cold 10 → 9. The extraconfigread costs nothing measurable — the cold count forfullis identical to the untouched default.Cache versioning
An env cache written before this key existed is refused, not defaulted. Invalidation is by config mtime and never by plugin version, so reading the absence of the key as "the default" would serve a resolution that never considered the option. Cost is one slow prompt, once, at upgrade.
Tests
TDD. RED, against zero implementation:
The 4 green are deliberate — three default-preservation assertions and the spawn budget, which can only ever fail by this change moving something it promised not to move. Everything asserting new behaviour was red.
GREEN:
14 passed in 5.32s. Full suite, run twice:1445 passed, 43 skipped, coverage 94.26%.The tests drive the real script through a subprocess and assert its stdout bytes, including a test that the default is byte-identical and one that
stablerenders the same under different context percentages.Docs
README.mdconfig table,config.example.json(value + annotation),CHANGELOG.md.