Hi all,
Sharing a small hook I built after one too many “cleanup complete” moments — the agent
had deleted my tests and never mentioned it.
What it does (single Python file, stdlib only, no network):
- Gates irreversible actions — delete /
git push / package install / outbound requests
- Deny means deny —
git push is refused outright (exit code 2), not “warned about”
- Every decision leaves a receipt — appended to
.fazhi/ledger.jsonl with a hash chain,
so anyone can recompute it with plain sha256 without trusting my code
What I tested in Cursor
deny works: the agent itself reported “git push was rejected by the local hook, nothing
was pushed”, and the target repo had zero commits
ask is not honoured in my testing — the action gets executed anyway. So I treat
deny as the hard guarantee, not ask.
If anyone knows the correct way to make Cursor honour an “ask” from a PreToolUse hook,
I’d really like to hear it — that’s the one gap I couldn’t close.
What it is NOT
- Not a detector: the rule layer is deliberately conservative and will miss actions that
look ordinary. The gate is the backstop, not the detector.
- Not DLP, not a sandbox, not a replacement for code review.
Setup
It’s a PreToolUse hook, so it works with Cursor (.cursor/hooks.json) and Claude Code
(.claude/settings.json). Restart the editor after adding it.
Repo (MIT, one file): GitHub - wzafamc009-creator/fazhi: Your AI can still work - it just can't do the things it shouldn't. Gate irreversible actions (delete/push/install) and keep a tamper-evident ledger. Works with Claude Code + Cursor. · GitHub
Happy to hear where it fails to catch things — failures are more useful to me than praise.
Adding a concrete use case people keep asking about: banning auto git commit / git push.
The rule in the hook is just:
if "git commit" in cmd or "git push" in cmd: -> exit 2
Why this works where denylist doesn’t:
- denylist matches a single command prefix, so
git add . && git commit -m x slips through
- a preToolUse hook sees the whole command string, so the
&& chained form is caught too
Net effect: the agent can still read git state (git status, git log, git diff),
but it cannot change it. If you want it to commit sometimes, don’t allow-list git commit
in the IDE — just remove that rule from the hook.
Caveat (same as above): ask isn’t honoured by Cursor yet, so this is deny-or-allow.
v0.1.1 is out — I fixed a fail-open bug I found while testing this.
Before: if the host sent a tool name the hook didn’t recognise, it fell through to allow,
silently, with no error. That’s exactly how Shell vs Bash let every command through in
my first test.
Now: unknown tool names are denied by default (E_UNKNOWN_TOOL), with an escape hatch at
.fazhi/allow_tools.txt for legitimate tools that get caught.
Fail-closed > convenient. A safety tool that fails open is worse than no tool — it makes you
think you’re protected when you aren’t.