Skip to content

fix(stop-hook): don't trip the ERR trap on the normal no-active-loop case - #9

Open
mahlerm454 wants to merge 1 commit into
promptadvisers:mainfrom
mahlerm454:fix/stop-hook-no-active-loop-err-trap
Open

fix(stop-hook): don't trip the ERR trap on the normal no-active-loop case#9
mahlerm454 wants to merge 1 commit into
promptadvisers:mainfrom
mahlerm454:fix/stop-hook-no-active-loop-err-trap

Conversation

@mahlerm454

Copy link
Copy Markdown

Problem

claudex_find_active_loop returns exit code 1 by design when no loop is active (state-helpers.sh: "They return non-zero on failure so the caller can decide how to handle it"). But that is the normal case in almost every session — and the bare command-substitution assignment in the stop hook lets that expected non-zero status fire the ERR trap installed a few lines above:

[2026-07-16T09:32:15Z] Hook fired. Input bytes: 2267
[2026-07-16T09:32:15Z] ERR trap at line 67; failing open

The clean approve "no active loop" path right below the assignment is never reached. The outcome happens to be identical (both paths approve), so nothing user-visible breaks — but the log fills up with pseudo-errors on every ordinary turn, and the ERR trap no longer distinguishes real failures from business as usual.

Fix

Guard the assignment with || true so the expected no-loop case takes the intended code path, and the ERR trap goes back to being a net for unexpected errors only.

Verification

  • No state file → {"decision":"approve"}, log shows APPROVE: no active loop
  • Active plan loop (phase: drafting, PLAN.md missing) → correct {"decision":"block", ...} with the drafting instructions

🤖 Generated with Claude Code

…case

claudex_find_active_loop returns exit code 1 by design when no loop is
active — which is the normal case in almost every session. The bare
command-substitution assignment at the top of the stop hook let that
expected non-zero status fire the ERR trap, so every ordinary session
logged "ERR trap at line 67; failing open" instead of taking the clean
`approve "no active loop"` path right below it.

Guard the assignment with `|| true` so the ERR trap goes back to being
what it is meant to be: a net for unexpected errors only.

Verified both paths: no state file → {"decision":"approve"} with
"APPROVE: no active loop" logged; active plan loop (drafting, missing
PLAN.md) → correct block decision.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant