File of the day

A Claude Code hook that keeps the agent from wiping your database

Slava Sazhin 23 September 2026 2 min read 2 views

A PreToolUse hook that stops Claude Code before it runs DROP TABLE, TRUNCATE or DELETE without WHERE. One script, a minute to install.

A new series starts today, File of the day: one file from our own setup that you can put into yours the same day. A hook, a prompt, a block for your CLAUDE.md. A few paragraphs on what it does, then the file itself, in full, free to read and download.

What it does

Claude Code runs this script before every terminal command. If the command would destroy data in a database, the hook refuses it and tells Claude why, and Claude looks for another way. It stops:

  • DROP TABLE, TRUNCATE TABLE and DROP DATABASE
  • ALTER TABLE that drops, renames or changes a column (ADD COLUMN passes)
  • DELETE FROM without WHERE

Why a hook and not a line in CLAUDE.md

A rule in CLAUDE.md is a request: the model reads it and usually follows it. A hook runs before the command whatever the model decided, which is what you want when Claude works with permission prompts switched off and nobody is watching.

When you really do need to drop a table

Put CLAUDE_USER_APPROVED=1 in front of the command and it goes through. Add one line to your ~/.claude/CLAUDE.md so that Claude uses the prefix only after you say yes in the conversation; the install note below has the wording. The prefix is a speed bump rather than a lock: Claude can still drop a table, but only on purpose and in plain sight in the transcript. DELETE FROM without WHERE never goes through, prefix or not.

Install

You need jq and perl (on macOS, brew install jq). The script goes into ~/.claude/hooks/, is made executable and is registered under PreToolUse in ~/.claude/settings.json. Every step, and a one-line check that it works, is in the note below. Or hand both files to Claude and ask it to install them.

The files

no-data-deletion-hook.sh 3 KB
how-to-install.md 2 KB

Files of the day are for paying subscribers: any plan opens every one. Already subscribed? Then sign in.

See the plans

Was this article worth your time?

Read next

Give Claude a computer of its own

Your own Linux machine with Claude Code on it, working around the clock while your laptop is shut. From $3.49 a month.

Contact the Combobulating team