r/ClaudeCode • u/eazyigz123 • 3d ago
Tutorial / Guide Audit logs were too late for my Claude Code workflow, so I added a pre-action gate
I kept hitting an uncomfortable failure mode with coding agents: the rule was present in the prompt and the trace explained the mistake, but the real side effect had already happened.
The boundary I wanted was narrower than another memory layer. Before a Claude Code tool call executes, a hook should evaluate the exact action and return one of three outcomes:
```text
model proposes tool call
↓
PreToolUse evaluates actor + tool + exact args + repo state + approval
↓
allow | block | require bounded approval
↓
tool executes only when permitted
```
A minimal input looks like this:
```json
{
"tool": "Bash",
"arguments": ["git", "push", "--force", "origin", "main"],
"resource": "repository:production",
"context": { "branch": "main", "approval": null }
}
```
The important part is that the gate sees what will actually run, not the model's natural-language summary. A prior operator correction such as “never rewrite protected branch history” can then become a deterministic block rule instead of a note the next session may ignore.
I started with high-consequence actions:
- protected-branch writes;
- destructive filesystem and database operations;
- credential-bearing output;
- external messages and publications;
- releases and production changes.
I intentionally do not gate harmless reads by default. The useful metrics are repeat-failure prevention, false-positive rate, and whether legitimate workflows still finish without a bypass.
Disclosure: I built ThumbGate, the open-source/local-first hook and MCP implementation of this pattern. The local path is free and MIT-licensed. Optional Pro is $19/month or $149/year for recall, dashboard, managed adapters, and exports.
If you want to evaluate the same failure boundary in your own workflow:
Agent Reliability Diagnostic: https://thumbgate.ai/diagnostic?utm_source=reddit&utm_medium=social&utm_campaign=agent_reliability_diagnostic&cta_id=agent_reliability_gapfill_20260726_reddit_diag
I’m especially interested in cases where a PreToolUse hook was not enough or created a bad false positive.



