Skip to content

feat: add agent_id/agent_type fields to hook input types #1

@Flohs

Description

@Flohs

Background

The Python SDK added agent_id and agent_type fields to hook input types in PR #628. These fields are critical for correlating tool calls to specific sub-agents when multiple agents run in parallel.

The affected hook input types in Python are:

  • PreToolUseHookInput
  • PostToolUseHookInput
  • PostToolUseFailureHookInput
  • PermissionRequestHookInput

Current State in Go SDK

The Go SDK uses a generic map[string]any for HookInput (hooks.go:24):

type HookInput map[string]any

While the map approach is flexible (the fields would be present in the map if the CLI sends them), it provides no type safety or discoverability for consumers.

Proposal

Introduce typed structs for hook inputs, with optional AgentID and AgentType fields:

type BaseHookInput struct {
    SessionID      string `json:"session_id"`
    TranscriptPath string `json:"transcript_path"`
    Cwd            string `json:"cwd"`
    PermissionMode string `json:"permission_mode"`
    HookEventName  string `json:"hook_event_name"`
    AgentID        string `json:"agent_id,omitempty"`
    AgentType      string `json:"agent_type,omitempty"`
}

type PreToolUseHookInput struct {
    BaseHookInput
    ToolName  string         `json:"tool_name"`
    ToolInput map[string]any `json:"tool_input"`
}

// ... similar for PostToolUse, PostToolUseFailure, PermissionRequest

Alternatively, keep HookInput as map[string]any for forward-compatibility but add typed accessor methods or a helper to extract these fields safely.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions