← Open sourceAgent verification

guard-hooks

Hooks that block an agent write that would damage a file (lost BOM, mojibake, changed line endings) and classify an action's risk level.

Status
Live
Launched
Licence
MIT
Language
JavaScript
Run it

One command, copied from the repo.

Install guard-hooks: npx guard-hooks init

rishsadh/guard-hooks

What it does

Coding agents rewrite whole files, and some of them lose things that are not visible in a diff. guard-hooks compares the file on disk with what the agent is about to write, and refuses when the change loses a BOM, flips line endings, or introduces mojibake, replacement characters or NUL bytes. The refusal goes back to the agent as text, so it can correct itself. The init command prints the settings snippet for Claude Code and writes nothing: merge it into .claude/settings.json. It has zero dependencies and needs Node 18 or newer.

The same package carries a classifier for what a tool call does, on a ladder of levels: read, local-write, delete, external-send, deploy and spend. A hook can ask or deny by level. It is a vocabulary plus a classifier, not a sandbox. Commands you can run yourself include check, compare, staged (for a pre-commit hook) and classify.

It cannot see inside a shell command, just the command text. For Edit and MultiEdit it can judge just the replacement text, so a lost BOM shows up after the fact in post-tool, where --fix repairs it. Claude Code is the one agent whose hooks are wired up, tested against the documented format and not yet against a long live session. Mojibake detection covers Latin-1 and Windows-1252 reads of UTF-8, not GBK or Shift-JIS.

Why it exists

On 2026-02-11 a Cursor forum thread reported that agent edits strip the UTF-8 BOM and fail a build that needs it. On 2026-02-24 Claude Code issue 28316 reported that the Write tool saves UTF-8 without a BOM, and that Delphi and SQL Server Management Studio then show mangled accents. It was closed as a duplicate.

Agents on Windows often edit through PowerShell. On 2026-09-30, in Windows PowerShell 5.1, (Get-Content f) | Set-Content f on a UTF-8 file with a BOM wrote the file back with the BOM gone, the accented e as a single invalid byte and the Han character as a question mark. It also happened in the maintainer's own repo: a bulk find and replace through Get-Content -Raw and WriteAllText turned arrows, dashes and bullets on six pages into mojibake, and the damage reached a live page.