From 75024ecbdf319ebf060f758493cd1d012037b9e2 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 21 Nov 2025 20:23:08 +0000 Subject: [PATCH] feat: add SessionStart and SessionEnd hook event types Add support for SessionStart and SessionEnd hook events: - SessionStartHookInput with source field (startup, resume, clear, compact) - SessionEndHookInput with reason field (clear, logout, prompt_input_exit, other) - SessionEndHookSpecificOutput for hook-specific output - Update HookEvent and HookInput union types to include new events --- src/claude_agent_sdk/types.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/claude_agent_sdk/types.py b/src/claude_agent_sdk/types.py index 81e19ac..94c273c 100644 --- a/src/claude_agent_sdk/types.py +++ b/src/claude_agent_sdk/types.py @@ -146,7 +146,7 @@ CanUseTool = Callable[ ##### Hook types # Supported hook event types. Due to setup limitations, the Python SDK does not -# support SessionStart, SessionEnd, and Notification hooks. +# support Notification hooks. HookEvent = ( Literal["PreToolUse"] | Literal["PostToolUse"] @@ -154,6 +154,8 @@ HookEvent = ( | Literal["Stop"] | Literal["SubagentStop"] | Literal["PreCompact"] + | Literal["SessionStart"] + | Literal["SessionEnd"] ) @@ -213,6 +215,20 @@ class PreCompactHookInput(BaseHookInput): custom_instructions: str | None +class SessionStartHookInput(BaseHookInput): + """Input data for SessionStart hook events.""" + + hook_event_name: Literal["SessionStart"] + source: Literal["startup", "resume", "clear", "compact"] + + +class SessionEndHookInput(BaseHookInput): + """Input data for SessionEnd hook events.""" + + hook_event_name: Literal["SessionEnd"] + reason: Literal["clear", "logout", "prompt_input_exit", "other"] + + # Union type for all hook inputs HookInput = ( PreToolUseHookInput @@ -221,6 +237,8 @@ HookInput = ( | StopHookInput | SubagentStopHookInput | PreCompactHookInput + | SessionStartHookInput + | SessionEndHookInput ) @@ -255,11 +273,18 @@ class SessionStartHookSpecificOutput(TypedDict): additionalContext: NotRequired[str] +class SessionEndHookSpecificOutput(TypedDict): + """Hook-specific output for SessionEnd events.""" + + hookEventName: Literal["SessionEnd"] + + HookSpecificOutput = ( PreToolUseHookSpecificOutput | PostToolUseHookSpecificOutput | UserPromptSubmitHookSpecificOutput | SessionStartHookSpecificOutput + | SessionEndHookSpecificOutput )