PulseAugur
中
实时 01:25:53
English(EN) Stop Claude Code from deleting your tests with a PreToolUse hook

Claude Code hook 可防止 AI 删除测试文件

一位开发者为 Claude Code 创建了一个 PreToolUse hook,以防止 AI 删除测试文件。此 hook 使用 Python 编写,在工具调用执行前进行拦截。如果 Claude Code 尝试使用 `rm`、`git rm` 等命令删除测试文件,或向测试文件写入空内容,该 hook 将阻止该操作,并提示模型修复失败的测试。此方法可确保测试不会被删除,而是得到纠正,从而提高 AI 生成代码的可靠性。 AI

影响 开发者可以使用此 hook 来防止意外删除测试,从而提高 AI 代码生成的可靠性。

排序理由 这是为现有 AI 产品创建的用户工具/配置,并非由 AI 提供商发布。

在 dev.to — Claude Code tag 阅读 →

AI 生成摘要 · Google Gemini · 来自 1 个来源。 我们如何撰写摘要 →

Claude Code hook 可防止 AI 删除测试文件

报道来源 [1]

  1. dev.to — Claude Code tag TIER_1 English(EN) · Vildanden ·

    使用 PreToolUse hook 防止 Claude Code 删除您的测试

    <p>A write guard can protect <code>.env</code> and <code>dist</code>. It will not stop Claude Code from "cleaning up" a failing test with <code>rm</code>, <code>git rm</code>, or an empty Write. A PreToolUse hook can refuse those deletions so the model has to fix the test instead…