Block Destructive Commands
Stops irreversible shell commands before they run — recursive deletes of /, ~, . or $HOME, force-pushes to main/master, hard resets to a remote ref, DROP DATABASE, recursive world-writable chmod, mkfs and dd onto block devices — and tells the model a safer alternative.
What it does
Stops irreversible shell commands before they run — recursive deletes of /, ~, . or $HOME, force-pushes to main/master, hard resets to a remote ref, DROP DATABASE, recursive world-writable chmod, mkfs and dd onto block devices — and tells the model a safer alternative.
- Category
- securitysafetygit
- Platforms
- any
- Capabilities
- guardrailcommand-filtering
Example tasks
- “The agent proposes a force-push to main to fix a bad merge and is steered to git revert or a pull request.”
- “A cleanup script ends up deleting the working directory and the hook stops it before anything is removed.”
- “The agent tries a hard reset to origin/main with uncommitted work present and is told to stash or inspect the diff first.”
Works with
Recommended alongside
Permissions summary
Files
Reads files only
Shell
No shell commands
Network
No network
Permissions are declared in the component manifest and compiled into each client's tool list. Components are built for least privilege.
Supported environments
| Client | Support | Installed as |
|---|---|---|
| Claude Code | Native | .forgekit/hooks/<id>/ + .claude/settings.json |
| OpenAI Codex | Not supported | Skipped (reported at install) |
| Cursor | Not supported | Skipped (reported at install) |
| VS Code (Copilot) | Not supported | Skipped (reported at install) |
| Generic markdown | Adapter | docs/forgekit/hooks/<id>.md |
Claude Code is the native reference. Other clients use adapters, so behaviour is close but not identical. See the compatibility matrix.
Included in packs
Full hook (free preview)
This is a free component, so its complete content is public. It is exactly what gets installed (before client-specific formatting).
block-destructive-commands
A PreToolUse guardrail for the Bash tool that refuses a short, explicit list of commands whose damage cannot be undone from inside the session. Each refusal is a single stderr line that names the reason and suggests a safer alternative, so the model can recover without asking you.
What is blocked
| Pattern | Why | Suggested alternative |
|---|---|---|
Recursive rm of /, /*, ~, $HOME, ., ./*, .., a bare *, $PWD, or system directories (/etc, /usr, /var, /home, ...); any rm --no-preserve-root | Wipes the machine, the home directory or the working tree | Delete explicit sub-paths, preview with git clean -n |
git push with --force, --force-with-lease or +ref to main, master or trunk (the current branch is read from .git/HEAD when no refspec is given); deleting those branches; --mirror | Rewrites shared history | Pull request, git revert; on feature branches --force-with-lease is allowed |
git reset --hard onto origin/..., upstream/..., @{u} or FETCH_HEAD | Discards local commits and uncommitted work | Stash first, inspect git diff HEAD..origin/<branch>, then merge or rebase |
DROP DATABASE (any case) and dropdb | Deletes a database | Throwaway local database, or a human after a verified backup |
Recursive chmod with mode 777 or a+rwx | World-writable trees break SSH and expose files | Grant the minimum, for example u+rwX,go+rX |
mkfs*, mke2fs | Formats a filesystem | Human-run, on a verified device |
dd of=/dev/... (except /dev/null, /dev/zero, /dev/stdout) and redirects onto block devices | Overwrites a disk | Write to an image file |
find / -delete, find ~ -delete | Mass deletion | Scope to a project directory, dry-run first |
Wrappers are unwrapped: sudo, env, time, bash -c "...", eval, $(...), ;, && and pipes are all inspected.
What is deliberately allowed
rm -rf ./build, rm -rf node_modules, plain git push origin main, git push --force-with-lease on a feature branch, git reset --hard HEAD, chmod 777 single-file.sh, dd of=./disk.img. The hook only blocks clear matches so it does not train people to turn it off.
Fail-safe behaviour
Empty or malformed input exits 0 with a note. The only filesystem access is reading .git/HEAD to learn the current branch; nothing is spawned and nothing touches the network.
Disable or extend
Remove the block-destructive-commands entry ForgeKit added to .claude/settings.json. To add a project-specific rule, edit checkSegment in scripts/block-destructive-commands.mjs and add a case to scripts/block-destructive-commands.test.mjs. Run the tests with node --test "registry/hooks/block-destructive-commands/scripts/*.test.mjs".
Version and changelog
Latest version 1.0.0. Requires DevBuildKit CLI 1.0.0 or newer.
Changelog — Block Destructive Commands
1.0.0
- Initial release.