From a1a3dfbd631382dc6a77d06f1433420c57c1ebfa Mon Sep 17 00:00:00 2001 From: Sheldon Finlay Date: Thu, 2 Apr 2026 10:42:46 -0400 Subject: [PATCH] fix: use env var instead of tmux check for Stop hook scoping The tmux display-message approach had edge cases: it could succeed outside tmux, fail on first iteration, or behave differently depending on tmux socket state. Replace with AGENT_LOOP_ACTIVE env var exported by loop.sh. CC sessions spawned by the loop inherit it; interactive CC sessions don't. Simple, no external dependencies, no race conditions. --- .claude-plugin/marketplace.json | 2 +- .claude-plugin/plugin.json | 2 +- lib/hooks.sh | 9 ++++----- loop.sh | 1 + 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 08bb3d6..09e8af7 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -10,7 +10,7 @@ "name": "agent-loop", "source": "./", "description": "Autonomous generator-evaluator agent loop for long-running coding tasks. Plan interactively, then execute with full visibility.", - "version": "0.10.0", + "version": "0.10.1", "author": { "name": "Sheldon" }, diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index b446e57..6de794e 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "agent-loop", - "version": "0.10.0", + "version": "0.10.1", "description": "Autonomous generator-evaluator agent loop for long-running coding tasks. Run /agent-loop:run to start.", "author": { "name": "Sheldon" diff --git a/lib/hooks.sh b/lib/hooks.sh index 84a6f60..df7b0de 100644 --- a/lib/hooks.sh +++ b/lib/hooks.sh @@ -14,11 +14,10 @@ SETTINGS_FILE="${PROJECT_ROOT}/.claude/settings.local.json" -# The hook command checks we're inside the agent-loop tmux session before killing. -# This prevents the hook from affecting other CC sessions open in the same project. -# IMPORTANT: Must check $TMUX first — tmux display-message can succeed even outside -# tmux by falling back to the most recently created session, which would be agent-loop. -HOOK_COMMAND='[ -n "$TMUX" ] && tmux display-message -p "#{session_name}" 2>/dev/null | grep -q "^agent-loop$" && kill -INT $PPID || true' +# The hook checks AGENT_LOOP_ACTIVE before killing. This env var is exported by +# loop.sh and inherited by CC sessions it spawns. Interactive CC sessions in the +# same project won't have it set, so the hook is a no-op for them. +HOOK_COMMAND='[ "${AGENT_LOOP_ACTIVE:-}" = "1" ] && kill -INT $PPID || true' install_hooks() { if [ ! -f "$SETTINGS_FILE" ]; then diff --git a/loop.sh b/loop.sh index 940efbe..e593c17 100755 --- a/loop.sh +++ b/loop.sh @@ -111,6 +111,7 @@ while [[ $# -gt 0 ]]; do done export ITERATION=0 MAX_ITERATIONS MODE +export AGENT_LOOP_ACTIVE=1 # --- Validate --- if [[ ! "$MODE" =~ ^(implement|explore|fix)$ ]]; then