Skip to content
zeeshare.com

writing / FDE and agents

Spec-driven development, for real

Spec-driven development, for realPart 10

Guardrail hooks

On this page
  1. Thursday, 9:15
  2. Signals at the junctions
  3. How work disappears without anyone deleting it
  4. Block or warn?
  5. A line per pull request
  6. Trackers that never conflict
  7. Checking every edit
  8. Which hook fits?
  9. In the kit
  10. Three rules of thumb

New to the short codes like REQ, ADR or AC? See the vocabulary in Part 1, or hover over any code.

In short: A few moments in every change go wrong quietly: a merge from a stale branch, a force-push, a pull request with no record of what it did, a push that leaves the tracker stale, an edit that breaks a principle. Each gets one hook. The policy is deliberately asymmetric: only the irreversible things block; daily work warns, with the exact checks attached. Every hook file starts with why it exists.

Part 9 checked the change. This part covers block 9, which guards the moments around it. The team and product are invented.

Hooks Blocks Warns The work Claude

Thursday, 9:15

Maya’s pull request is ready. When she asks Claude to merge it, a warning comes back: the branch is nine commits behind main. She would have merged without a second look. Instead she runs the two checks the warning names, and finds that resolving a conflict last night quietly undid a rounding fix Jonas merged on Monday.

Nobody did anything wrong on purpose. That is exactly why it needs a hook.

Think of it like this: A railway does not put a signal on every metre of track. It puts them at the junctions, where trains can collide. Each signal does one thing, and the driver knows why it is there.

Signals at the junctions

Edit a file edit-warnings tells git push push-tracker blocks gh pr create changelog blocks gh pr review changelog warns gh pr merge merge-safety warns push --force merge-safety blocks
Signals at the junctions, not on every metre of track. Each hook (named without its -gate suffix) sits on one risky moment.

How work disappears without anyone deleting it

  1. Day 1 · Maya branches from main

    Her branch has fees.py as it is today.

  2. Day 5 · Jonas fixes rounding on main

    His fix changes three lines of fees.py. Merged, reviewed, green.

  3. Day 12 · Maya resolves a conflict by keeping her whole file

    Her editor makes it one click. Jonas’s three lines are gone from her branch.

  4. Day 12 · The pull request diff looks clean

    GitHub shows the diff against the merge base: day 1. Against day 1, she changed only her lines.

  5. Day 13 · Merged. Jonas’s fix is gone

    No conflict, no red test (his test was in the same file), no reviewer saw it.

The trap is in step 4. GitHub shows a pull request’s diff against the merge base, the commit the branch started from, not against today’s main. A stale branch that overwrites a whole file conflicts with nothing and looks clean.

Block or warn?

BLOCK

A force-push to a shared branch. It rewrites history others built on and erases the evidence. There is no good reason, and no undo from the other side.

WARN

A merge. Merges are daily work; blocking them trains people to switch the hook off. The warning carries the two checks: how far behind, and what it deletes.

what Claude sees on gh pr merge
MERGE SAFETY (warning): before merging, prove nothing is being deleted.
  1. How stale is it?   git rev-list --count <pr-head>..origin/main   (this checkout: 9 behind)
  2. What does it delete? git diff --diff-filter=D --name-status origin/main...<pr-head>
                          git diff origin/main...<pr-head> | grep '^-[^-]'
A PR that is 0 commits behind and deletes nothing cannot clobber anyone.
See the pr-merge-safety skill.
9 behind is the signal. Merge main into the branch, run the tests, then merge.

Rule: turn on “Require branches to be up to date before merging” in your branch protection. It removes this whole class of problem. Without it, GitHub calls a branch thirty commits behind “mergeable”, because it only checks for textual conflicts.

A line per pull request

CHANGELOG.md, and the gate on gh pr create
## Unreleased

### Added
- ACME-41: a rental returned late shows its fee at the desk, per started
  hour and never more than a day; staff also see how it was worked out.

---
$ gh pr create --fill          (on a branch with code and no entry)
CHANGELOG: this pull request changes code but not CHANGELOG.md.
Add one line under "## Unreleased", at the end of Added, Changed or Fixed:
    - TICKET-123: what changed, in plain words for a reader outside the team
An entry written after the merge is an entry nobody writes. So the gate sits on the moment the pull request is created.

The tracker gate works the same way on git push: code without a work.md update is refused. It asks for one file only. Earlier versions in the real project tried to work out which other docs each change affected; they were noisy and still missed things, and a gate that is both gets reached past. So it requires the one file that is always right, and prompts for the rest.

Trackers that never conflict

Every pull request appends to the same files. Without help, every merge would conflict on the others.

  1. Three pull requests are open

    Each one appended a line to work.md and CHANGELOG.md, as the gates require.

  2. One merges

    The other two now conflict on lines nobody disagrees about.

  3. A workflow merges main into each open branch

    .gitattributes marks the trackers merge=union, so git keeps both sides’ lines.

    work.md merge=union
    CHANGELOG.md merge=union
    docs/modules/STATUS.md merge=union
  4. A real conflict is left for a person

    Anywhere else, the workflow aborts and comments on the pull request. Nothing dropped, nothing doubled.

Checking every edit

spec-kit.json editWarnings, and the result after an edit
"editWarnings": [
  { "files": "src/**/*.py",
    "pattern": "\\.objects\\.(all|filter|get)\\([^)]*company_id",
    "message": "manual company filter: the tenant boundary is the scoped manager (P1)." },
  { "files": "src/features/**/*.tsx",
    "pattern": "role\\s*===|hasRole\\(",
    "message": "a role check in a feature (F1): render what the API returns." }
]

RULE CHECK after your edit:
src/features/returns/fee-panel.tsx:31: a role check in a feature (F1):
render what the API returns.
A PostToolUse hook cannot undo the edit, but it can tell Claude straight away, with the rule’s reason, while the context is fresh.
Under the hood: writing hooks people keep
  • Start every hook with WHY. The kit’s hooks open with the incident or reasoning behind them, and what earlier versions got wrong. The next person deciding whether to keep a hook reads that first.
  • Fail open. No git, no network, bad JSON: allow the action. A hook that wedges a session is switched off, and then it protects nothing.
  • An off switch per session (SPEC_KIT_MERGE_GATE=off, SPEC_KIT_CHANGELOG_GATE=off for a revert or a dependency bump).
  • Exit codes: 0 allows, and stdout is shown; 2 blocks a PreToolUse call, and stderr goes to Claude. A PostToolUse hook uses exit 2 to show text to Claude, since the edit already happened. See hooks.
  • Your own pain points get hooks too. The real project added a hook that stops several Claude sessions on one shared laptop each building their own copy of the same Docker image and database, after the machine ran out of memory. Not in the kit, because it is specific, but the pattern is the same: one moment, one reason, block or warn.

Which hook fits?

  • Work vanished after a merge: merge-safety-gate + the skillRefuse force-pushes; warn on merges with staleness and deletions; detectors in pr-merge-safety.
  • Nobody knows what shipped: changelog-gateOne plain line per pull request, required at create and merge.
  • The tracker is always stale: push-tracker-gateEvery push with code updates work.md. One hard rule, plus a prompt for other docs.
  • A rule keeps getting broken: edit-warningsA pattern and a reason in spec-kit.json, checked after every edit.
  • Trackers conflict all the time: merge=union + the workflowAppend-only files merge by keeping both sides.

In the kit

Three rules of thumb

Block only the irreversible

Force-pushes and missing records block. Daily work warns, with the checks attached.

Put the reason in the hook

Every hook file starts with WHY. The next person reading it decides whether to keep it.

One hard rule beats a clever one

Earlier tracker gates tried to work out which docs a change affects. Noisy and incomplete. Require one file; prompt for the rest.

QuizA pull request is 12 commits behind main and its diff looks clean. Is it safe to merge?

Show the answer

Answer: Not yet: merge main into it first, then check what it deletes

The clean diff is against the merge base, not today’s main. Merging main in first makes the branch current, so any line it would remove from newer work shows up as a real change you can see.

Words in this post:

  • Merge base: the commit a branch started from. GitHub diffs against it.
  • Stale-branch clobber: a behind branch overwriting newer work without a conflict.
  • Force-push: rewriting a branch’s history. Blocked on shared branches.
  • merge=union: a git setting that keeps both sides’ lines in a file.
  • Asymmetric policy: block the irreversible, warn on the routine.

Next, Part 11: Proof of done shows that green tests and “a person can do this” are two different claims, and how to prove both.

Setting up Claude Code or AI agents for your team?

I help teams build this: agents, RAG search and Claude Code setups that hold up in production.

See services
Next in this seriesSpec-driven development, for realProof of done3 min read