Platform-specific types and helpers for Claude Code hooks. Use these when you need features not available in the unified API.
See Claude Code Hooks Documentation for official docs.
| Event | Input | Output | Description |
|---|---|---|---|
| Stop | StopInput |
StopOutput |
Agent finished responding |
| SubagentStop | SubagentStopInput |
SubagentStopOutput |
Subagent (Task tool) finished |
| SessionStart | SessionStartInput |
SessionStartOutput |
Session started or resumed |
| SessionEnd | SessionEndInput |
SessionEndOutput |
Session ending |
| PreToolUse | PreToolUseInput |
PreToolUseOutput |
Before tool execution |
| PostToolUse | PostToolUseInput |
PostToolUseOutput |
After tool execution |
| PermissionRequest | PermissionRequestInput |
PermissionRequestOutput |
Permission dialog shown |
| UserPromptSubmit | UserPromptSubmitInput |
UserPromptSubmitOutput |
User submitted a prompt |
| Notification | NotificationInput |
NotificationOutput |
Notification sent |
| PreCompact | PreCompactInput |
PreCompactOutput |
Before context compaction |
Called when the agent finishes responding.
type StopInput struct {
SessionID string `json:"session_id"`
Cwd string `json:"cwd"`
StopHookActive bool `json:"stop_hook_active"`
}type StopOutput struct {
Decision string `json:"decision,omitempty"` // "block" or "stop"
Reason string `json:"reason,omitempty"`
}func Continue() StopOutput // Allow stopping
func Block(reason string) StopOutput // Prevent stopping, continue working
func StopWith(reason string) StopOutput // Halt Claude entirelyhookshot.Register("claude-stop", func() {
hookshot.Run(func(input claude.StopInput) claude.StopOutput {
// IMPORTANT: Check StopHookActive to prevent infinite loops
if input.StopHookActive {
return claude.Continue()
}
return claude.Continue()
})
})Called when a session starts or resumes.
type SessionStartInput struct {
SessionID string `json:"session_id"`
Source string `json:"source"` // "startup", "resume", "clear", "compact"
Cwd string `json:"cwd"`
}type SessionStartOutput struct {
Context string `json:"context,omitempty"`
}func SessionStartOK() SessionStartOutput
func SessionStartContext(context string) SessionStartOutputhookshot.Register("claude-session-start", func() {
hookshot.Run(func(input claude.SessionStartInput) claude.SessionStartOutput {
return claude.SessionStartContext("Project uses Go 1.21+")
})
})Called when a session is ending.
type SessionEndInput struct {
SessionID string `json:"session_id"`
}type SessionEndOutput struct{}func SessionEndOK() SessionEndOutputCalled before a tool is executed.
type PreToolUseInput struct {
SessionID string `json:"session_id"`
ToolName string `json:"tool_name"`
ToolInput json.RawMessage `json:"tool_input"`
Cwd string `json:"cwd"`
}type PreToolUseOutput struct {
Decision string `json:"decision,omitempty"`
Reason string `json:"reason,omitempty"`
ModifiedInput map[string]any `json:"modified_input,omitempty"`
}func Allow(reason string) PreToolUseOutput
func AllowSilent() PreToolUseOutput
func AllowWithInput(reason string, modifiedInput map[string]any) PreToolUseOutput
func Deny(reason string) PreToolUseOutput
func Ask(reason string) PreToolUseOutput
func PassThrough() PreToolUseOutputhookshot.Register("claude-pre-tool-use", func() {
hookshot.Run(func(input claude.PreToolUseInput) claude.PreToolUseOutput {
// Block specific MCP servers
if strings.HasPrefix(input.ToolName, "mcp__blocked__") {
return claude.Deny("MCP server not allowed")
}
// Auto-approve Read tool
if input.ToolName == "Read" {
return claude.AllowSilent()
}
return claude.PassThrough()
})
})Called after a tool is executed.
type PostToolUseInput struct {
SessionID string `json:"session_id"`
ToolName string `json:"tool_name"`
ToolInput json.RawMessage `json:"tool_input"`
ToolResult json.RawMessage `json:"tool_result"`
Cwd string `json:"cwd"`
}type PostToolUseOutput struct {
Decision string `json:"decision,omitempty"` // "block"
Reason string `json:"reason,omitempty"`
Context string `json:"context,omitempty"`
}func PostToolOK() PostToolUseOutput
func PostToolBlock(reason string) PostToolUseOutput
func PostToolContext(context string) PostToolUseOutputCalled when a permission dialog is shown.
type PermissionRequestInput struct {
SessionID string `json:"session_id"`
ToolName string `json:"tool_name"`
ToolInput json.RawMessage `json:"tool_input"`
}type PermissionRequestOutput struct {
Decision string `json:"decision,omitempty"`
Message string `json:"message,omitempty"`
ModifiedInput map[string]any `json:"modified_input,omitempty"`
}func AllowPermission() PermissionRequestOutput
func AllowPermissionWithInput(modifiedInput map[string]any) PermissionRequestOutput
func DenyPermission(message string) PermissionRequestOutput
func DenyPermissionAndStop(message string) PermissionRequestOutputCalled when a user submits a prompt.
type UserPromptSubmitInput struct {
SessionID string `json:"session_id"`
Prompt string `json:"prompt"`
}type UserPromptSubmitOutput struct {
Decision string `json:"decision,omitempty"` // "block"
Reason string `json:"reason,omitempty"`
Context string `json:"context,omitempty"`
}func AllowPrompt() UserPromptSubmitOutput
func BlockPrompt(reason string) UserPromptSubmitOutput
func AddContext(context string) UserPromptSubmitOutputCalled when a notification is sent.
type NotificationInput struct {
SessionID string `json:"session_id"`
NotificationType string `json:"notification_type"`
// Types: permission_prompt, idle_prompt, auth_success, elicitation_dialog
}type NotificationOutput struct{}func NotificationOK() NotificationOutputCalled before context compaction.
type PreCompactInput struct {
SessionID string `json:"session_id"`
}type PreCompactOutput struct {
Summary string `json:"summary,omitempty"`
}func PreCompactOK() PreCompactOutput
func PreCompactSummary(summary string) PreCompactOutput