Skip to content
zeeshare.com

writing / FDE and agents

Spec-driven development, for real

Spec-driven development, for realPart 8

Gates that make Claude show its work

On this page
  1. Wednesday, 10:31
  2. Asking versus forcing
  3. One session, minute by minute
  4. Firing only where it matters
  5. The other easy ways out
  6. Wiring them up
  7. Which gate fits?
  8. In the kit
  9. 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: Asked “did you check the schema?”, a model says yes. So the contract fact-force gate does not ask. It blocks the first edit in a session to a file that uses the generated API client, and tells Claude to state four facts: is the contract current, which generated types and hooks it uses, which fields this role receives, and that every call goes through one door. Stating them means reading them. Two more gates stop the other easy ways out: config protection and the dependency allowlist.

Part 7 generated the contract. This part covers block 7, which makes sure Claude actually uses it. The team and product are invented.

Gates Generated contract Allowed Blocked Claude states facts

Wednesday, 10:31

Jonas asks Claude to build the return screen. Claude starts writing return-screen.tsx. Its first edit never lands. A message comes back from a hook instead, and Claude, without being asked, opens src/lib/api/generated/model/returnRecord.ts, reads it, and writes four short answers before trying again.

Jonas has seen Claude invent a field before: confidently, plausibly, and wrongly. This time it named every field it was about to use, and one of them was marked “staff only”.

Think of it like this: On a flight deck, the co-pilot does not ask “are the flaps set?”, because the answer is always “yes”. The checklist says “flaps”, and the pilot reads the gauge and says the number. The question is replaced by a fact that can only come from looking.

Asking versus forcing

Ask "did you check?" "yes, I checked" writes item_name compiles in loose code blank on screen Make it state the facts first edit blocked reads model file names ReturnRecord edit lands, correct Self-assessment says yes. Stating the facts requires reading them.
A pilot’s checklist is not "are the flaps set?". It is "flaps", and the pilot reads the gauge aloud.

One session, minute by minute

  1. 10:31 · Claude edits return-screen.tsx

    The new content imports useRentalsReturn and ReturnRecord from @/lib/api: generated contract.

  2. 10:31 · Blocked once

    The hook exits 2. Its message goes back to Claude: state four facts, then run the same edit again.

  3. 10:32 · Claude reads and states

    "Regenerated at 10:28. Using ReturnRecord and useRentalsReturn. Fields: late_fee_minor (all roles), fee_basis (optional, staff only). Calls go through @/lib/api."

  4. 10:32 · Same edit, allowed

    The file is remembered for this session. The edit lands, written against fields Claude has just read.

  5. 10:40 · Later edits to that file

    Allowed straight away. The gate fires once per file per session, not on every keystroke.

Here is the message Claude receives:

what Claude sees when the gate fires
CONTRACT GATE: first edit to return-screen.tsx this session.
Before writing code that uses the API, state these facts, then run the same edit again:
1. Is the contract current? If an endpoint changed this session, regenerate first: pnpm gen:api
   Never hand-type a request or response shape.
2. Which generated types and hooks does this file use? Name them exactly. If you cannot,
   read src/lib/api/generated/ before editing. Do not invent field names.
3. Field security: which fields does this role's response actually contain? A withheld field
   is absent (undefined), not null. Render what arrives; never hide a field by checking the role.
4. One door: every call goes through @/lib/api. No raw fetch or axios in features.
This gate fires once per file per session. Off: SPEC_KIT_CONTRACT_GATE=off
Exit code 2 from a PreToolUse hook blocks the edit and sends this text to Claude as the reason.
Under the hood: how the gate works
  • It is a PreToolUse hook on Edit|Write|MultiEdit. Claude Code sends the tool call as JSON on stdin; exit code 2 blocks the call and sends stderr back to Claude. See hooks.
  • It judges the content about to land, not just the path, so a brand-new file is judged on what it will contain.
  • It remembers gated files per session in a small file in the temp folder, keyed by session_id. If it cannot write that file, it allows the edit rather than block every retry.
  • It fails open on bad input or any error, and SPEC_KIT_CONTRACT_GATE=off switches it off for one session.
  • The idea follows a public pattern for “fact-forcing” gates. The kit’s version is written for an Orval client with field-level security, with its own tests.

Firing only where it matters

The first version of this gate, in the real project it comes from, fired on every API-consuming file. In one session it blocked ten edits, and every time the honest answer was “no generated model applies here”. A gate whose premise is false for most of its targets spends its credibility, and people learn to reach past it. So it was narrowed:

It fires on
  • .ts and .tsx files under features, app or routes.
  • Content that imports a generated model or hook, judged on what is about to land.
  • The first edit to that file in this session.
It stays quiet on
  • Tests, stories, type declarations, e2e and mocks.
  • The generated folder itself.
  • Files that import only plumbing like apiRequest: there is no shape to get wrong.

The other easy ways out

When a build is red, there are two shortcuts an agent will take: loosen the check, or bring in a different tool.

Make the build green the easy way typecheck fails "strict": false build is green bug ships Config protection typecheck fails edit tsconfig: blocked fix the code green for real
Agents loosen checks to make them pass. Creating a config is allowed; changing an existing one needs a person.
scripts/allowed-dependencies.json, and what happens on pnpm add moment
{
  "$comment": "The approved stack (ADR 0002). Adding a package means
               an ADR and a line here, made by a person.",
  "dependencies": ["react", "@tanstack/react-query", "axios", "zod",
                   "react-hook-form", "zustand", "i18next", "..."]
}

$ pnpm add moment
DEPENDENCY GUARD: moment not on scripts/allowed-dependencies.json.
The stack is a recorded decision. Use what is already installed, or stop
and propose the package with a reason; adding it means an ADR and an
entry on the allowlist, made by a person.
Asked to format a date, an agent will happily install a second date library. The allowlist makes the stack a decision, and CI checks package.json against it too.

Wiring them up

hooks/hooks.json (excerpt, from the kit)
"PreToolUse": [
  { "matcher": "Edit|Write|MultiEdit",
    "hooks": [
      { "type": "command", "command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/hooks/contract-fact-force.mjs\"" },
      { "type": "command", "command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/hooks/config-protection.mjs\"" } ] },
  { "matcher": "Bash",
    "hooks": [
      { "type": "command", "command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/hooks/deps-allowlist.mjs\"" } ] }
]
Three gates, wired by the plugin. Each reads its settings from spec-kit.json in your repository.

Which gate fits?

  • Claude invents fields: contract-fact-forceBlocks the first edit to each API-consuming file per session until Claude states the types and fields.
  • Claude loosens checks to pass: config-protectionBlocks edits to existing lint, type, contract and CI configs.
  • Claude adds libraries: deps-allowlistBlocks adding a package that is not on the allowlist. CI checks it again.
  • I want the whole procedure: The sync-contract skillRegenerate, read the types, build against them, render what arrives, test field security.
  • The gate fires too often: Narrow it in spec-kit.jsonSet consumerPaths and infraExports so it only fires where a shape could be wrong.

In the kit

Three rules of thumb

Make it state, not agree

A question gets a yes. A gate that needs named facts gets a read.

Fire where it matters

A gate that fires where nothing can go wrong is a tax, and people reach past taxes.

Fail open

A broken gate allows the action. A gate that wedges sessions gets switched off.

QuizClaude edits a test file that imports ReturnRecord. Does the contract gate fire?

Show the answer

Answer: No, tests, stories and mocks are skipped

Tests are where you deliberately build fixtures and edge cases, and they are checked by running them. Gating them would add friction without catching anything.

Words in this post:

  • Fact-force gate: a hook that blocks an action until Claude states specific facts.
  • PreToolUse hook: runs before a tool call and can block it with exit code 2.
  • Fail open: on any error, allow the action rather than block.
  • Config protection: blocks changes to existing lint, type and CI settings.
  • Dependency allowlist: the packages the stack may use, changed only with an ADR.

Next, Part 9: Skills and reviewers makes every change the same shape, and checks it with specialists who each know one set of rules.

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 realSkills and reviewers3 min read