fix: scope Stop hook to per-agent — prevents killing orchestrating CC session

This commit is contained in:
2026-03-27 16:06:48 -04:00
parent a9af753a2e
commit 3d86562205

15
loop.sh
View File

@@ -148,7 +148,8 @@ cd "$PROJECT_ROOT"
cleanup() { cleanup() {
[ -n "${LOOP_AGENT_TMPFILE:-}" ] && rm -f "$LOOP_AGENT_TMPFILE" [ -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 release_lock
} }
@@ -178,9 +179,8 @@ finish() {
} }
LOOP_AGENT_TMPFILE="" LOOP_AGENT_TMPFILE=""
if [ "$AUTO_HOOKS" = true ]; then # NOTE: Stop hook is installed/removed per-agent in run_agent(), not globally.
install_hooks # This prevents the hook from killing the orchestrating CC session.
fi
trap cleanup EXIT INT TERM trap cleanup EXIT INT TERM
check_archive check_archive
@@ -231,8 +231,10 @@ run_agent() {
local agent_exit=0 local agent_exit=0
if [ "${LOOP_HEADLESS:-false}" != "true" ]; then if [ "${LOOP_HEADLESS:-false}" != "true" ]; then
# --- Interactive mode (Ralph pattern) --- # --- Interactive mode (Ralph pattern) ---
# Pipe prompt to claude without --print — full interactive UI. # Install Stop hook just before claude starts, remove after it exits.
# The Stop hook handles session exit. # This scopes the hook to only affect the loop's claude sessions.
[ "$AUTO_HOOKS" = true ] && install_hooks
( (
case "$TOOL" in case "$TOOL" in
claude) claude)
@@ -248,6 +250,7 @@ run_agent() {
esac esac
) || agent_exit=$? ) || agent_exit=$?
[ "$AUTO_HOOKS" = true ] && remove_hooks
sleep 2 # Brief pause between sessions sleep 2 # Brief pause between sessions
# Read verdict from file if evaluator wrote one # Read verdict from file if evaluator wrote one