Claude Code hooks that stop destructive commands.
FailSafe adds Claude Code hooks that read every shell command, and every write or edit to sensitive files, before it runs. Catastrophic actions, such as deleting a home folder or formatting a disk, are blocked, including when hidden in sudo, bash -c, $(...) or inline Python. Risky ones ask you first: force pushes to protected branches, hard resets, dropped tables and DELETE without WHERE, cloud teardown, remote scripts piped into a shell, and edits to credentials, shell start-up files and git internals. A policy file per project sets your own rules. Before any command that throws work away, it saves a way back you can restore.
Free, MIT licence. Node.js 18+.

See it work
FailSafe, in real use.
4 screens from real runs of FailSafe. Every value shown is what the tool returned; click a screen to open it full size.
How it works
Every command, checked before it runs.
FailSafe is a PreToolUse hook. Claude Code hands it each shell command before running it, and it answers in milliseconds with one of three outcomes.
rm -rf ~ /tmp/build-cacherm -rf ~git push --force origin mainrm -rf node_modules distHooks
How Claude Code hooks work, with FailSafe as the example.
A hook is a command Claude Code runs at a set moment. A PreToolUse hook runs before a tool call, receives the call as JSON on stdin, and can answer allow, deny or ask. A deny prevents the call; an ask prompts you to confirm.
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "node ${CLAUDE_PLUGIN_ROOT}/scripts/guard.mjs"
}]
}]
}
}{
"hook_event_name": "PreToolUse",
"tool_name": "Bash",
"tool_input": {
"command": "rm -rf ~ /tmp/build-cache"
},
"cwd": "/home/me/project",
"permission_mode": "default"
}{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "deny",
"permissionDecisionReason":
"FailSafe blocked this command:
recursive delete of \"~\" would wipe
a system or home folder. ..."
}
}Permissions
FailSafe and Claude Code permissions.
Permission rules in settings.json match commands by pattern. A hook reads the whole command line, so it catches what patterns cannot.
| Command | A pattern rule such as Bash(rm -rf:*) | FailSafe |
|---|---|---|
| rm -rf ~ /tmp/build-cache | Matches only if you denied every rm -rf, which blocks normal work too | Blocked: ~ is a home folder |
| sudo env FOO=1 bash -c "rm -rf /" | Starts with sudo, so an rm rule does not match | Blocked: looks inside sudo, env and bash -c |
| git push origin feature/x --force | Any force push rule stops it | Runs: not a protected branch |
| psql -c "DELETE FROM sessions WHERE expires < now()" | No rule can read the SQL | Runs: the DELETE has a WHERE |
| mysql -e "delete from orders" | No rule can read the SQL | Asks: DELETE without WHERE |
Coverage
What it blocks, and what only asks.
Blocking is kept for commands with no plausible everyday use. Anything that could be intended asks instead, so real work is one click away.
- rm -rf of /, a home folder or a system folder
- rm --no-preserve-root
- find / -delete
- mkfs, and dd or redirection onto a disk
- Recursive chmod or chown of system folders
- Fork bombs
- Deletes outside the project
- Force pushes to main, master, release and other protected branches
- git reset --hard, git clean -f, checkout or restore of paths, branch -D, stash drop
- DROP, TRUNCATE, and DELETE or UPDATE without WHERE
- terraform destroy, kubectl delete, cloud delete commands
- curl or wget piped into a shell, npm publish, pkill
- rm -rf node_modules, dist or anything inside the project
- Force pushes to your own feature branches
- git checkout -b, git restore --staged
- DELETE and UPDATE with a WHERE clause
- Everything else Claude Code would normally run
Install
Install FailSafe.
Install FailSafe from the Dude Lemon marketplace inside Claude Code. Node.js 18+.
/plugin marketplace add https://plugins.dudelemon.cloud/marketplace.json/plugin install failsafe@dudelemonRun both commands inside Claude Code. The first adds the Dude Lemon marketplace once; the second installs the plugin.
What it adds
What the plugin adds to Claude Code.
Blocks- rm -rf of /, a home folder or a system folder, find / -delete, moving home or system folders, mkfs, dd onto a disk, recursive chmod or chown of system folders, fork bombs.
Asks first- Deletes outside the project or through an empty variable, force pushes to protected branches, git reset --hard, git clean -f, discarding changes, branch -D, tag and remote deletes, history rewrites.
Data and cloud- DROP, TRUNCATE, DELETE or UPDATE without WHERE, dropdb, Redis FLUSHALL, framework database resets, terraform and pulumi destroy, kubectl delete, Docker volume removal, deletes on AWS, Google Cloud, Azure, Heroku, Vercel, Firebase, Supabase and more.
Files- Writes and edits to SSH, AWS, Kubernetes and npm credentials, shell start-up files, the global git config, system folders, .git internals, and whole .env files.
.claude/failsafe.json- Mode (standard, strict, relaxed), extra protected branches, allow, ask and deny prefixes, and an optional audit log; /failsafe shows it.
Safety net- Before a destructive git command or file delete runs, uncommitted changes, branch tips, dropped stashes and files are saved; /failsafe restore brings them back.
Try it
Use it as you work.
Hooks work on their own; commands run when you type them in Claude Code.
- Clean up the build folders.
- Undo my last commit and push.
- Drop the old sessions table.
FAQ
FailSafe, answered
Anything we have not answered here, ask us directly. A senior engineer replies.
Contact usWhat is the difference between blocking and asking?
A blocked command is refused, and Claude is told to leave it to you. An asking command pauses for your approval in Claude Code, so intended work is one click away.
Can I set my own rules?
Yes. .claude/failsafe.json in a project (or ~/.claude/failsafe.json for all of them) sets the mode, extra protected branches, and command prefixes to allow, ask about or block. /failsafe init creates it.
Which branches count as protected?
main, master, production, prod, release, live, trunk and develop, including names that start with them such as release/2.4, plus any you add in the policy file.
Is FailSafe free?
Yes. FailSafe is free and MIT licensed.
How do I install FailSafe?
In Claude Code run /plugin marketplace add https://plugins.dudelemon.cloud/marketplace.json, then /plugin install failsafe@dudelemon.
Does FailSafe replace my permission settings?
No. It works beside them. Your allow and deny rules still apply; FailSafe adds a check that reads each whole command, including what is inside sudo, env, xargs and bash -c.



