Documentation
¶
Overview ¶
Package claude exposes typed public hook inputs, responses, and registrars for Claude plugin runtime integrations.
Index ¶
- func OutcomeFromResponse(r *Response) internalclaude.StopOutcome
- func PreToolOutcomeFromResponse(r *PreToolResponse) internalclaude.PreToolUseOutcome
- func RegisterCustomCommonJSON[T any](r *Registrar, eventName string, fn func(*T) *CommonResponse) error
- func RegisterCustomContextJSON[T any](r *Registrar, eventName string, fn func(*T) *ContextResponse) error
- func RegisterCustomPermissionRequestJSON[T any](r *Registrar, eventName string, fn func(*T) *PermissionRequestResponse) error
- func RegisterCustomPostToolUseJSON[T any](r *Registrar, eventName string, fn func(*T) *PostToolUseResponse) error
- func UserPromptOutcomeFromResponse(r *UserPromptResponse) internalclaude.UserPromptSubmitOutcome
- type CommonResponse
- type ConfigChangeEvent
- type ConfigChangeResponse
- type ContextResponse
- type NotificationEvent
- type NotificationResponse
- type PermissionBehavior
- type PermissionDecision
- type PermissionRequestEvent
- type PermissionRequestResponse
- type PermissionRuleValue
- type PermissionUpdate
- type PostToolUseEvent
- type PostToolUseFailureEvent
- type PostToolUseFailureResponse
- type PostToolUseResponse
- type PreCompactEvent
- type PreCompactResponse
- type PreToolResponse
- type PreToolUseEvent
- type Registrar
- func (r *Registrar) OnConfigChange(fn func(*ConfigChangeEvent) *ConfigChangeResponse)
- func (r *Registrar) OnNotification(fn func(*NotificationEvent) *NotificationResponse)
- func (r *Registrar) OnPermissionRequest(fn func(*PermissionRequestEvent) *PermissionRequestResponse)
- func (r *Registrar) OnPostToolUse(fn func(*PostToolUseEvent) *PostToolUseResponse)
- func (r *Registrar) OnPostToolUseFailure(fn func(*PostToolUseFailureEvent) *PostToolUseFailureResponse)
- func (r *Registrar) OnPreCompact(fn func(*PreCompactEvent) *PreCompactResponse)
- func (r *Registrar) OnPreToolUse(fn func(*PreToolUseEvent) *PreToolResponse)
- func (r *Registrar) OnSessionEnd(fn func(*SessionEndEvent) *SessionEndResponse)
- func (r *Registrar) OnSessionStart(fn func(*SessionStartEvent) *SessionStartResponse)
- func (r *Registrar) OnSetup(fn func(*SetupEvent) *SetupResponse)
- func (r *Registrar) OnStop(fn func(*StopEvent) *Response)
- func (r *Registrar) OnSubagentStart(fn func(*SubagentStartEvent) *SubagentStartResponse)
- func (r *Registrar) OnSubagentStop(fn func(*SubagentStopEvent) *SubagentStopResponse)
- func (r *Registrar) OnTaskCompleted(fn func(*TaskCompletedEvent) *TaskCompletedResponse)
- func (r *Registrar) OnTeammateIdle(fn func(*TeammateIdleEvent) *TeammateIdleResponse)
- func (r *Registrar) OnUserPromptSubmit(fn func(*UserPromptEvent) *UserPromptResponse)
- func (r *Registrar) OnWorktreeCreate(fn func(*WorktreeCreateEvent) *WorktreeCreateResponse)
- func (r *Registrar) OnWorktreeRemove(fn func(*WorktreeRemoveEvent) *WorktreeRemoveResponse)
- type Response
- type SessionEndEvent
- type SessionEndResponse
- type SessionStartEvent
- type SessionStartResponse
- type SetupEvent
- type SetupResponse
- type StopEvent
- type SubagentStartEvent
- type SubagentStartResponse
- type SubagentStopEvent
- type SubagentStopResponse
- type TaskCompletedEvent
- type TaskCompletedResponse
- type TeammateIdleEvent
- type TeammateIdleResponse
- type UserPromptEvent
- type UserPromptResponse
- type WorktreeCreateEvent
- type WorktreeCreateResponse
- type WorktreeRemoveEvent
- type WorktreeRemoveResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OutcomeFromResponse ¶
func OutcomeFromResponse(r *Response) internalclaude.StopOutcome
OutcomeFromResponse maps a handler return value to a platform outcome (nil → allow).
func PreToolOutcomeFromResponse ¶
func PreToolOutcomeFromResponse(r *PreToolResponse) internalclaude.PreToolUseOutcome
PreToolOutcomeFromResponse maps handler return to platform outcome (nil → allow).
func RegisterCustomCommonJSON ¶
func RegisterCustomCommonJSON[T any](r *Registrar, eventName string, fn func(*T) *CommonResponse) error
RegisterCustomCommonJSON registers an experimental Claude hook backed by stdin JSON and a common synchronous response family.
func RegisterCustomContextJSON ¶
func RegisterCustomContextJSON[T any](r *Registrar, eventName string, fn func(*T) *ContextResponse) error
RegisterCustomContextJSON registers an experimental Claude hook backed by stdin JSON and a context-producing response family.
func RegisterCustomPermissionRequestJSON ¶
func RegisterCustomPermissionRequestJSON[T any](r *Registrar, eventName string, fn func(*T) *PermissionRequestResponse) error
RegisterCustomPermissionRequestJSON registers an experimental Claude hook backed by stdin JSON and the permission decision response family.
func RegisterCustomPostToolUseJSON ¶
func RegisterCustomPostToolUseJSON[T any](r *Registrar, eventName string, fn func(*T) *PostToolUseResponse) error
RegisterCustomPostToolUseJSON registers an experimental Claude hook backed by stdin JSON and the PostToolUse response family.
func UserPromptOutcomeFromResponse ¶
func UserPromptOutcomeFromResponse(r *UserPromptResponse) internalclaude.UserPromptSubmitOutcome
UserPromptOutcomeFromResponse maps handler return to platform outcome (nil → allow).
Types ¶
type CommonResponse ¶
type CommonResponse struct {
// Continue overrides the continue flag for compatible hooks when non-nil.
Continue *bool
// SuppressOutput omits the usual hook output message when true.
SuppressOutput bool
// StopReason explains why processing should stop.
StopReason string
// Decision carries the Claude decision token such as approve or block.
Decision string
// Reason carries a human-readable reason for the decision.
Reason string
// SystemMessage injects a system message into Claude when supported.
SystemMessage string
}
CommonResponse contains fields shared by Claude's common hook response envelope.
type ConfigChangeEvent ¶
type ConfigChangeEvent = internalclaude.ConfigChangeInput
ConfigChangeEvent is the Claude ConfigChange hook input.
type ConfigChangeResponse ¶
type ConfigChangeResponse = CommonResponse
ConfigChangeResponse is the response type for ConfigChange.
type ContextResponse ¶
type ContextResponse struct {
CommonResponse
// AdditionalContext appends hook-specific context visible to Claude.
AdditionalContext string
}
ContextResponse extends CommonResponse with additional context text.
type NotificationEvent ¶
type NotificationEvent = internalclaude.NotificationInput
NotificationEvent is the Claude Notification hook input.
type NotificationResponse ¶
type NotificationResponse = ContextResponse
NotificationResponse is the response type for Notification.
type PermissionBehavior ¶
type PermissionBehavior = internalclaude.PermissionBehavior
PermissionBehavior enumerates allow or deny decisions for PermissionRequest.
const ( // PermissionAllow approves the pending action. PermissionAllow PermissionBehavior = internalclaude.PermissionAllow // PermissionDeny rejects the pending action. PermissionDeny PermissionBehavior = internalclaude.PermissionDeny )
type PermissionDecision ¶
type PermissionDecision struct {
// Behavior is either PermissionAllow or PermissionDeny.
Behavior PermissionBehavior
// UpdatedInput replaces the pending input before Claude continues.
UpdatedInput json.RawMessage
// UpdatedPermissions amends stored permission rules when approving.
UpdatedPermissions []PermissionUpdate
// Message explains the deny decision to the user.
Message string
// Interrupt asks Claude to interrupt the current flow after the message.
Interrupt bool
}
PermissionDecision describes the approval or denial returned from PermissionRequest.
type PermissionRequestEvent ¶
type PermissionRequestEvent = internalclaude.PermissionRequestInput
PermissionRequestEvent is the Claude PermissionRequest hook input.
type PermissionRequestResponse ¶
type PermissionRequestResponse struct {
CommonResponse
// Permission holds the allow or deny decision when one is returned.
Permission *PermissionDecision
}
PermissionRequestResponse extends CommonResponse with a permission decision.
func PermissionApprove ¶
func PermissionApprove() *PermissionRequestResponse
PermissionApprove returns a response that approves the requested action.
func PermissionApproveWithUpdates ¶
func PermissionApproveWithUpdates(input json.RawMessage, updates []PermissionUpdate) *PermissionRequestResponse
PermissionApproveWithUpdates approves the action and sends updated input or rules.
func PermissionBlock ¶
func PermissionBlock(message string, interrupt bool) *PermissionRequestResponse
PermissionBlock rejects the action with a message and interrupt choice.
type PermissionRuleValue ¶
type PermissionRuleValue = internalclaude.PermissionRuleValue
PermissionRuleValue mirrors the supported rule value payload for permission updates.
type PermissionUpdate ¶
type PermissionUpdate = internalclaude.PermissionUpdate
PermissionUpdate mirrors a single permission rule update returned to Claude.
type PostToolUseEvent ¶
type PostToolUseEvent = internalclaude.PostToolUseInput
PostToolUseEvent is the Claude PostToolUse hook input.
type PostToolUseFailureEvent ¶
type PostToolUseFailureEvent = internalclaude.PostToolUseFailureInput
PostToolUseFailureEvent is the Claude PostToolUseFailure hook input.
type PostToolUseFailureResponse ¶
type PostToolUseFailureResponse = ContextResponse
PostToolUseFailureResponse is the response type for PostToolUseFailure.
type PostToolUseResponse ¶
type PostToolUseResponse struct {
CommonResponse
// AdditionalContext appends hook-specific context visible to Claude.
AdditionalContext string
// UpdatedMCPToolOutput replaces the MCP tool output payload on the wire.
UpdatedMCPToolOutput json.RawMessage
}
PostToolUseResponse extends CommonResponse with tool output overrides.
type PreCompactEvent ¶
type PreCompactEvent = internalclaude.PreCompactInput
PreCompactEvent is the Claude PreCompact hook input.
type PreCompactResponse ¶
type PreCompactResponse = CommonResponse
PreCompactResponse is the response type for PreCompact.
type PreToolResponse ¶
type PreToolResponse struct {
// contains filtered or unexported fields
}
PreToolResponse is the hook outcome for PreToolUse (hookSpecificOutput on wire).
func PreToolAllow ¶
func PreToolAllow() *PreToolResponse
PreToolAllow lets the tool run (exit 0 + "{}" or optional reason for allow path).
func PreToolAllowWithReason ¶
func PreToolAllowWithReason(reason string) *PreToolResponse
PreToolAllowWithReason returns allow with permissionDecisionReason (shown to user).
func PreToolAsk ¶
func PreToolAsk(reason string) *PreToolResponse
PreToolAsk prompts the user to confirm.
func PreToolBlockExit2 ¶
func PreToolBlockExit2(reason string) *PreToolResponse
PreToolBlockExit2 blocks the tool via exit 2; stderr carries reason to Claude.
func PreToolDeny ¶
func PreToolDeny(reason string) *PreToolResponse
PreToolDeny blocks the tool with hookSpecificOutput deny.
type PreToolUseEvent ¶
type PreToolUseEvent = internalclaude.PreToolUseInput
PreToolUseEvent is the Claude Code PreToolUse hook input (stdin JSON).
type Registrar ¶
type Registrar struct {
// contains filtered or unexported fields
}
Registrar registers public Claude hook handlers on a root SDK app.
func NewRegistrar ¶
func NewRegistrar(backend runtime.RegistrarBackend) *Registrar
NewRegistrar builds a Claude registrar on top of the shared runtime backend.
func (*Registrar) OnConfigChange ¶
func (r *Registrar) OnConfigChange(fn func(*ConfigChangeEvent) *ConfigChangeResponse)
OnConfigChange registers a handler for the Claude ConfigChange.
func (*Registrar) OnNotification ¶
func (r *Registrar) OnNotification(fn func(*NotificationEvent) *NotificationResponse)
OnNotification registers a handler for the Claude Notification.
func (*Registrar) OnPermissionRequest ¶
func (r *Registrar) OnPermissionRequest(fn func(*PermissionRequestEvent) *PermissionRequestResponse)
OnPermissionRequest registers a handler for the Claude PermissionRequest.
func (*Registrar) OnPostToolUse ¶
func (r *Registrar) OnPostToolUse(fn func(*PostToolUseEvent) *PostToolUseResponse)
OnPostToolUse registers a handler for the Claude PostToolUse.
func (*Registrar) OnPostToolUseFailure ¶
func (r *Registrar) OnPostToolUseFailure(fn func(*PostToolUseFailureEvent) *PostToolUseFailureResponse)
OnPostToolUseFailure registers a handler for the Claude PostToolUseFailure.
func (*Registrar) OnPreCompact ¶
func (r *Registrar) OnPreCompact(fn func(*PreCompactEvent) *PreCompactResponse)
OnPreCompact registers a handler for the Claude PreCompact.
func (*Registrar) OnPreToolUse ¶
func (r *Registrar) OnPreToolUse(fn func(*PreToolUseEvent) *PreToolResponse)
OnPreToolUse registers a handler for the Claude PreToolUse.
func (*Registrar) OnSessionEnd ¶
func (r *Registrar) OnSessionEnd(fn func(*SessionEndEvent) *SessionEndResponse)
OnSessionEnd registers a handler for the Claude SessionEnd.
func (*Registrar) OnSessionStart ¶
func (r *Registrar) OnSessionStart(fn func(*SessionStartEvent) *SessionStartResponse)
OnSessionStart registers a handler for the Claude SessionStart.
func (*Registrar) OnSetup ¶
func (r *Registrar) OnSetup(fn func(*SetupEvent) *SetupResponse)
OnSetup registers a handler for the Claude Setup.
func (*Registrar) OnSubagentStart ¶
func (r *Registrar) OnSubagentStart(fn func(*SubagentStartEvent) *SubagentStartResponse)
OnSubagentStart registers a handler for the Claude SubagentStart.
func (*Registrar) OnSubagentStop ¶
func (r *Registrar) OnSubagentStop(fn func(*SubagentStopEvent) *SubagentStopResponse)
OnSubagentStop registers a handler for the Claude SubagentStop.
func (*Registrar) OnTaskCompleted ¶
func (r *Registrar) OnTaskCompleted(fn func(*TaskCompletedEvent) *TaskCompletedResponse)
OnTaskCompleted registers a handler for the Claude TaskCompleted.
func (*Registrar) OnTeammateIdle ¶
func (r *Registrar) OnTeammateIdle(fn func(*TeammateIdleEvent) *TeammateIdleResponse)
OnTeammateIdle registers a handler for the Claude TeammateIdle.
func (*Registrar) OnUserPromptSubmit ¶
func (r *Registrar) OnUserPromptSubmit(fn func(*UserPromptEvent) *UserPromptResponse)
OnUserPromptSubmit registers a handler for the Claude UserPromptSubmit.
func (*Registrar) OnWorktreeCreate ¶
func (r *Registrar) OnWorktreeCreate(fn func(*WorktreeCreateEvent) *WorktreeCreateResponse)
OnWorktreeCreate registers a handler for the Claude WorktreeCreate.
func (*Registrar) OnWorktreeRemove ¶
func (r *Registrar) OnWorktreeRemove(fn func(*WorktreeRemoveEvent) *WorktreeRemoveResponse)
OnWorktreeRemove registers a handler for the Claude WorktreeRemove.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is the hook outcome for Stop (see Stop decision control in Claude Code hooks reference).
func Allow ¶
func Allow() *Response
Allow lets Claude stop (omit decision / empty JSON object on wire).
func Block ¶
Block prevents Claude from stopping; maps to {"decision":"block","reason":...} with exit 0.
func BlockExit2 ¶
BlockExit2 requests a non-zero exit without JSON stdout (alternate path per Claude Stop docs).
func Continue ¶
Continue is the same as Block for Stop: keep the session running (decision block on wire).
func (*Response) BlockReason ¶
BlockReason is set when AllowStop is false (JSON block path or exit-2 path).
type SessionEndEvent ¶
type SessionEndEvent = internalclaude.SessionEndInput
SessionEndEvent is the Claude SessionEnd hook input.
type SessionEndResponse ¶
type SessionEndResponse = CommonResponse
SessionEndResponse is the response type for SessionEnd.
type SessionStartEvent ¶
type SessionStartEvent = internalclaude.SessionStartInput
SessionStartEvent is the Claude SessionStart hook input.
type SessionStartResponse ¶
type SessionStartResponse = ContextResponse
SessionStartResponse is the response type for SessionStart.
type SetupEvent ¶
type SetupEvent = internalclaude.SetupInput
SetupEvent is the Claude Setup hook input.
type SetupResponse ¶
type SetupResponse = ContextResponse
SetupResponse is the response type for Setup.
type StopEvent ¶
type StopEvent = internalclaude.StopInput
StopEvent is the Claude Code Stop hook input (decoded from stdin JSON). Field names follow Claude docs; wire uses snake_case via the platform adapter.
type SubagentStartEvent ¶
type SubagentStartEvent = internalclaude.SubagentStartInput
SubagentStartEvent is the Claude SubagentStart hook input.
type SubagentStartResponse ¶
type SubagentStartResponse = ContextResponse
SubagentStartResponse is the response type for SubagentStart.
type SubagentStopEvent ¶
type SubagentStopEvent = internalclaude.SubagentStopInput
SubagentStopEvent is the Claude SubagentStop hook input.
type SubagentStopResponse ¶
type SubagentStopResponse = CommonResponse
SubagentStopResponse is the response type for SubagentStop.
type TaskCompletedEvent ¶
type TaskCompletedEvent = internalclaude.TaskCompletedInput
TaskCompletedEvent is the Claude TaskCompleted hook input.
type TaskCompletedResponse ¶
type TaskCompletedResponse = CommonResponse
TaskCompletedResponse is the response type for TaskCompleted.
type TeammateIdleEvent ¶
type TeammateIdleEvent = internalclaude.TeammateIdleInput
TeammateIdleEvent is the Claude TeammateIdle hook input.
type TeammateIdleResponse ¶
type TeammateIdleResponse = CommonResponse
TeammateIdleResponse is the response type for TeammateIdle.
type UserPromptEvent ¶
type UserPromptEvent = internalclaude.UserPromptSubmitInput
UserPromptEvent is the Claude Code UserPromptSubmit hook input.
type UserPromptResponse ¶
type UserPromptResponse struct {
// contains filtered or unexported fields
}
UserPromptResponse is the hook outcome for UserPromptSubmit.
func UserPromptAllow ¶
func UserPromptAllow() *UserPromptResponse
UserPromptAllow lets the prompt proceed.
func UserPromptAllowWithContext ¶
func UserPromptAllowWithContext(context string) *UserPromptResponse
UserPromptAllowWithContext adds additionalContext on exit 0 (JSON).
func UserPromptBlock ¶
func UserPromptBlock(reason string) *UserPromptResponse
UserPromptBlock blocks the prompt with decision/reason (exit 0 + JSON).
func UserPromptBlockExit2 ¶
func UserPromptBlockExit2(reason string) *UserPromptResponse
UserPromptBlockExit2 rejects the prompt via exit 2; stderr to Claude.
type WorktreeCreateEvent ¶
type WorktreeCreateEvent = internalclaude.WorktreeCreateInput
WorktreeCreateEvent is the Claude WorktreeCreate hook input.
type WorktreeCreateResponse ¶
type WorktreeCreateResponse = CommonResponse
WorktreeCreateResponse is the response type for WorktreeCreate.
type WorktreeRemoveEvent ¶
type WorktreeRemoveEvent = internalclaude.WorktreeRemoveInput
WorktreeRemoveEvent is the Claude WorktreeRemove hook input.
type WorktreeRemoveResponse ¶
type WorktreeRemoveResponse = CommonResponse
WorktreeRemoveResponse is the response type for WorktreeRemove.