mirror of
https://github.com/anthropics/claude-code-sdk-python.git
synced 2025-12-23 09:19:52 +00:00
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:
parent
36c75374ec
commit
75024ecbdf
1 changed files with 26 additions and 1 deletions
|
|
@ -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
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue