Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AllHook ¶
type AllHook interface {
PreToolUseHook
PostToolUseHook
UserPromptSubmitHook
StopHook
NotificationHook
}
AllHook represents a strongly typed hook object; individual methods remain optional via the narrow interfaces above.
type Decision ¶
type Decision int
Decision captures the permission outcome encoded in the hook exit code. Claude Code spec: 0=success(parse JSON), 2=blocking error(stderr), other=non-blocking(log stderr & continue).
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor executes hooks by spawning shell commands with JSON stdin payloads.
func NewExecutor ¶
func NewExecutor(opts ...ExecutorOption) *Executor
NewExecutor constructs a shell-based hook executor.
func (*Executor) Close ¶
func (e *Executor) Close()
Close is present for API parity; no resources are held.
func (*Executor) Execute ¶
Execute runs all matching hooks for the provided event and returns their results.
type ExecutorOption ¶
type ExecutorOption func(*Executor)
ExecutorOption configures optional behaviour.
func WithCommand ¶
func WithCommand(cmd string) ExecutorOption
WithCommand defines the fallback shell command used when a hook omits Command.
func WithErrorHandler ¶
func WithErrorHandler(fn func(events.EventType, error)) ExecutorOption
WithErrorHandler installs an async error sink. Errors are still returned to callers.
func WithMiddleware ¶
func WithMiddleware(mw ...middleware.Middleware) ExecutorOption
WithMiddleware wraps execution with the provided middleware chain.
func WithTimeout ¶
func WithTimeout(d time.Duration) ExecutorOption
WithTimeout sets the default timeout per hook run. Zero uses the default budget.
func WithWorkDir ¶
func WithWorkDir(dir string) ExecutorOption
WithWorkDir sets the working directory for hook command execution.
type HookOutput ¶
type HookOutput struct {
Continue *bool `json:"continue,omitempty"`
StopReason string `json:"stopReason,omitempty"`
Decision string `json:"decision,omitempty"`
Reason string `json:"reason,omitempty"`
SystemMessage string `json:"systemMessage,omitempty"`
HookSpecificOutput *HookSpecificOutput `json:"hookSpecificOutput,omitempty"`
}
HookOutput is the structured JSON output from hooks on exit 0.
type HookSpecificOutput ¶
type HookSpecificOutput struct {
HookEventName string `json:"hookEventName,omitempty"`
// PreToolUse specific
PermissionDecision string `json:"permissionDecision,omitempty"`
PermissionDecisionReason string `json:"permissionDecisionReason,omitempty"`
UpdatedInput map[string]any `json:"updatedInput,omitempty"`
AdditionalContext string `json:"additionalContext,omitempty"`
}
HookSpecificOutput carries event-specific fields from hook JSON output.
type NotificationHook ¶
type NotificationHook interface {
Notification(context.Context, events.NotificationPayload) error
}
Individual hook interfaces allow hook implementations to opt-in to only the callbacks they care about while keeping type safety.
type PostToolUseHook ¶
type PostToolUseHook interface {
PostToolUse(context.Context, events.ToolResultPayload) error
}
Individual hook interfaces allow hook implementations to opt-in to only the callbacks they care about while keeping type safety.
type PreToolUseHook ¶
type PreToolUseHook interface {
PreToolUse(context.Context, events.ToolUsePayload) error
}
Individual hook interfaces allow hook implementations to opt-in to only the callbacks they care about while keeping type safety.
type Result ¶
type Result struct {
Event events.Event
Decision Decision
ExitCode int
Output *HookOutput // parsed JSON stdout on exit 0
Stdout string
Stderr string
}
Result captures the full outcome of executing a shell hook.
type Selector ¶
Selector filters hooks by matcher target and/or payload pattern.
func NewSelector ¶
NewSelector compiles optional regex patterns. Empty strings are treated as wildcards.
type ShellHook ¶
type ShellHook struct {
Event events.EventType
Command string
Selector Selector
Timeout time.Duration
Env map[string]string
Name string // optional label for debugging
Async bool // fire-and-forget execution
Once bool // execute only once per session
StatusMessage string // status message shown during execution
}
ShellHook describes a single shell command bound to an event type.
type StopHook ¶
type StopHook interface {
Stop(context.Context, events.StopPayload) error
}
Individual hook interfaces allow hook implementations to opt-in to only the callbacks they care about while keeping type safety.
type UserPromptSubmitHook ¶
type UserPromptSubmitHook interface {
UserPromptSubmit(context.Context, events.UserPromptPayload) error
}
Individual hook interfaces allow hook implementations to opt-in to only the callbacks they care about while keeping type safety.