--- /dev/null
+#!/bin/sh
+# Copyright (c) 2026 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+#
+# block-builds - Guard guix/make build/reconfigure.
+
+command=$($GUIX_BIN/sed --quiet \
+ 's/.*"command"[[:space:]]*:[[:space:]]*"\([^"]\+\)".*/\1/p')
+case "$command" in
+ *'guix home build'*|*'guix system build'*)
+ $GUIX_BIN/echo \
+ '{"hookSpecificOutput": {' \
+ ' "hookEventName": "PreToolUse",' \
+ ' "permissionDecision": "ask"' \
+ '}}'
+ exit 0
+ ;;
+ *'guix home reconfigure'*|*'guix system reconfigure'*)
+ if $GUIX_BIN/echo "$PWD" | $GUIX_BIN/grep -q '/worktrees/'
+ then
+ $GUIX_BIN/echo \
+ '{"hookSpecificOutput": {' \
+ ' "hookEventName": "PreToolUse",' \
+ ' "permissionDecision": "deny",' \
+ ' "systemMessage": "🚫 Reconfigure only on main worktree."' \
+ '}}'
+ exit 0
+ fi
+ $GUIX_BIN/echo \
+ '{"hookSpecificOutput": {' \
+ ' "hookEventName": "PreToolUse",' \
+ ' "permissionDecision": "ask"' \
+ '}}'
+ exit 0
+ ;;
+ *'make build-'*)
+ $GUIX_BIN/echo \
+ '{"hookSpecificOutput": {' \
+ ' "hookEventName": "PreToolUse",' \
+ ' "permissionDecision": "ask"' \
+ '}}'
+ exit 0
+ ;;
+ *'make home-'*|*'make system-'*)
+ if $GUIX_BIN/echo "$PWD" | $GUIX_BIN/grep -q '/worktrees/'
+ then
+ $GUIX_BIN/echo \
+ '{"hookSpecificOutput": {' \
+ ' "hookEventName": "PreToolUse",' \
+ ' "permissionDecision": "deny",' \
+ ' "systemMessage": "🚫 Reconfigure only on main worktree."' \
+ '}}'
+ exit 0
+ fi
+ $GUIX_BIN/echo \
+ '{"hookSpecificOutput": {' \
+ ' "hookEventName": "PreToolUse",' \
+ ' "permissionDecision": "ask"' \
+ '}}'
+ exit 0
+ ;;
+esac
+++ /dev/null
-#!/bin/sh
-# Copyright (c) 2026 Jakub Czajka <jakub@ekhem.eu.org>
-# License: GPL-3.0 or later.
-#
-# guard-commands — PreToolUse hook that guards against dangerous or
-# branch-inappropriate commands.
-
-cmd=$($GUIX_BIN/cat | $GUIX_BIN/sed --regexp-extended --quiet \
- 's/.*"command"\s*:\s*"([^"]+)".*/\1/p')
-[ -z "$cmd" ] && exit 0
-
-branch=$($HOME/.guix-home/profile/bin/git -C "$CLAUDE_PROJECT_DIR" \
- branch --show-current 2>/dev/null)
-
-# --- git checkout / git switch: deny everywhere ---
-if $GUIX_BIN/echo "$cmd" | $GUIX_BIN/grep --extended-regexp --quiet \
- '\bgit (checkout|switch)\b'; then
- $GUIX_BIN/echo \
- '{"hookSpecificOutput": {' \
- ' "hookEventName": "PreToolUse",' \
- ' "permissionDecision": "deny",' \
- ' "systemMessage": "Branch switching disabled. Use EnterWorktree."' \
- '}}'
- exit 0
-fi
-
-# --- make build-*: ask everywhere ---
-if $GUIX_BIN/echo "$cmd" | $GUIX_BIN/grep --extended-regexp --quiet \
- '\bmake build-'; then
- $GUIX_BIN/echo \
- '{"hookSpecificOutput": {' \
- ' "hookEventName": "PreToolUse",' \
- ' "permissionDecision": "ask"' \
- '}}'
- exit 0
-fi
-
-# --- guix build: ask everywhere ---
-if $GUIX_BIN/echo "$cmd" | $GUIX_BIN/grep --extended-regexp --quiet \
- '\bguix (home|system) build\b'; then
- $GUIX_BIN/echo \
- '{"hookSpecificOutput": {' \
- ' "hookEventName": "PreToolUse",' \
- ' "permissionDecision": "ask"' \
- '}}'
- exit 0
-fi
-
-# --- guix reconfigure: ask on main, deny on branches ---
-if $GUIX_BIN/echo "$cmd" | $GUIX_BIN/grep --extended-regexp --quiet \
- '\bguix (home|system) reconfigure\b'; then
- if [ "$branch" != "main" ]; then
- $GUIX_BIN/echo \
- '{"hookSpecificOutput": {' \
- ' "hookEventName": "PreToolUse",' \
- ' "permissionDecision": "deny",' \
- ' "systemMessage": "guix reconfigure blocked. Merge into main."' \
- '}}'
- exit 0
- fi
- $GUIX_BIN/echo \
- '{"hookSpecificOutput": {' \
- ' "hookEventName": "PreToolUse",' \
- ' "permissionDecision": "ask"' \
- '}}'
- exit 0
-fi
-
-# --- make home-* / make system-*: ask on main, deny on branches ---
-if $GUIX_BIN/echo "$cmd" | $GUIX_BIN/grep --extended-regexp --quiet \
- '\bmake (home|system)-'; then
- if [ "$branch" != "main" ]; then
- $GUIX_BIN/echo \
- '{"hookSpecificOutput": {' \
- ' "hookEventName": "PreToolUse",' \
- ' "permissionDecision": "deny",' \
- ' "systemMessage": "Reconfigure blocked. Merge into main."' \
- '}}'
- exit 0
- fi
- $GUIX_BIN/echo \
- '{"hookSpecificOutput": {' \
- ' "hookEventName": "PreToolUse",' \
- ' "permissionDecision": "ask"' \
- '}}'
- exit 0
-fi
-
-exit 0