---
id: OBPI-0.0.56-05-ghi-close-defect-accounting-backstop
parent: ADR-0.0.56-closeout-defect-accounting-invariant
item: 5
lane: Heavy
status: Draft
---

# OBPI-0.0.56-05-ghi-close-defect-accounting-backstop: Ghi Close Defect Accounting Backstop

## ADR Item

- **Source ADR:** `docs/design/adr/foundation/ADR-0.0.56-closeout-defect-accounting-invariant/ADR-0.0.56-closeout-defect-accounting-invariant.md`
- **Checklist Item:** #5 - "OBPI-0.0.56-05: Extend the mechanism to ghi-close — PreToolUse hook backstop intercepting `gh issue close`, plus the `ghi-close` skill update naming the mechanical gate."

**Status:** Draft

## Objective

Extend the mechanism to ghi-close — PreToolUse hook backstop intercepting `gh issue close`, plus the `ghi-close` skill update naming the mechanical gate.

## Lane

**Heavy** - This OBPI changes a command/API/schema/runtime contract surface.

> Heavy is reserved for command/API/schema/runtime-contract changes. Process,
> documentation, and template-only work stays Lite unless it changes one of
> those external surfaces.

## Allowed Paths

<!-- What files/directories are IN SCOPE? Be explicit with paths. -->

- `docs/design/adr/foundation/ADR-0.0.56-closeout-defect-accounting-invariant/ADR-0.0.56-closeout-defect-accounting-invariant.md` — parent ADR; READ reference for the § Decision item 5 contract
- `.claude/hooks/` — vendor-surface hooks directory; create a new PreToolUse hook (sibling shape: `.claude/hooks/ghi-triage-chat-silence.py`) that intercepts the `gh issue close` Bash action. NOTE: `.claude/hooks/` has NO `.gzkit/` canonical source — hooks are `.claude/`-only and are edited directly here (unlike skills/rules)
- `.claude/settings.json` — hook registration; register the new hook under the `PreToolUse` `Bash` matcher block (sibling registration: `ghi-triage-chat-silence.py`)
- `.gzkit/skills/ghi-close/SKILL.md` — CANONICAL ghi-close skill; update to name the mechanical reconcile gate. Edit `.gzkit/` first per `.claude/rules/skill-surface-sync.md`; bump `skill-version` and `last_reviewed`. The `.claude/skills/ghi-close/SKILL.md` mirror is regenerated by `uv run gz agent sync control-surfaces` and is NEVER hand-edited (see Denied Paths)
- `tests/test_hooks_guards_ledger_sync.py` — hook-guard tests; add the ghi-close-backstop hook tests here

## Denied Paths

<!-- What files/directories are OUT OF SCOPE? Agents will not touch these. -->

- `src/gzkit/commands/closeout.py`, `src/gzkit/commands/obpi_complete.py`, `src/gzkit/commands/obpi_stages.py` — the `gz closeout` and `gz obpi complete` surfaces are OBPI-01/03/04 scope
- `src/gzkit/event_evidence.py`, the `closeout_defect_accounting` reconcile module — the snapshot model, `RoutingReceipt` model, and reconcile predicate are authored by OBPI-01/02/03; the hook INVOKES the reconcile predicate, it does not reimplement it
- `.claude/skills/ghi-close/SKILL.md` — generated vendor mirror of the canonical skill; regenerated by `uv run gz agent sync control-surfaces`, NEVER hand-edited (canonical surface is `.gzkit/skills/ghi-close/SKILL.md`, in Allowed Paths)
- `docs/governance/advisory-rules-audit.md`, `docs/user/runbook.md`, `docs/user/manpages/validate.md` — docs + scorecard reclassification is OBPI-06 scope
- Adding a prose anti-rationalization table to the `ghi-close` skill — the parent ADR § Scope boundary explicitly forbids this; the skill update NAMES the mechanical gate, it does not add another "Common Rationalizations" table
- Paths not listed in Allowed Paths
- New runtime dependencies, CI files, lockfiles

## Requirements (FAIL-CLOSED)

<!-- Constraints that MUST hold. Numbered list. NEVER/ALWAYS language.
     These are the rules agents ground against. If not met, OBPI fails. -->

1. REQUIREMENT: A new PreToolUse hook MUST be added at `.claude/hooks/ghi-close-defect-accounting.py` (sibling shape: `.claude/hooks/ghi-triage-chat-silence.py`) that intercepts the `gh issue close` Bash action and runs the closeout-defect-accounting reconcile predicate. The hook filename is pinned: `ghi-close-defect-accounting.py`. When a gate-surfaced defect from the session lacks a routing receipt, the hook MUST block the close action (PreToolUse deny).
2. REQUIREMENT: The hook MUST be registered in `.claude/settings.json` under the `PreToolUse` `Bash` matcher block. An unregistered hook is inert — registration is part of the deliverable.
3. REQUIREMENT: The hook MUST REUSE the OBPI-02 reconcile predicate and OBPI-03 `RoutingReceipt` model — it is an adapter behind the same port. NEVER reimplement the fingerprint algorithm or the reconcile logic inside the hook (parent ADR § Port-vs-adapter framing).
4. REQUIREMENT: `.claude/hooks/` is a `.claude/`-only vendor surface with NO canonical `.gzkit/hooks/` source — the hook file is authored directly under `.claude/hooks/` and is NOT propagated by `gz agent sync control-surfaces`. The implementer MUST NOT attempt to canonicalize the hook into `.gzkit/`.
5. REQUIREMENT: The `ghi-close` skill update MUST be made to the CANONICAL `.gzkit/skills/ghi-close/SKILL.md` first, per `.claude/rules/skill-surface-sync.md` non-negotiable rule #1; `skill-version` and `last_reviewed` MUST be bumped in the same edit; `uv run gz agent sync control-surfaces` then propagates to `.claude/skills/ghi-close/SKILL.md`. The mirror MUST NEVER be hand-edited.
6. REQUIREMENT: The `ghi-close` skill update MUST NAME the mechanical reconcile gate as the structural witness — it MUST NOT add another prose anti-rationalization table. GHI #514's evidence shows prose did not bind; the parent ADR § Scope boundary forbids more prose tables.
7. REQUIREMENT: This OBPI is the BACKSTOP for the non-`gz` ghi-close surface ONLY. The hook is the secondary defense; it MUST NOT replace the `gz`-runtime mechanism (OBPI-01/02/03) — that mechanism remains primary (parent ADR § Alternatives Considered #1).
8. REQUIREMENT: Work MUST stay inside the Allowed Paths; NEVER include the operator's personal email in the hook, skill, or any example.

> STOP-on-BLOCKERS: if OBPI-02 (reconcile scope) / OBPI-03 (`RoutingReceipt`) are not yet landed, or `.claude/settings.json` / `.gzkit/skills/ghi-close/SKILL.md` is absent, print a BLOCKERS list and halt.

## Discovery Checklist

<!-- What to read before implementation. Complete this checklist first.
     Order matters: read the structured input (parent ADR § Decision)
     before the unstructured one (allowed paths, prerequisites). -->

**Parent ADR (read first; order pinned — GHI #321):**

- [ ] **Parent ADR § Decision item — quote the line this OBPI implements** verbatim into the brief's Implementation Summary. The Decision item is the contract; everything else hangs off it.
- [ ] Parent ADR § Intent — the why-frame for the Decision read above.
- [ ] Parent ADR file: `docs/design/adr/foundation/ADR-0.0.56-closeout-defect-accounting-invariant/ADR-0.0.56-closeout-defect-accounting-invariant.md`

> **STOP:** If you cannot quote the parent ADR § Decision item that this OBPI implements, STOP and re-read. Do not proceed to Allowed Paths, Prerequisites, or implementation until the Decision quote is in hand.

**Governance (read once, cache):**

- [ ] `.github/discovery-index.json` - repo structure
- [ ] `AGENTS.md` or `CLAUDE.md` - agent operating contract

**Context:**

- [ ] `.claude/hooks/ghi-triage-chat-silence.py` — sibling PreToolUse `Bash`-matcher hook shape; the new hook follows this structure
- [ ] `.claude/settings.json` `PreToolUse` `Bash` block — sibling hook registration
- [ ] `.gzkit/skills/ghi-close/SKILL.md` — the canonical ghi-close skill; locate its existing "Common Rationalizations" / "Red Flags" prose (named in parent ADR § Alternatives Considered #3)
- [ ] `.claude/rules/skill-surface-sync.md` — canonical-first editing and `skill-version`/`last_reviewed` bump rules
- [ ] OBPI-02 reconcile predicate, OBPI-03 `RoutingReceipt` model — the port this hook adapts
- [ ] **Related OBPIs:** depends on OBPI-02/03. Sibling of OBPI-04 (both extend the same port to a third surface). Sequencing 01 → 02 → 03 → {04, 05} (this is step 05).

**Prerequisites (check existence, STOP if missing):**

- [ ] Required path exists or is intentionally created in this OBPI: `docs/design/adr/foundation/ADR-0.0.56-closeout-defect-accounting-invariant/ADR-0.0.56-closeout-defect-accounting-invariant.md`
- [ ] Required path exists or is intentionally created in this OBPI: `docs/design/adr/foundation/ADR-0.0.56-closeout-defect-accounting-invariant/**`
- [ ] Parent ADR evidence artifacts referenced by this brief are present

**Existing Code (understand current state):**

- [ ] Existing tests adjacent to the Allowed Paths reviewed before implementation
- [ ] Parent ADR integration points reviewed for local conventions

## Quality Gates

<!-- Which gates apply and how to verify them. -->

### Gate 1: ADR

- [ ] Intent and scope recorded in this OBPI brief
- [ ] Parent ADR checklist item quoted

### Gate 2: TDD (Red-Green-Refactor)

- [ ] Tests derived from brief acceptance criteria, not from implementation
- [ ] Red-Green-Refactor cycle followed per behavior increment
- [ ] Tests pass: `uv run gz test`
- [ ] Validation commands recorded in evidence with real outputs

### Code Quality

- [ ] Lint clean: `uv run gz lint`
- [ ] Type check clean: `uv run gz typecheck`

<!-- Heavy lane only: -->
### Gate 3: Docs (Heavy only)

- [ ] Docs build: `uv run mkdocs build --strict`
- [ ] Relevant docs updated

### Gate 4: BDD (Heavy only)

- [ ] Acceptance scenarios pass: `uv run -m behave features/`

### Gate 5: Human (Heavy only)

- [ ] Human attestation recorded

## Verification

<!-- What commands verify this work? Use real repo commands, then paste the
     outputs into Evidence. These are CONSTRUCTION HOUSEKEEPING (lint, type,
     test, mkdocs) — they prove the codebase is healthy, not what the OBPI
     yielded. The yielded product belongs in the `## Demo` section below. -->

```bash
uv run gz lint
uv run gz typecheck
uv run gz test

# Specific verification for this OBPI
uv run -m unittest tests.test_hooks_guards_ledger_sync -v
uv run gz agent sync control-surfaces
test -f .claude/hooks/ghi-close-defect-accounting.py
uv run mkdocs build --strict
```

## Demo

<!-- THE YIELDED PRODUCT, not housekeeping. Concrete, runnable invocations
     that demonstrate the capability this OBPI delivers — e.g. an actual
     diagnosis run against a real file, the `--json` form, an auto-chain
     trigger. The closeout ceremony walkthrough harvests this section
     (parser-validated; unregistered verbs are dropped). Prefer real paths
     and arguments over `<placeholder>` syntax. `--help` is not a demo. -->

```bash
# Simulate the PreToolUse hook intercepting a `gh issue close` with an unrouted defect.
# The hook reads the PreToolUse payload on stdin and emits a deny decision:
echo '{"tool_name":"Bash","tool_input":{"command":"gh issue close 514"}}' \
  | uv run python .claude/hooks/ghi-close-defect-accounting.py; echo "exit=$?"

# Confirm the hook is registered in settings.json under the PreToolUse Bash matcher:
uv run python -c "import json; h=json.load(open('.claude/settings.json'))['hooks']['PreToolUse']; print([c['command'] for b in h if b['matcher']=='Bash' for c in b['hooks']])"

# Read the ghi-close skill update naming the mechanical gate:
grep -n 'closeout-defect-accounting' .gzkit/skills/ghi-close/SKILL.md
```

## Acceptance Criteria

<!--
Specific, testable criteria for completion.
Each checkbox MUST carry a deterministic REQ ID:
REQ-<semver>-<obpi_item>-<criterion_index>
-->

- [ ] REQ-0.0.56-05-01: Given a `gh issue close` Bash action and a session gate-surfaced defect with no routing receipt, when the PreToolUse hook runs, then the hook blocks the close action (deny decision).
- [ ] REQ-0.0.56-05-02: Given a `gh issue close` Bash action and every session gate-surfaced defect carrying a routing receipt, when the PreToolUse hook runs, then the hook allows the close action.
- [ ] REQ-0.0.56-05-03: Given the new hook, when `.claude/settings.json` is read, then the hook is registered under the `PreToolUse` `Bash` matcher block.
- [ ] REQ-0.0.56-05-04: Given the hook invokes the reconcile, when its source is read, then it reuses the OBPI-02 reconcile predicate and OBPI-03 `RoutingReceipt` model — no reimplemented fingerprint or reconcile logic.
- [ ] REQ-0.0.56-05-05: Given the `ghi-close` skill update, when `.gzkit/skills/ghi-close/SKILL.md` is read, then it names the mechanical reconcile gate as the structural witness and adds NO new prose anti-rationalization table; `skill-version` and `last_reviewed` are bumped and the mirror is sync-propagated.

## Completion Checklist

<!-- Verify all gates before marking OBPI accepted. -->

- [ ] **Gate 1 (ADR):** Intent recorded in brief
- [ ] **Gate 2 (TDD):** RGR cycle followed, tests derived from brief, coverage maintained
- [ ] **Code Quality:** Lint, format, type checks clean
- [ ] **Value Narrative:** Problem-before vs capability-now is documented
- [ ] **Key Proof:** One concrete usage example is included
- [ ] **OBPI Acceptance:** Evidence recorded below

> For ceremony steps and lane-inheritance attestation rules, see `AGENTS.md` section `OBPI Acceptance Protocol`.

## Evidence

<!-- Record observations during/after implementation.
     Command outputs, file:line references, dates. -->

### Gate 1 (ADR)

- [ ] Intent and scope recorded

### Gate 2 (TDD — Red-Green-Refactor)

```text
# Paste test output here
```

### Code Quality

```text
# Paste lint/format/type check output here
```

### Gate 3 (Docs)

```text
# Paste docs-build output here when Gate 3 applies
```

### Gate 4 (BDD)

```text
# Paste behave output here when Gate 4 applies
```

### Gate 5 (Human)

```text
# Record attestation text here when required by parent lane
```

### Value Narrative

<!-- What problem existed before this OBPI, and what capability exists now? -->

### Key Proof

<!-- One concrete usage example, command, or before/after behavior. -->

### Implementation Summary

- Files created/modified:
- Tests added:
- Date completed:
- Attestation status:
- Defects noted:

## Tracked Defects

<!-- Record GitHub defect linkage when defects are discovered during this OBPI.
     Use one bullet per issue so status surfaces can preserve traceability. -->

_No defects tracked._

## Human Attestation

- Attestor: `<name>` when required, otherwise `n/a`
- Attestation: substantive attestation text or `n/a`
- Date: YYYY-MM-DD or `n/a`

---

**Date Completed:** -

**Evidence Hash:** -
