delivery-gate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Delivery 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
self-audit
): delivery-gate checks machine-verifiable facts; self-audit checks output quality across four reasoning dimensions. Together they form defense in depth:
  • 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推理。
它与推理检查门(如
self-audit
)不同:delivery-gate检查机器可验证的事实;self-audit则从四个推理维度检查输出质量。二者共同构建深度防御体系:
  • delivery-gate:“今日是否更新了学习库?磁盘空间是否安全?”
  • self-audit:“文件内容是否正确、完整且真实?”
这与CI流水线检查门的模式一致——通过自动化、确定性检查来验证机器可读的事实,而非依赖自我报告的状态。

What It Checks

检查内容

CheckMechanismOn Hit
Rationalization patternsRegex on transcript tailWarning only (never blocks)
Stale learning librariesmtime on 5 configurable pathsWarning if some stale; Block if >=3 stale OR growth-log stale + complex task
Disk space < 50GB
shutil.disk_usage
Warning
Disk space < 15GB
shutil.disk_usage
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,
>=3 learning libs stale
, OR
growth-log
specifically stale (all require complex task >=3 edits).
检查项实现机制触发结果
合理化模式匹配对话末尾的正则表达式仅警告(从不阻止)
过期学习库检查5个可配置路径的修改时间部分过期时警告;阻止条件:≥3个库过期 或 growth-log过期且任务复杂
磁盘空间 < 50GB
shutil.disk_usage
警告
磁盘空间 < 15GB
shutil.disk_usage
阻止(退出码2)
合理化检测会针对诸如“暂时跳过测试”“已有bug”之类的模式发出警告——这些是思维可能被打断的表层信号。由于正则启发式可能出现误报,因此它不会单独触发阻止。阻止条件为:磁盘空间临界、
≥3个学习库过期
,或
growth-log
明确过期(均要求复杂任务≥3次编辑)。

Why

设计初衷

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.json
:
json
{
  "hooks": {
    "Stop": [{
      "hooks": [{
        "type": "command",
        "command": "python3 ~/.claude/scripts/quality-gate.py",
        "timeout": 5000
      }]
    }]
  }
}
bash
cp quality-gate.py ~/.claude/scripts/
添加至
~/.claude/settings.json
json
{
  "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 inventory
Customize the
LIBS
dict to match your own file structure.
在项目的内存目录中创建以下文件。钩子会检查是否至少有一个文件在今日被更新:
memory/
├── growth-log/          # 每日学习记录(目录)
├── decisions/log.md     # 决策日志
├── output-index.md      # 会话输出索引
├── ratings-tracker.md   # 技能评分跟踪
└── tooling_capabilities.md  # 已知工具清单
可自定义
LIBS
字典以匹配你的文件结构。

Configuration

配置

Edit
quality-gate.py
:
VariableDefaultPurpose
RATIONALIZE
4 patternsRegex patterns for rationalization detection
LIBS
5 librariesFiles/dirs to check for today's updates
COMPLEX_THRESHOLD
3Edit/Write calls to classify as complex
DISK_WARN_GB
50Warn below this
DISK_CRIT_GB
15Block below this
编辑
quality-gate.py
变量默认值用途
RATIONALIZE
4种模式用于检测合理化行为的正则表达式模式
LIBS
5个学习库需检查今日更新的文件/目录
COMPLEX_THRESHOLD
3判定任务为复杂所需的编辑/写入次数
DISK_WARN_GB
50低于该值时发出警告
DISK_CRIT_GB
15低于该值时阻止会话结束

Examples

示例

Simple session — allowed:
edit_count=1 (< 3, not complex) → exit 0
Complex task, learning captured — allowed:
edit_count=5 (complex) → checks LIBS → growth-log updated today → exit 0
Complex 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
output-index.md
is updated but
growth-log
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
self-audit
.
该钩子仅强制养成更新学习库的习惯,不检查记录内容的质量。例如若仅更新
output-index.md
而跳过
growth-log
,钩子仍会通过(5个库中有1个已更新)。这是设计使然:机械检查门仅验证机器可识别的事实。如需验证内容质量,请搭配
self-audit
使用。

Compatibility

兼容性

  • 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

相关链接

  • self-audit
    — Reasoning quality gate (completeness/consistency/groundedness/honesty)
  • verification-loop
    — Code quality checks (build/type/lint/test)
  • gateguard
    — PreToolUse safety gate
  • self-audit
    — 推理质量检查门(完整性/一致性/相关性/真实性)
  • verification-loop
    — 代码质量检查(构建/类型检查/代码规范/测试)
  • gateguard
    — PreToolUse安全检查门