Documentation
¶
Overview ¶
Package hook provides types and utilities for handling Claude Code hook events. For more information about Claude Code hooks, see: https://docs.anthropic.com/en/docs/claude-code/hooks
Package hook provides unified handling for both Claude Code and Codex hook events
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CodexNotifyEvent ¶ added in v0.1.5
type CodexNotifyEvent struct {
Type string `json:"type"` // "agent-turn-complete"
ThreadID string `json:"thread-id"` // UUID of the thread
TurnID int `json:"turn-id"` // Turn number
CWD string `json:"cwd"` // Current working directory
InputMessages []string `json:"input-messages"` // User's input messages
LastAssistantMessage string `json:"last-assistant-message"` // Model's final response
}
CodexNotifyEvent represents the Codex notify hook event See: https://github.com/openai/codex/blob/main/docs/config.md
func ParseCodexNotifyEvent ¶ added in v0.1.5
func ParseCodexNotifyEvent(r io.Reader) (*CodexNotifyEvent, error)
ParseCodexNotifyEvent reads and parses Codex notify event from stdin
func ReadCodexNotifyEvent ¶ added in v0.1.5
func ReadCodexNotifyEvent() (*CodexNotifyEvent, error)
ReadCodexNotifyEvent is a convenience function to read Codex notify event from stdin
type HookEvent ¶
type HookEvent struct {
SessionID string `json:"session_id"`
TranscriptPath string `json:"transcript_path"`
CWD string `json:"cwd,omitempty"`
HookEventName string `json:"hook_event_name"`
}
HookEvent represents the common hook event data from Claude Code
func ParseHookEvent ¶
ParseHookEvent reads and parses the hook event from stdin
func ReadHookEvent ¶
ReadHookEvent is a convenience function to read hook event from stdin
type NotificationEvent ¶
NotificationEvent represents the Notification hook event
func ParseNotificationEvent ¶
func ParseNotificationEvent(r io.Reader) (*NotificationEvent, error)
ParseNotificationEvent reads and parses Notification event from stdin
func ReadNotificationEvent ¶
func ReadNotificationEvent() (*NotificationEvent, error)
ReadNotificationEvent is a convenience function to read Notification event from stdin
type PostToolUseEvent ¶
type PostToolUseEvent struct {
HookEvent
ToolName string `json:"tool_name"`
ToolResult map[string]interface{} `json:"tool_result,omitempty"`
}
PostToolUseEvent represents the PostToolUse hook event
type PreCompactEvent ¶
type PreCompactEvent struct {
HookEvent
CompactMode string `json:"compact_mode"` // "manual" or "auto"
}
PreCompactEvent represents the PreCompact hook event
type PreToolUseEvent ¶
type PreToolUseEvent struct {
HookEvent
ToolName string `json:"tool_name"`
ToolParams map[string]interface{} `json:"tool_params,omitempty"`
}
PreToolUseEvent represents the PreToolUse hook event
type SessionEndEvent ¶ added in v0.1.6
type SessionEndEvent struct {
HookEvent
}
SessionEndEvent represents the SessionEnd hook event Triggered when a Claude Code session ends
func ParseSessionEndEvent ¶ added in v0.1.6
func ParseSessionEndEvent(r io.Reader) (*SessionEndEvent, error)
ParseSessionEndEvent reads and parses SessionEnd event from stdin
func ReadSessionEndEvent ¶ added in v0.1.6
func ReadSessionEndEvent() (*SessionEndEvent, error)
ReadSessionEndEvent is a convenience function to read SessionEnd event from stdin
type SessionStartEvent ¶ added in v0.1.6
type SessionStartEvent struct {
HookEvent
}
SessionStartEvent represents the SessionStart hook event Triggered when a Claude Code session starts or resumes
func ParseSessionStartEvent ¶ added in v0.1.6
func ParseSessionStartEvent(r io.Reader) (*SessionStartEvent, error)
ParseSessionStartEvent reads and parses SessionStart event from stdin
func ReadSessionStartEvent ¶ added in v0.1.6
func ReadSessionStartEvent() (*SessionStartEvent, error)
ReadSessionStartEvent is a convenience function to read SessionStart event from stdin
type StopEvent ¶
StopEvent represents the Stop/SubagentStop hook event
func ParseStopEvent ¶
ParseStopEvent reads and parses Stop event from stdin
func ReadStopEvent ¶
ReadStopEvent is a convenience function to read Stop event from stdin
type UnifiedHookEvent ¶ added in v0.1.5
type UnifiedHookEvent struct {
Source string // "claude-code" or "codex"
SessionID string // Session/Thread identifier
CWD string // Current working directory
EventType string // Event type (e.g., "user-prompt-submit", "agent-turn-complete")
UserInput []string // User's input messages
AIResponse string // AI's response message
RawEvent interface{} // Original event for type-specific handling
}
UnifiedHookEvent represents a normalized hook event that works for both Claude Code and Codex
func DetectAndParse ¶ added in v0.1.5
func DetectAndParse(r io.Reader) (*UnifiedHookEvent, error)
DetectAndParse automatically detects the hook source and parses the event
func (*UnifiedHookEvent) GetClaudeCodeEvent ¶ added in v0.1.5
func (e *UnifiedHookEvent) GetClaudeCodeEvent() (interface{}, bool)
GetClaudeCodeEvent returns the underlying Claude Code event if available
func (*UnifiedHookEvent) GetCodexEvent ¶ added in v0.1.5
func (e *UnifiedHookEvent) GetCodexEvent() (*CodexNotifyEvent, bool)
GetCodexEvent returns the underlying Codex event if available
func (*UnifiedHookEvent) IsClaudeCode ¶ added in v0.1.5
func (e *UnifiedHookEvent) IsClaudeCode() bool
IsClaudeCode returns true if the event is from Claude Code
func (*UnifiedHookEvent) IsCodex ¶ added in v0.1.5
func (e *UnifiedHookEvent) IsCodex() bool
IsCodex returns true if the event is from Codex
type UserPromptSubmitEvent ¶
UserPromptSubmitEvent represents the UserPromptSubmit hook event
func ParseUserPromptSubmitEvent ¶
func ParseUserPromptSubmitEvent(r io.Reader) (*UserPromptSubmitEvent, error)
ParseUserPromptSubmitEvent reads and parses UserPromptSubmit event from stdin
func ReadUserPromptSubmitEvent ¶
func ReadUserPromptSubmitEvent() (*UserPromptSubmitEvent, error)
ReadUserPromptSubmitEvent is a convenience function to read UserPromptSubmit event from stdin