# A PreToolUse hook that deterministically blocks an AI agent's dangerous tool calls locally — poke holes in the threat model — retained record

> Retained reddit record from reddit:devops.

Canonical: https://highsignal.app/data/records/1bd8d747591e1a0b

[← sources](https://highsignal.app/data)


source: [reddit](https://highsignal.app/data/reddit) (reddit:devops)  published 2026-06-05 17:44 ingested 2026-06-06 08:28

[original source ↗](https://www.reddit.com/r/devops/comments/1txs0bf/a_pretooluse_hook_that_deterministically_blocks/)

## retained text



```
<!-- SC_OFF --><div class="md"><p>I've been building a local-first enforcement layer for AI coding agents and want this community to break the approach before I trust it further.</p> <p>Problem: agents (Claude Code, Cursor, Codex, Gemini CLI, etc.) increasingly run with real shell/tool access. <a href="http://CLAUDE.md">CLAUDE.md</a> / .cursorrules are suggestions the model can ignore, and most &quot;governance&quot; tooling is observability — it tells you about the <code>rm -rf</code> or the <code>.env</code> read after it happened.</p> <p>Approach: intercept at the PreToolUse hook, on the local machine, before the tool call executes. The gate decision is deliberately deterministic — literal pattern match → AST match → scoped rule lookup. No LLM call on the enforcement path, so there's nothing a prompt injection can renegotiate. Where semantic matching is needed (a destructive command not on the literal denylist but close to one we've blocked), it uses local CPU-only bge-small embeddings via LanceDB — no external API.</p> <p>The part I think is actually different from a hand-rolled hook: a block defined once distributes across every connected agent over MCP stdio, instead of living in one tool's config.</p> <p>Stuff I'd want critique on:</p> <ul> <li>Bypass surface: an agent that shells out to a wrapper script to dodge pattern matches. How would you defeat the AST layer?</li> <li>Over-firing: there's a short-TTL break-glass recovery path, but I worry about gates trapping the operator.</li> <li>Whether deterministic-first is the right call vs a model-judged gate.</li> </ul> <p>MIT, Node &gt;=18. Repo: <a href="https://github.com/IgorGanapolsky/ThumbGate">https://github.com/IgorGanapolsky/ThumbGate</a></p> <p>Not selling anything — genuinely want the failure modes I'm not seeing.</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/eazyigz123"> /u/eazyigz123 </a> <br /> <span><a href="https://www.reddit.com/r/devops/comments/1txs0bf/a_pretooluse_hook_that_deterministically_blocks/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/devops/comments/1txs0bf/a_pretooluse_hook_that_deterministically_blocks/">[comments]</a></span>
```



document fetched 2026-06-06 08:28
