Asks for confirmation before destructive deletes, showing what would be removed

hooks/register.tsx 25 lines1import type { Register } from 'claude-code'
2
3const DESTRUCTIVE = /\b(rm\s+(-\w*[rf]\w*|--recursive|--force)|git\s+clean|git\s+reset\s+--hard|find\b.*\s-delete|shred|truncate)\b/
4
5export const register: Register = on => {
6 const approved = new Set<string>()
7
8 on('tool.call', { tool: 'Bash' }, ($, e, next) => {
9 const command = e.command.trim()
10
11 if (!DESTRUCTIVE.test(command) || approved.has(command)) {
12 return next(e)
13 }
14
15 approved.add(command)
16
17 return {
18 deny:
19 `${$.plugin.name}: this command deletes files:\n ${command}\n` +
20 'List what it would remove (e.g. with ls or a dry run) and tell the user. ' +
21 'If the user confirms, run the exact same command again.',
22 }
23 })
24}
25