Add stop and notification hooks, wire up session lifecycle hooks#2136
Merged
dgageot merged 2 commits intodocker:mainfrom Mar 17, 2026
Merged
Conversation
trungutt
previously approved these changes
Mar 17, 2026
Wire up session_start and session_end hooks that were defined but never called from the runtime. session_start fires at the beginning of RunStream, session_end fires in finalizeEventChannel with a cancellation-resistant context so cleanup hooks run even on Ctrl+C. Add a new 'stop' hook that fires when the model finishes responding and is about to return control to the user. The hook receives the model's final response content in the stop_response field, enabling response validation, logging, and analytics. Add a new 'notification' hook that fires when the agent emits user-facing errors or warnings (model failures, degenerate loops, max iterations). The hook receives notification_level and notification_message fields. Also wire on_user_input at the max-iterations-reached pause point where it was previously missing. Update documentation, JSON schema, config types, and add examples. Assisted-By: docker-agent
- Propagate session_start hook additional_context as a system message into the session so the agent can actually use it - Validate notification hook level against allowed values (error/warning) - Upgrade session_end hook error logging from Warn to Error for visibility Assisted-By: docker-agent
9761491 to
f298d98
Compare
trungutt
approved these changes
Mar 17, 2026
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
Wire up session lifecycle hooks and add two new hook event types matching Claude Code's hook system.
Changes
Wire up session_start / session_end hooks
session_startfires at the beginning ofRunStream, right after telemetrysession_endfires infinalizeEventChannelwithcontext.WithoutCancelso cleanup hooks run even on Ctrl+CAdd
stophookres.Stopped == true)stop_responsefieldAdd
notificationhooknotification_level(error/warning) andnotification_messageAlso
on_user_inputat the max-iterations pause point (was missing)executeNotificationHooksinstead ofCurrentAgentName()FromConfigconversionhooks_session_lifecycle.yaml,hooks_stop.yaml,hooks_notification.yamldocs/configuration/hooks/index.mdanddocs/configuration/agents/index.md