From 3d8656220573be35d328574ceb46e91dbdf4e288 Mon Sep 17 00:00:00 2001 From: Sheldon Finlay Date: Fri, 27 Mar 2026 16:06:48 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20scope=20Stop=20hook=20to=20per-agent=20?= =?UTF-8?q?=E2=80=94=20prevents=20killing=20orchestrating=20CC=20session?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- loop.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/loop.sh b/loop.sh index e9fd960..3847542 100755 --- a/loop.sh +++ b/loop.sh @@ -148,7 +148,8 @@ cd "$PROJECT_ROOT" cleanup() { [ -n "${LOOP_AGENT_TMPFILE:-}" ] && rm -f "$LOOP_AGENT_TMPFILE" - [ "$AUTO_HOOKS" = true ] && remove_hooks + # Remove hooks in case we exit mid-agent (Ctrl+C during a claude session) + [ "$AUTO_HOOKS" = true ] && remove_hooks 2>/dev/null release_lock } @@ -178,9 +179,8 @@ finish() { } LOOP_AGENT_TMPFILE="" -if [ "$AUTO_HOOKS" = true ]; then - install_hooks -fi +# NOTE: Stop hook is installed/removed per-agent in run_agent(), not globally. +# This prevents the hook from killing the orchestrating CC session. trap cleanup EXIT INT TERM check_archive @@ -231,8 +231,10 @@ run_agent() { local agent_exit=0 if [ "${LOOP_HEADLESS:-false}" != "true" ]; then # --- Interactive mode (Ralph pattern) --- - # Pipe prompt to claude without --print — full interactive UI. - # The Stop hook handles session exit. + # Install Stop hook just before claude starts, remove after it exits. + # This scopes the hook to only affect the loop's claude sessions. + [ "$AUTO_HOOKS" = true ] && install_hooks + ( case "$TOOL" in claude) @@ -248,6 +250,7 @@ run_agent() { esac ) || agent_exit=$? + [ "$AUTO_HOOKS" = true ] && remove_hooks sleep 2 # Brief pause between sessions # Read verdict from file if evaluator wrote one