rusty-hooks 0.1.0

PostToolUse validation hook for Claude Code — blocks Edit/Write when on-disk content diverges from expected
Documentation

rusty-hooks

A PostToolUse validation hook for Claude Code that blocks Edit and Write operations when the on-disk file content diverges from what the tool reported writing.

What it does

Claude Code supports hooks — shell commands that run before or after tool calls. rusty-hooks installs as a PostToolUse hook and validates every Edit and Write by reading the file back from disk and comparing it to the content the tool claimed to write. If they differ, the hook emits a block decision with a reason, preventing the divergence from being silently accepted.

Installation

cargo install rusty-hooks

Then add to your Claude Code settings (~/.claude/settings.json):

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": { "tool_name": "Edit|Write" },
        "hooks": [{ "type": "command", "command": "validate-hook" }]
      }
    ]
  }
}

How it works

The hook reads a JSON payload from stdin (the Claude Code hook protocol), extracts the tool_name and tool_input, and for Edit/Write calls reads the target file from disk. If the on-disk content does not match tool_input.content, it exits with code 2 and emits:

{ "decision": "block", "reason": "Write validation failed: on-disk content does not match expected for path/to/file" }

A successful validation exits with code 0 and no output.

License

MIT