Claude Code hooks stop a DROP TABLE locally, not at the database
PreToolUse hooks are a real, documented, hard block: a script that exits with code 2 stops Claude Code's tool call before it runs, even overriding an allow rule. The popular pattern — grep the command for DROP TABLE, TRUNCATE, rm -rf, git push --force, deny it — genuinely works, on the machine it is configured on. What it cannot do is travel with the agent to a teammate's laptop, a CI runner, or a raw psql connection that never goes through Claude Code's own tool-call path at all.
Last checked December 3, 2026.
The real mechanism, not a guess
Claude Code's own hooks reference documents this precisely: on a PreToolUse event, a hook script that exits with code 2 "blocks the tool call," and a hook that blocks "stops the action before permission rules are evaluated" — so the deny applies even if an allow rule would otherwise let the call through. The usual script reads the proposed bash command from stdin, checks it against a deny-list (DROP TABLE, DROP DATABASE, TRUNCATE, terraform destroy -auto-approve, git push --force), and exits 2 with a reason Claude sees as the block's explanation.
Sources: Claude Code docs: Hooks reference (PreToolUse, exit code 2), Claude Code docs: Automate workflows with hooks
What a hook cannot do
- It lives in one settings.json (project or user scope), on one machine. A teammate's clone, a fresh CI container, or tomorrow's re-install starts with none of it unless someone remembers to copy the file over.
- It is editable and deletable by anyone with file access — including the agent itself, if it is ever asked to "clean up the project config."
- It only fires on tool calls Claude Code itself makes. An agent that gets a raw connection string and runs psql, a one-off script, or a different MCP client entirely never passes through this hook at all.
- It leaves no audit trail anyone else can see: a blocked command is a line in one person's terminal, not an event a team or an approver can review later.
The actual block: enforced where the database is
Scribase moves the same deny-dangerous-command instinct to the one place every agent, every machine, and every tool has to go through: the database connection itself. sql_execute is read-only by default — writing requires an explicit read_only: false and the database:write scope on the token presented, not a local config file. migrations_apply is linted before it runs (a table shipped without row level security is refused). And a change that needs production access waits on approvals_wait — a named human approver, not a script anyone could have skipped installing.
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
CREATE POLICY "owner only" ON orders
USING (auth.uid() = user_id);Sources: Scribase docs: Production approver, Scribase docs: Tokens and safety
Questions people ask
Do Claude Code hooks actually block dangerous commands, or is that a myth?
They really do, for the specific case they cover: Claude Code's own documentation confirms a PreToolUse hook exiting with code 2 blocks the tool call before permission rules are even evaluated. A script that greps for DROP TABLE or rm -rf and exits 2 genuinely prevents that one call on that one machine.
So why isn't a hook enough on its own?
A hook is local config: one settings.json, on one machine, for one agent's own tool-call path. It does not follow the agent to a teammate's laptop or a CI runner, can be edited or deleted by anyone with file access, and does nothing for a command that never goes through Claude Code at all (a raw psql connection, a different MCP client).
Where should the real block live instead?
At the database connection itself, enforced server-side for every token regardless of which agent or machine is calling: read-only by default, migrations linted for row level security, and a named human approver gating anything that reaches production.
Should I stop using Claude Code hooks, then?
No — they are a useful extra layer for fast local feedback. The point is not to replace them, it is to not rely on them as the only thing standing between an agent and production, since they protect one machine, not the data.