Add proposal scraper Stop hook example#48714
Open
WGlynn wants to merge 1 commit intoanthropics:mainfrom
Open
Conversation
Adds examples/hooks/proposal_scraper_example.py — a Stop hook that persists option/alternative blocks from assistant responses to a PROPOSALS.md file so they survive session crashes, context compaction, and API errors. Motivation: when an assistant proposes options (Option A/B/C, numbered alternatives) and a session crashes before the user decides, the options exist only in the chat transcript. Regenerating them in a new session produces different options because LLMs are non-deterministic. Persisting proposals the moment they are generated makes the file the source of truth and the chat a view. Detection heuristics: - Strong signal (auto-trigger): explicit option labels (Option A/B/C, cycle IDs like C11-A, "Option A:") outside of code spans. - Weak signal: two or more numbered bold items plus a proximity keyword (options, propose, alternative, pick one, which of, choose). - Matches inside backtick code spans are ignored so that documentation of the trigger patterns does not self-trigger. The hook is fail-open: any error returns cleanly without blocking the turn. This adds a second example to examples/hooks/ (alongside the existing bash_command_validator_example.py) demonstrating a different hook type (Stop vs PreToolUse).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a second example to
examples/hooks/— a Stop hook that persists proposal blocks (options, alternatives) from assistant responses to aPROPOSALS.mdfile so they survive session crashes, context compaction, and API errors.Alongside the existing
bash_command_validator_example.py(aPreToolUsehook), this demonstrates a different hook type (Stop) and a different use case (output persistence vs input validation).Motivation
When an assistant proposes options for a user to choose between —
**Option A**/**Option B**/**Option C**, or a numbered decision slate — and the session crashes before the user decides, the options exist only in the chat transcript. Regenerating them in a new session produces different options because LLM sampling is non-deterministic. Persisting proposals the moment they are generated makes the file the source of truth and the chat a view.Detection
The hook uses two layers of detection:
**Option A**, cycle-style IDs like**C11-A**, orOption A:prose) appearing outside of code spans.options,propose,alternative,pick one,which of,choose). This prevents false positives on structured summaries that happen to use numbered bold lists.Matches inside backtick code spans are stripped before detection so that documentation of the trigger patterns (including this PR description) does not self-trigger.
Behavior
transcript_pathfield from the hook context..claude/PROPOSALS.md(project-local) or falls back to the current working directory.Testing
The hook was developed iteratively and has been tested against a corpus of real proposal and non-proposal content, including:
**Option A**/**Option B**blocks (triggers)**C11-A**labels (triggers)Style
Follows the convention of
bash_command_validator_example.py:settings.jsonsnippetConfiguration
{ "hooks": { "Stop": [ { "hooks": [ { "type": "command", "command": "python3 /path/to/claude-code/examples/hooks/proposal_scraper_example.py" } ] } ] } }