Skip to content

Add stop and notification hooks, wire up session lifecycle hooks#2136

Merged
dgageot merged 2 commits intodocker:mainfrom
dgageot:board/what-kinfd-of-hook-claude-code-has-and-w-466f6107
Mar 17, 2026
Merged

Add stop and notification hooks, wire up session lifecycle hooks#2136
dgageot merged 2 commits intodocker:mainfrom
dgageot:board/what-kinfd-of-hook-claude-code-has-and-w-466f6107

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 16, 2026

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_start fires at the beginning of RunStream, right after telemetry
  • session_end fires in finalizeEventChannel with context.WithoutCancel so cleanup hooks run even on Ctrl+C

Add stop hook

  • Fires when the model finishes responding (res.Stopped == true)
  • Receives the model's final response content in stop_response field
  • Enables response validation, logging, and analytics

Add notification hook

  • Fires when the agent emits user-facing errors or warnings
  • Receives notification_level (error/warning) and notification_message
  • Fires on: model errors, degenerate tool-call loops, max iterations reached

Also

  • Wire on_user_input at the max-iterations pause point (was missing)
  • Pass session-scoped agent to executeNotificationHooks instead of CurrentAgentName()
  • Update JSON schema, config types, validation, and FromConfig conversion
  • Add unit tests for new hook types
  • Add example YAMLs: hooks_session_lifecycle.yaml, hooks_stop.yaml, hooks_notification.yaml
  • Update docs: docs/configuration/hooks/index.md and docs/configuration/agents/index.md

@dgageot dgageot requested a review from a team as a code owner March 16, 2026 19:07
docker-agent[bot]

This comment was marked as outdated.

trungutt
trungutt previously approved these changes Mar 17, 2026
dgageot added 2 commits March 17, 2026 09:05
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
@dgageot dgageot force-pushed the board/what-kinfd-of-hook-claude-code-has-and-w-466f6107 branch from 9761491 to f298d98 Compare March 17, 2026 08:13
@dgageot dgageot merged commit a5e4548 into docker:main Mar 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants