Fajl dana

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

Slava Sazhin 23. septembar 2026 2 min čitanja 2 pregleda

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.

Fajlovi

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

Fajlovi dana su za pretplatnike: otvara ih svaki plan. Već imate pretplatu? Onda se prijavite.

Pogledajte planove

Da li je ovaj članak bio vredan vašeg vremena?

Pročitajte i ovo

Sopstveni računar za Claude

Vaš sopstveni Linux računar sa instaliranim Claude Code, koji radi danonoćno dok je vaš laptop zatvoren. Od $3.49 mesečno.

Kontaktirajte tim Combobulating