delivery-gate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDelivery Gate — Mechanical Quality Gate for Claude Code
Delivery Gate — Claude Code的机械质量检查门
A Stop hook that checks three things before Claude can finish a session, using only deterministic checks — file modification timestamps, disk usage, and regex patterns on the transcript text. No AI inference.
This is distinct from reasoning gates (like ): delivery-gate checks machine-verifiable facts; self-audit checks output quality across four reasoning dimensions. Together they form defense in depth:
self-audit- delivery-gate: "Was the learning library touched today? Is disk space safe?"
- self-audit: "Is the file content correct, complete, and honest?"
This is the same pattern as CI pipeline gates — automated, deterministic checks that verify machine-readable facts rather than trusting self-reported status.
这是一种Stop钩子,在Claude结束会话前会检查三项内容,仅使用确定性检查——文件修改时间戳、磁盘使用情况以及对话文本的正则匹配模式,无需AI推理。
它与推理检查门(如)不同:delivery-gate检查机器可验证的事实;self-audit则从四个推理维度检查输出质量。二者共同构建深度防御体系:
self-audit- delivery-gate:“今日是否更新了学习库?磁盘空间是否安全?”
- self-audit:“文件内容是否正确、完整且真实?”
这与CI流水线检查门的模式一致——通过自动化、确定性检查来验证机器可读的事实,而非依赖自我报告的状态。
What It Checks
检查内容
| Check | Mechanism | On Hit |
|---|---|---|
| Rationalization patterns | Regex on transcript tail | Warning only (never blocks) |
| Stale learning libraries | mtime on 5 configurable paths | Warning if some stale; Block if >=3 stale OR growth-log stale + complex task |
| Disk space < 50GB | | Warning |
| Disk space < 15GB | | Block (exit 2) |
Rationalization detection warns about patterns like "skip tests for now" and "pre-existing bug" — surface signals that thinking may have been cut short. It never blocks on its own, because regex heuristics can false-positive. The blocking conditions are: disk critical, , OR specifically stale (all require complex task >=3 edits).
>=3 learning libs stalegrowth-log| 检查项 | 实现机制 | 触发结果 |
|---|---|---|
| 合理化模式 | 匹配对话末尾的正则表达式 | 仅警告(从不阻止) |
| 过期学习库 | 检查5个可配置路径的修改时间 | 部分过期时警告;阻止条件:≥3个库过期 或 growth-log过期且任务复杂 |
| 磁盘空间 < 50GB | | 警告 |
| 磁盘空间 < 15GB | | 阻止(退出码2) |
合理化检测会针对诸如“暂时跳过测试”“已有bug”之类的模式发出警告——这些是思维可能被打断的表层信号。由于正则启发式可能出现误报,因此它不会单独触发阻止。阻止条件为:磁盘空间临界、,或明确过期(均要求复杂任务≥3次编辑)。
≥3个学习库过期growth-logWhy
设计初衷
Claude Code's built-in checks cover code quality (build → type → lint → test). But there's a different failure mode: the agent produces working code while the session hygiene was neglected — learning not captured, rationalized shortcuts, disk running out silently.
Over many sessions of "ship and forget," the human hasn't grown. This hook enforces the habit: complex task → must touch learning libraries.
Claude Code的内置检查覆盖代码质量(构建→类型检查→代码规范→测试)。但存在另一种失败模式:Agent生成了可运行的代码,却忽略了会话规范——未记录学习内容、使用合理化借口走捷径、磁盘空间悄然耗尽。
长期“交付后即遗忘”会导致人类用户无法成长。该钩子强制养成习惯:复杂任务→必须更新学习库。
Install
安装
bash
cp quality-gate.py ~/.claude/scripts/Add to :
~/.claude/settings.jsonjson
{
"hooks": {
"Stop": [{
"hooks": [{
"type": "command",
"command": "python3 ~/.claude/scripts/quality-gate.py",
"timeout": 5000
}]
}]
}
}bash
cp quality-gate.py ~/.claude/scripts/添加至:
~/.claude/settings.jsonjson
{
"hooks": {
"Stop": [{
"hooks": [{
"type": "command",
"command": "python3 ~/.claude/scripts/quality-gate.py",
"timeout": 5000
}]
}]
}
}Learning Libraries
学习库
Create these files in your project's memory directory. The hook checks if at least one was updated today:
memory/
├── growth-log/ # Daily learning entries (directory)
├── decisions/log.md # Decision log
├── output-index.md # Index of session outputs
├── ratings-tracker.md # Skill ratings over time
└── tooling_capabilities.md # Known tools inventoryCustomize the dict to match your own file structure.
LIBS在项目的内存目录中创建以下文件。钩子会检查是否至少有一个文件在今日被更新:
memory/
├── growth-log/ # 每日学习记录(目录)
├── decisions/log.md # 决策日志
├── output-index.md # 会话输出索引
├── ratings-tracker.md # 技能评分跟踪
└── tooling_capabilities.md # 已知工具清单可自定义字典以匹配你的文件结构。
LIBSConfiguration
配置
Edit :
quality-gate.py| Variable | Default | Purpose |
|---|---|---|
| 4 patterns | Regex patterns for rationalization detection |
| 5 libraries | Files/dirs to check for today's updates |
| 3 | Edit/Write calls to classify as complex |
| 50 | Warn below this |
| 15 | Block below this |
编辑:
quality-gate.py| 变量 | 默认值 | 用途 |
|---|---|---|
| 4种模式 | 用于检测合理化行为的正则表达式模式 |
| 5个学习库 | 需检查今日更新的文件/目录 |
| 3 | 判定任务为复杂所需的编辑/写入次数 |
| 50 | 低于该值时发出警告 |
| 15 | 低于该值时阻止会话结束 |
Examples
示例
Simple session — allowed:
edit_count=1 (< 3, not complex) → exit 0Complex task, learning captured — allowed:
edit_count=5 (complex) → checks LIBS → growth-log updated today → exit 0Complex task, no learning — BLOCKED:
edit_count=4 (complex) → checks LIBS → all 5 stale → exit 2
stderr: "Blocked: complex task completed but no learning captured today."Low disk space — BLOCKED:
disk_free=12GB < 15GB critical → exit 2
stderr: "Blocked: disk space at 12GB (threshold: 15GB)."简单会话——允许结束:
edit_count=1 (< 3,非复杂任务) → 退出码0复杂任务且已记录学习内容——允许结束:
edit_count=5(复杂任务)→ 检查学习库 → growth-log今日已更新 → 退出码0复杂任务但未记录学习内容——被阻止:
edit_count=4(复杂任务)→ 检查学习库 → 全部5个库均过期 → 退出码2
stderr: "Blocked: complex task completed but no learning captured today."磁盘空间不足——被阻止:
disk_free=12GB < 15GB临界值 → 退出码2
stderr: "Blocked: disk space at 12GB (threshold: 15GB)."Limitations
局限性
The hook enforces the habit of touching learning libraries, not the quality of what was recorded. If is updated but is skipped, the hook passes (1 of 5 libraries touched). This is by design: mechanical gates check machine-verifiable facts. For content quality verification, pair with .
output-index.mdgrowth-logself-audit该钩子仅强制养成更新学习库的习惯,不检查记录内容的质量。例如若仅更新而跳过,钩子仍会通过(5个库中有1个已更新)。这是设计使然:机械检查门仅验证机器可识别的事实。如需验证内容质量,请搭配使用。
output-index.mdgrowth-logself-auditCompatibility
兼容性
- Python 3.8+ (uses )
from __future__ import annotations - Cross-platform: Windows, macOS, Linux
- Zero dependencies beyond stdlib
- Python 3.8+(使用)
from __future__ import annotations - 跨平台:Windows、macOS、Linux
- 仅依赖标准库,无额外依赖
Quality
质量说明
This code went through 4 rounds of automated code review (CodeRabbit + Greptile) with 9 real bugs found and fixed.
此代码经过4轮自动化代码审查(CodeRabbit + Greptile),共发现并修复9个真实bug。
See Also
相关链接
- — Reasoning quality gate (completeness/consistency/groundedness/honesty)
self-audit - — Code quality checks (build/type/lint/test)
verification-loop - — PreToolUse safety gate
gateguard
- — 推理质量检查门(完整性/一致性/相关性/真实性)
self-audit - — 代码质量检查(构建/类型检查/代码规范/测试)
verification-loop - — PreToolUse安全检查门
gateguard