Skip to content

HookJSONOutput type is not exported in __init__.py #203

@kushal-goenka

Description

@kushal-goenka

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
      # ...
  ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions