Repository navigation
Description
Symptom
Every prompt submission blocks for a measured p50 of 8.7s, max 30.0s, with 6 hard timeouts, on Windows 11 ARM64 (Git Bash, under QEMU). Aggregated from 256 UserPromptSubmit hook records across 50 sessions over 5.7 days:
| hook | runs | p50 | max | timed out |
|---|---|---|---|---|
UserPromptSubmit |
256 | 8718ms | 30003ms | 6 |
That is ~37 minutes of blocking wait across those 256 prompts. Claude Code's guidance is >2s is a slow hook for per-prompt events, so this is ~4x over.
Root cause
scripts/user-prompt-hook.sh sources three libraries to print a timestamp:
REMEMBER_PATHS_SOFT_FAIL=1 source "$(dirname "$0")/resolve-paths.sh" || exit 0
source "$(dirname "$0")/bootstrap-dirs.sh"
source "$(dirname "$0")/log.sh" 2>/dev/nullTraced with bash -x, one invocation of the hook makes 27 external process spawns. Cumulative cost, isolated by sourcing each library in turn:
| sourced through | cumulative |
|---|---|
resolve-paths.sh |
1862ms |
+ bootstrap-dirs.sh |
8372ms |
+ log.sh |
12584ms |
bootstrap-dirs.sh is the biggest single contributor (~6.5s), almost entirely via lib-memory-dir.sh, which on every prompt runs git -C "$proj" rev-parse --path-format=absolute ... plus several jq config merges to re-resolve REMEMBER_DIR.
Measured per-spawn cost on this platform, which is what turns a benign design into a blocking one:
git rev-parse --path-format=absolute --git-common-dir 194ms / 190ms / 234ms
jq (lookup) ~200ms
whoami 716ms
date 813ms
On a normal Linux box 27 spawns is ~300ms and nobody notices. At 150-800ms per spawn it is ~8s. The design is fine; the platform assumption underneath it isn't.
A red herring, ruled out by measurement: jq was not installed on this box, so lib-memory-dir.sh was taking its documented Python fallback for the config deep-merge (# No jq — do the same deep-merge in Python instead of silently dropping). That looked like the obvious aggravating factor. It is not. Installing jq 1.8.2 moved the shared-library prefix from a median of 3784ms to 3401ms across 7 runs each — overlapping distributions, a worse max, i.e. noise. Bare spawn cost explains why: python -c pass is 64ms here and the (amd64, emulated) jq is 81ms, so the fallback was never the expensive part. Please don't spend effort on the jq path on account of this report.
The stable, reproducible cost centre is detect-tools.sh at ~1.0-1.3s, consistent across all 14 runs above and independent of jq. user-prompt-hook.sh notably does not source it (# detect-tools.sh is deliberately NOT sourced here), which is the strongest evidence that the hook does not need the heavy chain at all.
What the hook actually needs
Per its own header, the hook prints [HH:MM TZ — username], a context-percent warning at >=95%, and a rare capture-gap notice. Nothing it emits requires the resolved paths, the directory bootstrap, or the logger:
dispatch "after_user_prompt"is a no-op —hooks.d/after_user_prompt/does not exist in the distribution, sodispatch()returns at[ -d "$event_dir" ] || return 0._remember_datefalls through to plaindatewheneverREMEMBER_TZis unset, which is the default.- The directory tree that
bootstrap-dirs.shguarantees is only needed by hooks that write memory —SessionStartandPostToolUse— not by this one. - The only genuine dependency is
$REMEMBER_DIRfor the capture-gap notice path, which fires rarely.
Suggested fix
Three changes, in rough order of payoff:
- Don't source the heavy libraries for the common path. Compute the timestamp with bash's
printf '%(...)T'builtin (bash >= 4.2) and take the username from${USER:-$USERNAME}. Both are spawn-free and byte-identical in output — verified: builtin anddate/whoamiboth produce[14:21 SEAST — mar]. - Resolve
REMEMBER_DIRlazily, only when a capture-gap notice actually needs delivering, rather than on every prompt. - Cache the resolved
REMEMBER_DIR(and the merged config) per project for the session's lifetime. Thegit rev-parseanswer cannot change mid-session, and this would also speed upSessionStartandPostToolUse, which pay the same resolution cost.
As a local workaround I replaced the hook with a builtin-only version preserving all four output paths (plain, context-percent, >=95% warning, capture-gap notice + systemMessage JSON) and the unconditional exit 0. Result: 27 spawns -> 0, and ~8.7s -> ~0.7s, where the remaining 0.7s is bash's own startup. Happy to open a PR against scripts/user-prompt-hook.sh if the approach looks right to you.
Note on why this one matters more than the timing suggests
UserPromptSubmit is the one event where a non-zero exit doesn't merely error — it blocks and erases what the user typed. The current script is careful about that (the _JSON-built-before-printing dance guards it explicitly), but it reaches that careful ending after 27 spawns and three sourced libraries, any of which is an opportunity to fail on a slow or unusual platform. Six of the 256 runs above hit the timeout outright.
Environment
- Windows 11 Pro ARM64 (10.0.26200), under QEMU
- Git Bash, bash 5.2.37
remember0.9.0, installed via theclaude-plugins-officialmarketplace- Claude Code 2.1.220
- Measured both without
jq(Python fallback active) and withjq1.8.2 installed — see the ruled-out section above; it makes no material difference
Related: the same prefix is paid per tool call
post-tool-hook.sh sources the same chain plus detect-tools.sh on every tool call, so the 3.4-3.8s prefix above is not confined to prompt submission. I could not cleanly attribute a per-call figure — successful silent PostToolUse runs are not persisted to transcripts, and manual invocation measured 6.5s / 11.6s / 31.9s but almost certainly included a real save-session.sh fork past its 120s cooldown, so I am not reporting that as the per-call cost. Flagging it as worth your own measurement rather than as a claim: caching the resolved paths and tool detection per session (suggestion 3 above) would pay off there far more than it does here.
Activity
fix(tests): keep the clock interceptable where tests fake time (#227)
fix(prompt-hook): stop spawning 19 processes to print a timestamp (#227…
fdaviddpt commentedon Jul 30, 2026
Fixed and released in v0.10.0 (#229). Thank you — this report did most of the diagnosis, and two parts of it changed what we built.
What shipped
Two changes, and the shape of both was decided by what must not break.
_remember_datemoved to a newscripts/lib-clock.shand uses theprintf '%(FMT)T'builtin — withdateas a supported path, not a legacy one. Your fix #1 was right about the builtin and we could not take it alone: stock macOS ships bash 3.2.57, where that builtin does not exist and a builtin-only rewrite prints a literal%(%H:%M %Z)T. So the two implementations are held byte-identical by a test that runs both and compares (retrying across a minute boundary), andREMEMBER_NO_PRINTF_T=1makes bash-5 CI exercise the 3.2 path.%-Iand%sroute todatedeliberately — those are GNUdateextensions, and a literal%sreaching$(( ))is an arithmetic error rather than a wrong number.The resolution is cached rather than repeated, in
scripts/lib-env-cache.sh. It never computes anything — it replays what the one resolver produced, or declines and the caller runs the real chain. That distinction is deliberate: a hook that re-derivedREMEMBER_DIRits own way once resolved a different store than every other hook (#158), which is split-brain memory rather than a clean failure. Invalidation is by mtime against all three config layers plusCLAUDE_PROJECT_DIR/CLAUDE_PLUGIN_ROOT/HOME; every check is a bash builtin, because a validation step that forked would spend the savings it exists to protect.REMEMBER_ENV_CACHE=0disables it.Two of your claims did not survive, and it is worth saying which
You framed both as suggestions rather than findings, which is why chasing them was cheap — but the record should be accurate:
$REMEMBER_DIRfor the capture-gap notice, which fires rarely." True of the purpose, false of the cost. The notice lives at$REMEMBER_DIR/tmp/capture-gap-notice, so the[ -f ]runs on every prompt — fix Fix PROJECT_DIR path traversal when installed via plugin cache #2 as written is not implementable, because you cannot know whether a notice is pending without first knowing where the store is. That is why the cache (your fix: export CLAUDE_PROJECT_DIR in hooks for background subprocesses #3) turned out to be load-bearing rather than an optimisation: fix save-session.sh and run-consolidation.sh fail when installed via plugin cache (PROJECT_DIR path traversal) #1 alone removes 3 of 19 spawns, ~2.3s of your 8.7s, leaving ~5s p50 — still 2.5× over the guidance, same hook, still blocking.REMEMBER_TZfromconfig.json, whose third layer lives insideREMEMBER_DIR. Four existing tests pin it; a hook that skipped that read would print system local time for anyone who had configured a timezone.Your 19 vs 27 was re-derived rather than repeated: 19 with a PATH shim on macOS. The gap is platform — Git Bash forks
cygpathin the slug and the projects dir, and withjqabsent both thedata_dirread and the config merge take their fallbacks. So the ratio is what carries across, not the absolute number.And your jq paragraph saved real time. Ruling out your own most plausible aggravating factor — installing
jq1.8.2 and finding the median moved 3784ms → 3401ms with overlapping distributions and a worse max — is the part of a report that usually has to be redone by whoever picks it up. It was not touched, exactly as you asked.One cost of this fix that your suggestion could not have known
A builtin is not on
PATH. So faking time by putting adateearlier inPATH— the obvious way to test anything time-dependent in a shell pipeline, and howtests/test_ndc_day_boundary.pyfakes midnight — silently stops intercepting anything on bash ≥ 4.2. The fake is not refused, it is ignored, so the test quietly asserts against the real clock. It surfaced as a red CI leg. It is now handled in the shared test-env builder rather than per test, with a lint that fails if a test shimsdatewithout namingREMEMBER_NO_PRINTF_T— and that also fails if it stops recognising how tests fakedate, so it cannot pass by finding nothing. Documented inlib-clock.shunderTHE SEAM THIS REMOVED.On your offer to open a PR
We implemented it here rather than waiting, because the report described people abandoning the plugin on Windows and the release was the blocker. That was about timing, not about the quality of your patch — your local version preserved all four output paths and the unconditional
exit 0, which is the part that matters most in this hook, and you had clearly read why that dance exists. If you want to look over what landed,scripts/lib-clock.shandscripts/lib-env-cache.share the new files and the review would be genuinely useful.Getting it
The version that matters is the one in your plugin cache, not the one in
main— the plugin is loaded from~/.claude/plugins/cache/dpt-plugins/remember/<version>/, and a cache that has not rolled still runs the old code no matter what this repository contains (that is the open half of #204). If your install has not picked up 0.10.0,FORCE_AUTOUPDATE_PLUGINS=1on a session start is what moves it.If you get a chance to re-measure on that ARM64 box, the number worth knowing is the warmed steady-state — one
dateon bash 3.2, zero on Git Bash's bash 5. If it is still seconds, something else is in that chain that we cannot see from here, and I would want to know.Left open
PostToolUseandSessionStartstill pay the same resolution prefix — filed as #230, with the two cheap behaviour-preserving wins it should start from. Not folded in here because it carries lifetime and cleanup risk this change does not.test(spawns): one counted-command list, shared by both budget tests
perf(hooks): post-tool-hook 30 → 17 spawns per tool call (#230)
test(spawns): one counted-command list, shared by both budget tests
perf(hooks): post-tool-hook 30 → 17 spawns per tool call (#230) (#233)
feat(#226): record save.lock hold times, so the 30s timeout can be se…
Commit the now.md entry by rename, not two appends (#247) (#250)
feat(git-restore): fast-forward the memory store from its backup remo…
feat(prompt-hook): prompt_stamp — make the injected line the user's c…
perf(post-tool): give PostToolUse the #227 env-cache fast path (#352)