Skip to content

Commit 0d26581

Browse files
committed
block direct execution of stop hook scripts during active loops
1 parent 80ac4b0 commit 0d26581

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

hooks/lib/loop-common.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,20 @@ IMPORTANT: The commit message must NOT contain the literal string \".humanize\"
11951195
load_and_render_safe "$TEMPLATE_DIR" "block/git-add-humanize.md" "$fallback"
11961196
}
11971197

1198+
# Standard message for blocking direct execution of hook scripts
1199+
# Usage: stop_hook_direct_execution_blocked_message
1200+
stop_hook_direct_execution_blocked_message() {
1201+
local fallback="# Direct Execution of Hook Scripts Blocked
1202+
1203+
You are attempting to directly execute a hook script via Bash. This is not allowed during an active loop.
1204+
1205+
Hook scripts are managed by the hooks system and are triggered automatically at the appropriate time. You should NOT execute them manually.
1206+
1207+
Simply complete your work and end your response. The hooks system will handle the rest automatically."
1208+
1209+
load_and_render_safe "$TEMPLATE_DIR" "block/stop-hook-direct-execution.md" "$fallback"
1210+
}
1211+
11981212
# Check if a shell command attempts to modify a file matching the given pattern
11991213
# Usage: command_modifies_file "$command_lower" "goal-tracker\.md"
12001214
# Returns 0 if the command tries to modify the file, 1 otherwise

hooks/loop-bash-validator.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ if [[ -z "$ACTIVE_LOOP_DIR" ]] && [[ -z "$ACTIVE_PR_LOOP_DIR" ]]; then
6969
exit 0
7070
fi
7171

72+
# ========================================
73+
# Block Direct Execution of Hook Scripts
74+
# ========================================
75+
# Prevents Claude from manually running stop hook or stop gate scripts.
76+
# These scripts should only be invoked by the hooks system, not via Bash.
77+
78+
BLOCKED_HOOK_SCRIPTS="(loop-codex-stop-hook\.sh|pr-loop-stop-hook\.sh|rlcr-stop-gate\.sh)"
79+
if echo "$COMMAND_LOWER" | grep -qE "$BLOCKED_HOOK_SCRIPTS"; then
80+
stop_hook_direct_execution_blocked_message >&2
81+
exit 2
82+
fi
83+
7284
# ========================================
7385
# RLCR Loop Specific Checks
7486
# ========================================
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Direct Execution of Hook Scripts Blocked
2+
3+
You are attempting to directly execute a hook script via Bash. This is not allowed during an active loop.
4+
5+
Hook scripts are managed by the hooks system and are triggered automatically at the appropriate time. You should NOT execute them manually.
6+
7+
Simply complete your work and end your response. The hooks system will handle the rest automatically.

0 commit comments

Comments
 (0)