Claude Code PreToolUse hook: deny a command before it runs
Claude Code runs your PreToolUse hooks before every tool call, and a hook can deny the call. For a short, fixed list of commands, write the hook or a deny rule yourself. ThumbGate is a PreToolUse hook whose rules come from your thumbs-downs, and it denies catastrophic commands by default. Free and local (npm 1.64.0).
In short
- PreToolUse runs before the tool call, and a hook that returns a deny decision stops it. PostToolUse runs after the call, too late to stop it.
- For a few commands you never want run, a deny rule in your Claude Code permissions or a hook you write is enough, and free.
- ThumbGate adds the rules you would otherwise write by hand: give a command a thumbs-down and it is Denied the next time the agent tries it, with your reason (if that rule would also have blocked commands you allowed before, it warns instead).
What the PreToolUse hook does
Before a tool runs, Claude Code sends each PreToolUse hook the tool name and its input as JSON (for Bash, the command). The hook can let the call through, ask you, or deny it with a reason the agent sees. Hooks live in ~/.claude/settings.json or in the project's .claude/settings.json.
Cursor has the same kind of hook (beforeShellExecution and preToolUse). MCP-only clients such as Cline and OpenCode do not, so a check there is Advisory: the agent has to call it, and nothing stops a command it skips.
What ThumbGate denies by default (npm 1.64.0)
- git push --force, git reset --hard, git clean -fdx, rm -rf on home or root, find / -delete and DROP TABLE.
- Cloud and cluster wipes such as terraform destroy, kubectl delete and aws s3 rm.
- Sending a secret out, for example curl -d @.env.
- git push origin main. Lift it for an hour with npx thumbgate unblock protected-branch-push --reason "why you need it".
- Switching ThumbGate off from inside the agent, for example pkill -f thumbgate.
- Any command you gave a thumbs-down, the next time it runs. If that rule would also have blocked commands you let through before, it stays a Warning.
What is only a Warning, and what it does not catch
Other flagged actions, such as npm publish or git commit --no-verify, are a Warning by default: the agent sees the reason and the command can still run. Strict mode (THUMBGATE_STRICT_ENFORCEMENT=1) denies them instead.
A learned rule matches the command, not its purpose. If you give rm -rf a thumbs-down and the agent then deletes the same folder from Python, the rule does not catch it. ThumbGate is not a sandbox.
Write your own hook, or use ThumbGate?
Write your own when the list is short and stable. A small script that reads the command and prints a deny decision is free, and you understand all of it.
Use ThumbGate when the list keeps growing from real sessions and you would rather give a thumbs-down in the chat than edit a script. npx thumbgate rules lists every learned rule, and npx thumbgate unblock <gate-id> --reason "why you need it" lifts one for an hour.
Install, check and remove
- Install in your project folder: npx thumbgate init --agent claude. It adds ThumbGate's hooks and status line to ~/.claude/settings.json and a .thumbgate/ folder for your lessons.
- Restart Claude Code. The status line shows ThumbGate ยท Free.
- Check it: echo '{"tool_name":"Bash","tool_input":{"command":"git push --force"}}' | npx thumbgate gate-check should print "permissionDecision":"deny" and [GATE:force-push].
- Remove it: from the next npm release, run npx thumbgate uninstall in your own terminal. Until then, delete the ThumbGate entries under hooks and statusLine in ~/.claude/settings.json.
FAQ
Do I need ThumbGate if Claude Code already has hooks?
Not for a fixed list of commands: write a deny rule or a hook. ThumbGate is a hook whose rules come from your thumbs-downs, plus default checks for catastrophic commands, so you stop writing a new rule each time the agent repeats a mistake.
Does the hook call a cloud service to decide?
No. The decision runs in the hook process on your machine, and your lessons and rules stay in .thumbgate/ in your repo. The CLI sends anonymous usage events, never the words of your rules; THUMBGATE_NO_TELEMETRY=1 turns them off.
What does it cost?
Free includes every default Denied check, 3 active learned rules and 2 thumbs a day. Pro is $19/month or $149/year and keeps every learned rule active, with recall and lesson search.