Skip to content

Commit 0d14116

Browse files
committed
refactor: update stop hook to use last_assistant_message instead of response_preview for real-time response capture
1 parent 9ee7d72 commit 0d14116

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

hooks/scripts/stop.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ if ! command -v jq &>/dev/null; then
1111
exit 0
1212
fi
1313

14-
# Use response_preview (current turn, first 500 chars) instead of transcript.
15-
# The transcript is written AFTER the Stop hook returns, so transcript-based
16-
# extraction is always one turn behind.
17-
RESPONSE=$(printf '%s' "$INPUT" | jq -r '.response_preview // empty' 2>/dev/null || true)
14+
# Use last_assistant_message (the full text of the current turn's response)
15+
RESPONSE=$(printf '%s' "$INPUT" | jq -r '.last_assistant_message // empty' 2>/dev/null || true)
1816

1917
if [[ -z "$RESPONSE" ]]; then
2018
printf '{"decision":"approve"}\n'

tests/test-hooks.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ mkdir -p "${CLAUDE_PROJECT_DIR}/.claude"
1111
FLAG="${CLAUDE_PROJECT_DIR}/.claude/.claudesay-active"
1212
trap 'rm -f "$TTY_FILE"; rm -rf "$CLAUDE_PROJECT_DIR"' EXIT
1313

14-
# run_stop passes a response_preview string directly, matching the real Stop
15-
# hook input. Using response_preview avoids the one-turn delay caused by the
16-
# transcript being written AFTER the hook returns.
14+
# run_stop passes a last_assistant_message string directly, matching the
15+
# Stop hook input. Using last_assistant_message avoids the one-turn delay
16+
# caused by the transcript being written AFTER the hook returns.
1717
run_stop() {
18-
local preview="$1"
19-
jq -n --arg p "$preview" '{"response_preview":$p}' \
18+
local msg="$1"
19+
jq -n --arg p "$msg" '{"last_assistant_message":$p}' \
2020
| bash "$PLUGIN_ROOT/hooks/scripts/stop.sh"
2121
}
2222

@@ -51,7 +51,7 @@ assert_contains "last tag wins" "$parsed" "second msg"
5151
> "$TTY_FILE"
5252

5353
echo ""
54-
echo "=== stop.sh: empty response_preview → silent approve ==="
54+
echo "=== stop.sh: empty last_assistant_message → silent approve ==="
5555
out=$(run_stop '')
5656
assert_eq "returns approve on empty preview" "$out" '{"decision":"approve"}'
5757

0 commit comments

Comments
 (0)