Wait for Claude Code's final message instead of the stop marker

Commit

gtrrz-victor12h ago

The turn-end transcript wait looked for a hook_progress entry naming the stop hook. Claude Code 2.1.78 wrote one when a hook started; current releases (checked on 2.1.281-2.1.291) record hooks only after they finish (stop_hook_summary), which a wait inside the hook can't see. So the marker never matched, every wait fell back to size stability, and a previous turn's summary could match within the 2s timestamp window and end the wait early.

The Stop payload carries the turn's final assistant text (last_assistant_message, a string on 2.1.291). The wait now returns once the transcript tail holds an end_turn assistant entry with that text and no user entry after it, and falls back to size stability when the text is absent (StopFailure, non-turn-end callers) or never found.

To get the payload to the wait, TurnEnd prefers a new built-in-only TurnEndTranscriptPreparer that receives the event; Event gains FinalAssistantText.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Entire-Checkpoint: 01M48CBBT9M5TK02ZC82NB0D9J

Checkpoints

Handle Claude Code StopFailure Events

Claude CodeOpus 5.5
View session
Checkpoint 1