Repository navigation
claude-bulkhead: a PreToolUse hook for Qwen Code that blocks rm -rf on an empty $VAR, pkill of other sessions and similar #17229
Replies: 1 comment
|
Great tool—the cygpath and $home PowerShell catches are super practical, especially on Windows where automatic variables trip up agents constantly. Regarding the limitation you mentioned: "It reads the command text, so a delete inside a script the agent wrote and then runs is not seen." A clean way to cover that gap in Qwen Code is pairing the run_shell_command hook with a second PreToolUse matcher on file-creation tools (write_file / replace) that scans the incoming content payload for the same destructive AST/regex patterns (e.g., unquoted rm -rf $VAR or Remove-Item -Recurse) before the .sh or .ps1 file ever hits disk. Does bulkhead setup qwen currently only register the matcher for run_shell_command, or are you planning to extend the hook matchers to file-write tools as well? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
claude-bulkhead started as PreToolUse hooks for Claude Code, and 0.5.0 adds Qwen Code. It registers a
PreToolUsehook onrun_shell_commandin~/.qwen/settings.jsonand denies a short list of commands that cannot be undone, with the reason and the safe form, so the model usually rewrites the command on its own.What it blocks, each taken from an accident someone reported this autumn:
rm -rf $D/,rm -rf "$BUILD_DIR"/*andrsync -a --delete src/ $R/when the variable can come out empty (it suggests"${D:?}")rm -rf "$(cygpath -u 'C:\')"and other paths that resolve to a drive root, home, or a whole app-data folder such as~/Library/Application Supportfind ... | xargs -n1 dirname | xargs rm -rf, where a space in a path makesdirnamereturn a parent (it suggests-print0 | xargs -0)rm -rf .giton an existing repositoryRemove-Item -Recurse (Split-Path $home)in PowerShell, where$homeis the automatic variable for the user profilepkill -f nodeorkillall nodewhen the pattern also matches processes from other agent sessions or desktop appsgit add -Aand branch switches in a tree another session is editing, and starting a dev server on a port another session already usesYou can check any command without installing it; nothing is executed:
It reads the command text, so a delete inside a script the agent wrote and then runs is not seen. MIT, no dependencies, Node 18+. Repository: https://github.com/dooly6276/claude-bulkhead
I maintain claude-bulkhead; questions about how it behaves with Qwen Code are welcome here.
All reactions