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
This commit is contained in:
Claude 2025-11-21 20:23:08 +00:00
parent 36c75374ec
commit 75024ecbdf
No known key found for this signature in database

View file

@ -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
)