fix: include hook lifecycle events in message stream when include_hook_events is enabled#1007
Open
Oxygen56 wants to merge 1 commit into
Open
fix: include hook lifecycle events in message stream when include_hook_events is enabled#1007Oxygen56 wants to merge 1 commit into
Oxygen56 wants to merge 1 commit into
Conversation
…k_events is enabled Bug: When include_hook_events=True in ClaudeAgentOptions, the --include-hook-events CLI flag was passed correctly and hook callbacks executed, but hook_started and hook_response system messages never appeared in the parsed message stream. Root cause: The CLI needs send includeHookEvents: true in the initialize request (control protocol) to emit hook lifecycle messages to stdout. The SDK only passed --include-hook-events as a CLI flag but never told the CLI via the control protocol. Changes: - Add include_hook_events parameter to Query.__init__() and send it as includeHookEvents: true in the initialize request payload - Pass include_hook_events from InternalClient to Query - Add hook_progress to the recognized system message subtypes in the message parser (matching TypeScript SDK's hook_progress lifecycle) - Update HookEventMessage docstring to document hook_progress - Add tests for hook_progress parsing and includeHookEvents in initialize Closes anthropics#991 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Description
When
include_hook_events=TrueinClaudeAgentOptions, the--include-hook-eventsCLI flag was passed correctly and hook callbacks executed via the control protocol, buthook_startedandhook_responsesystem messages never appeared in the parsed message stream. Onlyinitandstatussystem messages were visible.Root Cause
The Python SDK passed
--include-hook-eventsas a CLI startup flag but did not sendincludeHookEvents: truein the initialize request payload over the control protocol. The CLI needs both signals to emit hook lifecycle events (hook_started,hook_progress,hook_response) to stdout instream-jsonmode.Additionally, the message parser only handled
hook_startedandhook_responsesubtypes but was missinghook_progress, which the TypeScript SDK supports as an intermediate lifecycle update.Changes
src/claude_agent_sdk/_internal/query.py: Addedinclude_hook_eventsparameter toQuery.__init__(). When True, sendsincludeHookEvents: truein the initialize request payload to the CLI.src/claude_agent_sdk/_internal/client.py: Passesinclude_hook_eventsfromClaudeAgentOptionsthrough to theQueryconstructor.src/claude_agent_sdk/_internal/message_parser.py: Addedhook_progressto the recognized system message subtypes alongsidehook_startedandhook_response, matching the TypeScript SDK's lifecycle support.src/claude_agent_sdk/types.py: UpdatedHookEventMessagedocstring to document thehook_progresssubtype.Tests: Added tests for
hook_progressparsing and forincludeHookEventsbeing properly included/omitted in the initialize request.Fixes #991