Skip to content

Guard hook RULE 3 — block rewrites of foreign or published git history#46

Merged
MartinMontero merged 1 commit into
mainfrom
claude/wcjbt-hook-guard-rewrites
Jul 3, 2026
Merged

Guard hook RULE 3 — block rewrites of foreign or published git history#46
MartinMontero merged 1 commit into
mainfrom
claude/wcjbt-hook-guard-rewrites

Conversation

@MartinMontero

Copy link
Copy Markdown
Owner

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 on origin/main. This makes the documented misfire class — an advisory stop-hook suggesting --amend --reset-author against a GitHub-authored merge commit already on main — 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_advisory protection) 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

  • New catalog entry
  • Fix/update to an existing entry
  • New or updated recipe
  • Build flow / docs
  • Enforcement engine / tooling
  • Other — agent-workflow safety hook

Required checks

The enforcement engine is blocking. CI runs all of this on your PR, but please
confirm you ran it locally too.

  • npm run check passes (schema validation)
  • npm run enforce passes (three-layer exclusion policy + recipe contract)
  • npm test passes (7 new hermetic hook tests; suite skips cleanly if python3 is absent)
  • npm run build succeeds (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-run was 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

…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
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
wecanjustbuildthings 2597ab2 Jul 03 2026, 10:07 PM

@MartinMontero
MartinMontero marked this pull request as ready for review July 3, 2026 22:21
@MartinMontero
MartinMontero merged commit 8bbf0a4 into main Jul 3, 2026
14 checks passed
@MartinMontero
MartinMontero deleted the claude/wcjbt-hook-guard-rewrites branch July 3, 2026 22: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.

2 participants