Skip to content

Conversation

@ashwin-ant
Copy link
Collaborator

Add typed hook input structures (PreToolUseHookInput, PostToolUseHookInput, etc.) to provide better IDE autocomplete and type safety for hook callbacks. Also convert HookContext from dataclass to TypedDict to match runtime behavior.

Changes:

  • Add BaseHookInput, PreToolUseHookInput, PostToolUseHookInput, UserPromptSubmitHookInput, StopHookInput, SubagentStopHookInput, and PreCompactHookInput TypedDict classes
  • Update HookCallback signature to use HookInput union type
  • Convert HookContext from dataclass to TypedDict (fixes type mismatch)
  • Export all new hook input types from init.py
  • Update all examples and tests to use typed hook inputs

Benefits:

  • Zero breaking changes (TypedDict is dict-compatible at runtime)
  • Full type safety and IDE autocomplete for hook callbacks
  • Matches TypeScript SDK structure exactly
  • Self-documenting hook input fields

🤖 Generated with Claude Code

@ashwin-ant ashwin-ant requested a review from a team October 10, 2025 17:17
km-anthropic
km-anthropic previously approved these changes Oct 10, 2025
Base automatically changed from ashwin/hookfix to main October 10, 2025 17:25
@ashwin-ant ashwin-ant dismissed km-anthropic’s stale review October 10, 2025 17:25

The base branch was changed.

Add typed hook input structures (PreToolUseHookInput, PostToolUseHookInput,
etc.) to provide better IDE autocomplete and type safety for hook callbacks.
Also convert HookContext from dataclass to TypedDict to match runtime behavior.

Changes:
- Add BaseHookInput, PreToolUseHookInput, PostToolUseHookInput,
  UserPromptSubmitHookInput, StopHookInput, SubagentStopHookInput,
  and PreCompactHookInput TypedDict classes
- Update HookCallback signature to use HookInput union type
- Convert HookContext from dataclass to TypedDict (fixes type mismatch)
- Export all new hook input types from __init__.py
- Update all examples and tests to use typed hook inputs

Benefits:
- Zero breaking changes (TypedDict is dict-compatible at runtime)
- Full type safety and IDE autocomplete for hook callbacks
- Matches TypeScript SDK structure exactly
- Self-documenting hook input fields

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@ashwin-ant ashwin-ant force-pushed the ashwin/hooktypesupdate branch from e0ea441 to 2bd04ce Compare October 10, 2025 17:25
@ashwin-ant ashwin-ant merged commit d754e5c into main Oct 10, 2025
26 checks passed
@ashwin-ant ashwin-ant deleted the ashwin/hooktypesupdate branch October 10, 2025 23:22
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.

3 participants