Skip to content

Hooks: whole-space validation baseline at prompt submit, compared at Stop #127

Closed

Description

@mindsocket

Follow-up to #124 / #126.

Problem

The hooks validate per file: the PreToolUse hook takes a baseline for each edited .md file, and the Stop hook re-validates each one. validateFile reads the whole space on every call, so every edited file costs two full-space reads. It also misses:

  • edits made through Bash (sed, mv, scripts);
  • breakage in files Claude never touched, e.g. renaming a node breaks other files' parent links (validateFile filters results to the target file).

Measured with validate-file: 0.2–0.36s per call in 23-file spaces, 9.3–10.4s in a 5,128-file space.

Proposal

Take the baseline when the prompt is submitted, for the whole space, and compare at Stop. Modelled on the security-guidance plugin, which snapshots with git stash create on UserPromptSubmit and diffs at Stop.

  • UserPromptSubmit: find the configured spaces under the session's cwd. For each one, record a content hash and whole-space validation results (issues keyed by file) in the session state file.
  • Stop: for each space in the state, recompute the hash. If it's unchanged, skip it. Otherwise validate the whole space and report issues missing from the baseline, in any file. Errors block and warnings go to additionalContext, as today.
  • Reuse results: Stop saves the current results with their hash. At the next prompt, if the hash still matches, those results become the new baseline without validating again, so only the first prompt, or one after the user's own edits, pays for a full validation.
  • Fallback: a space outside cwd (edited via additional directories) has no baseline taken at prompt submit. Keep the pre-edit hook for that case: on the first edit to a space with no baseline for this prompt, validate that space then.

Content hash

  • Git spaces: the tree hash, not the commit hash from git stash create, which changes on every call. git stash create skips untracked files, so a temporary index is better: GIT_INDEX_FILE=<tmp> git add -A -- <space> && git write-tree. git stash create measured 26ms and git status 37ms in the 5,128-file space.
  • Non-git spaces: a hash of the .md paths and modification times.

Open questions / checks

  • Needs a whole-space validation API that returns issues keyed by file (or a validate --json shape that's easy to key).
  • User edits made while Claude is working are attributed to Claude. The security plugin accepts the same limitation.
  • Interrupted turns: if Stop never ran, the next prompt should keep the existing baseline rather than replace it (as the security plugin does).
  • A space that's a subdirectory of a repo needs its paths mapped relative to the repo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions