Skip to content

feat: name the silent no-op, and a doctor to ask about it (#200) - #201

Merged
fdaviddpt merged 3 commits into
mainfrom
max/detect-silent-noop-and-doctor
Jul 27, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
max/detect-silent-noop-and-doctor

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #200. Reported by @fmanimashaun.

The failure

Claude Code reads hook registrations at session start, so a plugin enabled part-way through a session has none of them wired for the rest of it. PostToolUse never fires, nothing is captured, and hook-errors.log stays empty because nothing failed. The reporter lost a day to it and found one session-start line as the only trace.

The plugin was working exactly as designed. It simply was not wired in — and there was no way for a user to discover that.

What can't be done, and why

Suggestion 1 in the issue was to have SessionStart check whether PostToolUse is registered. That is not possible, and it's worth recording so nobody re-attempts it:

  • No introspection exists. No env var, no file, no CLI subcommand exposes which hooks are active. /hooks is a read-only UI a hook script cannot invoke.
  • SessionStart cannot tell why it fired. Its source field is only startup|resume|clear|compact|fork. A plugin-enable is indistinguishable from a fresh start.

So the gap is undetectable while it is happening. What remains is detecting it afterwards.

What is done

Detection. The signature is exact: a session where SessionStart ran and PostToolUse never did. PostToolUse records the session id it saw; the next SessionStart compares that against the previous session's id and, if that session used tools at all, leaves a notice.

The zero-tool guard is load-bearing: a conversation with no tool calls produces no PostToolUse either, and warning about it would be crying wolf.

Identity rather than timestamps — the first cut compared mtimes and a test caught it calling a healthy session broken, because bash 3.2's -nt resolves to the second and the sign of life landed inside the same one as the stamp.

Delivery. Through systemMessage, the only hook output the human sees. additionalContext reaches the model alone, which is the shape of the original bug and would have been the wrong channel. The ordinary path still prints exactly what it always did; only the notice case switches to JSON, and a test pins that so context injection cannot change silently.

/remember:doctor. Resolved paths, detected tools, storage mode, whether the session dir Claude Code created matches the computed slug (#144), the last successful save, and whether PostToolUse has ever fired. OK/WARN/FAIL per line, one VERDICT.

README. A restart note in the install steps, and a section on the diagnostics command.

Two bugs its own tests found

  1. An install predating the new capture-alive marker was reported as FAIL PostToolUse has never fired — while the next line printed a successful save. Self-contradictory, and it would have sent every existing working user off to restart for nothing.
  2. The slug helpers are not guaranteed to be defined when lib-memory-dir.sh returns early, so the report printed an empty slug as OK and skipped the session_dir_slug() mis-slugs non-ASCII (CJK) paths under byte-wise sed, silently disabling saves #144 check entirely. It now says it could not check, which is not the same as no problem — that distinction being the entire subject of this issue.

Tests

tests/test_capture_gap_notice.py (8) and tests/test_doctor.py (5). Verified against the pre-fix scripts: the four asserting new behaviour fail without it. The rest are false-alarm guards protecting the new logic — one of which caught the mtime bug above.

Full suite: 880 passed, 41 skipped.

Not addressed here

/reload-plugins exists but the docs do not say whether it re-registers hooks. If it does, the remedy is a reload rather than a restart and the README should say so. Worth raising upstream either way — "enabling a plugin silently does nothing until restart" is arguably a Claude Code issue, not a plugin one.

@fmanimashaun offered to test on Windows/Git Bash, which we cannot do here — the scripts are written for bash 3.2 and MSYS, but that offer is worth taking up before release.

Claude Code reads hook registrations at session start, so a plugin enabled
part-way through a session has none of them wired for the rest of it.
PostToolUse never fires, nothing is captured, and hook-errors.log stays empty
because nothing failed. The reporter lost a day to it and found a single
session-start line as the only trace.

It cannot be caught while it is happening, and that is worth stating plainly:
no env var, file or command exposes which hooks are registered — /hooks is a
UI a script cannot invoke — and SessionStart's `source` field is only
startup/resume/clear/compact/fork, so a plugin-enable is indistinguishable
from a fresh start. Every "detect it live" design was checked and none work.

Afterwards, though, the signature is exact: a session where SessionStart ran
and PostToolUse never did. PostToolUse now records the session id it saw;
the next SessionStart compares it with the previous session's id and, if that
session used tools at all, leaves a notice. The zero-tool guard matters — a
conversation with no tool calls produces no PostToolUse either, and warning
about that would be crying wolf.

Identity rather than mtimes: the first cut compared timestamps and a test
caught it reporting a HEALTHY session as broken, because bash 3.2's `-nt`
resolves to the second and the sign of life landed inside the same one as the
stamp.

The notice is delivered through systemMessage, which is the only hook output
the human sees. additionalContext reaches the model alone — which is the
shape of the original bug, so it would have been the wrong channel. The
ordinary path still prints exactly what it always did; only the notice case
switches to JSON, and a test pins that so context injection cannot silently
change.

Adds /remember:doctor: resolved paths, detected tools, storage mode, whether
the session dir Claude Code created matches the computed slug (#144), the
last successful save, and whether PostToolUse has ever fired. OK/WARN/FAIL
per line, one VERDICT.

Two things its own tests found: an install predating the capture-alive marker
was reported as "PostToolUse has never fired" while the next line printed a
successful save — a working user sent off to restart for nothing; and the
slug helpers are not guaranteed to be defined, so the report printed an empty
slug as OK and skipped the #144 check entirely. It now says it could not
check, which is not the same as no problem.

Full suite 880 passed, 41 skipped.

Reported by @fmanimashaun.

Co-Authored-By: Max <noreply>
…rdict that misdiagnosed

Four review passes on #201, four real defects. Recorded because each one was
the feature failing in the shape of the bug it was written to fix.

A pending notice could DESTROY the user's prompt. The systemMessage path
builds its JSON with jq, and jq was the script's last command, so its exit
status became the hook's. jq exits 2 on a usage error, and on UserPromptSubmit
exit 2 blocks the prompt and erases what was typed — on every prompt with a
notice pending, silently, with jq's stderr going to a log nobody reads. The
JSON is now built first and printed only if it was produced, falling back to
plain text, and the hook ends with an explicit exit 0.

The check could not catch the incident it was written for. It was gated on a
prior session-start stamp so a fresh install would not be warned about a
session predating it — which removes the entire point: during a mid-session
enable no hook runs, so no stamp is written, so the one case this exists to
report was the exact case it stayed silent for. It could only ever have caught
a recurrence. The gate is gone. A fresh install sees the notice once per
project and the wording covers both readings.

The doctor misdiagnosed the failure it was built to name. capture-alive was
written after the hook's no-transcript early exit, so in a slug mismatch (#144)
it was never written at all — and the verdict tested the generic "never fired"
branch before the specific causes, so a slug mismatch AND a missing Python both
came out as "restart Claude Code", which fixes neither, on the one line
commands/doctor.md told the operator not to second-guess. A separate
post-tool-ran marker now answers "is the hook wired" before every early exit,
the verdict names specific causes first, and the command doc asks for the FAIL
lines alongside the verdict rather than the verdict alone.

The comment claiming capture-alive was written "unconditionally" was false in
exactly that case. Fixed, and the write goes through a rename now — the lesson
last-save.json learned in #140, since a truncate-then-write killed midway
leaves an empty marker that matches no session and reports a healthy one as a
gap.

Test harness honesty: the fixture's config.json write is inert, because
_LIB_MEMORY_DIR_LOADED=1 stops lib-memory-dir.sh before the config merge, so
features.recovery reads true whatever the file says. It said it suppressed
recovery; it does not, and a test that creates last-save.json while believing
it would get a stray fork. Said outright now. Transcript ordering uses explicit
spaced mtimes rather than a 50ms sleep — the same sub-second-resolution
assumption that bit this feature once already.

Known limits are now written down rather than discovered later: capture-alive
is per project, so concurrent sessions on one project can produce a spurious
notice; and a notice is consumed by the next prompt in any session.

Full suite 882 passed, 41 skipped.

Co-Authored-By: Max <noreply>
@fdaviddpt

Copy link
Copy Markdown
Contributor Author

Review pass — four defects, all fixed in 2d717ec

Ran four independent review agents over this branch. Each found something real, and each was the feature failing in the shape of the bug it was written to fix. Recording them because the PR description above was written before this pass and one of its claims was wrong.

1. A pending notice could destroy the user's prompt. The systemMessage path builds JSON with jq, and jq was the script's last command — so its exit status became the hook's. jq exits 2 on a usage error, and on UserPromptSubmit exit 2 blocks the prompt and erases what was typed. That would have fired on every prompt with a notice pending, silently, with jq's stderr going to a log nobody reads in the moment. Proven end-to-end with a stub. The JSON is now built first and printed only if produced, falling back to plain text, and the hook ends with an explicit exit 0.

2. The check could not catch the incident it was written for. It was gated on a prior session-start stamp, so a fresh install wouldn't be warned about a session predating it. That sounds right and removes the entire point: during a mid-session enable no hook runs, so no stamp is written, so the one case this exists to report was the exact case it stayed silent for. It could only ever have caught a recurrence — and my own test locked that in. The claim in the description above that "the signature is exact" was false as written. The gate is gone; a fresh install sees the notice once per project and the wording covers both readings.

3. The doctor misdiagnosed the failure it was built to name. capture-alive was written after the hook's no-transcript early exit, so in a slug mismatch (#144) it was never written — and the verdict tested the generic "never fired" branch before the specific causes. So a slug mismatch and a missing Python both came out as "restart Claude Code", which fixes neither, on the one line commands/doctor.md told the operator not to second-guess. Now: a separate post-tool-ran marker answers "is the hook wired" before every early exit, the verdict names specific causes first, and the command doc asks for the FAIL lines alongside the verdict.

My comment claiming that marker was written "unconditionally" was false in exactly that case. Fixed, and the write now goes through a rename — the lesson last-save.json learned in #140.

4. Test-harness honesty. The fixture's config.json write is inert: _LIB_MEMORY_DIR_LOADED=1 stops lib-memory-dir.sh before the config merge, so features.recovery reads true whatever the file says. The comment claimed it suppressed recovery. It doesn't — recovery is only absent because these fixtures don't create last-save.json, and anyone copying the pattern into a test that does would get a stray background fork. Said outright now. Transcript ordering also moved from a 50ms sleep to explicit spaced mtimes, since sub-second mtime resolution is the assumption that bit this feature once already.

Known limits, now written down rather than discovered later

  • capture-alive is per project, not per session — two concurrent Claude Code windows on one project can produce a spurious notice.
  • A notice is consumed by the next prompt in any session, so a session closed before its first prompt hands it to the following one.

Neither is silent, and both are in the CHANGELOG.

Full suite: 882 passed, 41 skipped.

@fdaviddpt
fdaviddpt merged commit e58f3a6 into main Jul 27, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the max/detect-silent-noop-and-doctor branch July 27, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Silent no-op when the plugin is enabled mid-session: PostToolUse never registers, no error surfaced

2 participants