chore(claude): add CLAUDE.md preflight hook + auditor subagent#599
Merged
Conversation
Wires a PreToolUse hook (.claude/hooks/preflight-claude-md.sh) that gates git commit/push on a verdict from a fresh-context auditor subagent (.claude/agents/claude-md-auditor.md). The auditor judges the diff against every applicable bullet in CLAUDE.md's Workflow section and writes a structured verdict to .claude/.last-audit.json; the hook reads that file, validates branch + HEAD + freshness, and consumes it on PASS. Verified end-to-end on this branch: first attempt denied (no audit), auditor returned FAIL with four findings, addressed each (added a 19-case test suite covering matcher + gate logic, documented matcher and one-shot-consumption trade-offs in the script header, tightened matcher to catch chain segments), re-audited PASS, this commit allowed.
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.
Summary
PreToolUsehook (.claude/hooks/preflight-claude-md.sh) gatesgit commit/git pushon a verdict from a fresh-context auditor subagent (.claude/agents/claude-md-auditor.md).CLAUDE.mdand the staged diff cold, judges every applicable Workflow bullet, writes a structured verdict to.claude/.last-audit.json(gitignored). Hook validates branch + HEAD + command-kind + freshness, consumes the verdict on PASS (one-shot, so re-staged content always re-audits)..claude/hooks/preflight-claude-md.test.sh) covers the chain-segment matcher (direct,&&,||,;, env-var prefix,$(), literal-mention passthrough) and the gate logic (PASS/FAIL/stale/mismatch/consumed paths).How the loop terminates
git commit-> hook denies with "invoke claude-md-auditor".CLAUDE.md+ diff, writes verdict file.Test plan
Cost / caveats