From dad4f1920bf5d20101c539830016ef5a1b31c69b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Sat, 25 Jul 2026 13:48:20 +0200 Subject: [PATCH] Make the Claude stop-check blocking with autofix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Move the Stop hook into .claude/hooks/check-on-stop.sh. On a failed `make check` it exits 2, which makes Claude Code block the stop and feed the check output back to the agent to fix, instead of only reporting it; a passing check exits 0 and lets the turn end. * It re-runs until green — interrupt to break out, or guard on the hook input's stop_hook_active to cap it at one attempt. --- .claude/hooks/check-on-stop.sh | 13 +++++++++++++ .claude/settings.json | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100755 .claude/hooks/check-on-stop.sh diff --git a/.claude/hooks/check-on-stop.sh b/.claude/hooks/check-on-stop.sh new file mode 100755 index 0000000..318c0e3 --- /dev/null +++ b/.claude/hooks/check-on-stop.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# Stop hook: run the quality gate. On failure, exit 2 so Claude Code blocks the +# stop and hands the output back to the agent to fix; on success, exit 0 to let +# the turn end. It keeps retrying until green — interrupt to break out, or guard +# on the input's stop_hook_active to cap it at one attempt. +set -uo pipefail + +cd "${CLAUDE_PROJECT_DIR:-.}" || exit 0 + +if ! output=$(make check 2>&1); then + printf '%s\n' "$output" >&2 + exit 2 +fi diff --git a/.claude/settings.json b/.claude/settings.json index 953faad..ed666b4 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -5,7 +5,7 @@ "hooks": [ { "type": "command", - "command": "cd \"$CLAUDE_PROJECT_DIR\" && make check" + "command": "\"$CLAUDE_PROJECT_DIR/.claude/hooks/check-on-stop.sh\"" } ] } -- 2.51.2