Guard hook RULE 3 — block rewrites of foreign or published git history#46
Merged
Merged
Conversation
…t history Deterministic backstop for the stop-hook misfire class documented in PR #44's tooling note: an advisory hook suggested `--amend --reset-author` against a GitHub-authored merge commit already on origin/main. Whatever any advisory tooling suggests, the PreToolUse guard now refuses to EXECUTE a history rewrite (--amend / --reset-author / filter-branch) unless every commit it would touch is authored by the agent identity AND not already published on origin/main. Fails open only when there is no git state to inspect (backstop, not a brick); everything else about the guard is unchanged. Seven hermetic tests spawn the real hook via python3 against throwaway git repos (skipped cleanly where python3 is absent). Live-fired in-session: the exact misfire scenario (amending the foreign, published merge commit) is blocked with the new reason text. The nudge-side fixes from the tooling note — suppress commit/push prompts during a declared hold, never nudge push — live in the USER-LEVEL stop hook (~/.claude/stop-hook-git-check.sh), which a repo change cannot reach; this rule removes the damage vector those nudges point at. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LVPyHAtQ1cdK76RpFasafP
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
wecanjustbuildthings | 2597ab2 | Jul 03 2026, 10:07 PM |
MartinMontero
marked this pull request as ready for review
July 3, 2026 22:21
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.
What does this PR do?
Implements the scoped hook fix authorized from PR #44's tooling note, as its own small change under
.claude/plus one test file.RULE 3 in
.claude/hooks/guard.py: when a Bash command is a git history rewrite (--amend,--reset-author,filter-branch), the guard inspects the repo and blocks unless every commit the rewrite would touch is (a) authored by the agent identity (noreply@anthropic.com) and (b) not already published onorigin/main. This makes the documented misfire class — an advisory stop-hook suggesting--amend --reset-authoragainst a GitHub-authored merge commit already onmain— impossible to execute, regardless of what any advisory tooling suggests. It fails open only when there is no git state to inspect (it's a backstop, not a brick), and rules 1–2 (vendor exclusion,operational_advisoryprotection) are untouched.Honest boundary: items (b) and (c) of the tooling note — suppress commit/push nudges during a declared STOP/hold, and never nudge
push— live in the user-level stop hook (~/.claude/stop-hook-git-check.sh) on the operator's machines, which no repo PR can reach. This rule removes the damage vector those nudges point at; the nudge wording itself is an operator-side edit.Type of change
Required checks
npm run checkpasses (schema validation)npm run enforcepasses (three-layer exclusion policy + recipe contract)npm testpasses (7 new hermetic hook tests; suite skips cleanly if python3 is absent)npm run buildsucceeds (no build-surface changes)For catalog entries
Not applicable.
For recipes
Not applicable.
Verification
Seven hermetic tests (
scripts/guard-hook.test.ts) spawn the real hook via python3 against throwaway git repos: foreign-HEAD amend blocked; agent-authored unpublished amend allowed; published-on-origin/main amend blocked; rebase-amend with a foreign commit in range blocked; non-rewrite git commands unaffected; non-repo dirs fail open; non-Bash tools unaffected + RULE 1 regression.Live-fired in the session that wrote it: with HEAD at the #44 merge commit (foreign-authored, on origin/main) — the exact misfire scenario — an attempted
git commit --amend --no-edit --dry-runwas blocked by the running hook with the new reason text.Merging this PR deploys nothing user-facing (hook + test only), though Workers Builds will still run on the merge.
Draft on purpose — do not mark ready-for-review, do not merge; merge is the operator's alone.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LVPyHAtQ1cdK76RpFasafP
Generated by Claude Code