claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

HookJSONOutput type is not exported in __init__.py

Open kushal-goenka opened this issue 3 months ago • 0 comments

Problem

HookJSONOutput is defined in types.py and used as the return type for HookCallback:

  HookCallback = Callable[
      [dict[str, Any], str | None, HookContext],
      Awaitable[HookJSONOutput],
  ]

However, HookJSONOutput is not exported in init.py, which causes type checking issues when implementing hook callbacks.

Current Workaround

Users need to either:

  1. Import from the private module: from claude_agent_sdk.types import HookJSONOutput
  2. Define their own TypedDict matching the structure
  3. Use dict[str, Any] and lose type safety

Example Code

from claude_agent_sdk import HookContext

HookJSONOutput is not available

  async def my_hook(
      input_data: dict[str, Any],
      tool_use_id: str | None,
      context: HookContext,
  ) -> HookJSONOutput:  # Type error: HookJSONOutput not found
      return {"decision": "block", "systemMessage": "Not allowed"}

Suggested Fix

Add HookJSONOutput to the all list in init.py:

  __all__ = [
      # ... existing exports
      "HookCallback",
      "HookContext",
      "HookMatcher",
      "HookJSONOutput",  # Add this
      # ...
  ]

kushal-goenka avatar Oct 03 '25 21:10 kushal-goenka