summaryrefslogtreecommitdiff
path: root/constrain/notevi-only-guard.sh
diff options
context:
space:
mode:
Diffstat (limited to 'constrain/notevi-only-guard.sh')
-rwxr-xr-xconstrain/notevi-only-guard.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/constrain/notevi-only-guard.sh b/constrain/notevi-only-guard.sh
new file mode 100755
index 0000000..729f4d4
--- /dev/null
+++ b/constrain/notevi-only-guard.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+# Claude Code PreToolUse hook (matcher: Bash): deny shell commands that read
+# files without going through notevi. A guardrail, not a jail — it catches the
+# common readers at command position, not every conceivable bypass.
+cmd=$(jq -r '.tool_input.command // empty')
+
+readers='cat|head|tail|less|more|sed|awk|cut|rg|grep|egrep|fgrep|find|fd|strings|xxd|hexdump|od|tac|nl'
+pattern='(^|[;&|(`]|\$\()[[:space:]]*('$readers')([[:space:]]|$)'
+
+if printf '%s' "$cmd" | grep -qE "$pattern"; then
+ echo "blocked: read/search files only through notevi (run 'notevi -doc' for usage)" >&2
+ exit 2
+fi
+vcs='jj[[:space:]]+(file[[:space:]]+show|diff)|git[[:space:]]+(show|diff|grep|cat-file|blame|log)'
+if printf '%s' "$cmd" | grep -qE "(^|[;&|(\`])[[:space:]]*($vcs)"; then
+ echo "blocked: use 'notevi read -r REV FILE' / 'notevi grep -r REV' instead of raw jj/git reads" >&2
+ exit 2
+fi
+exit 0