hook

package
v0.1.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 4 Imported by: 0

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               string   `json:"turn-id"`                // Turn number (string from Codex)
	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 CursorAfterAgentResponseEvent added in v0.1.11

type CursorAfterAgentResponseEvent struct {
	CursorHookEvent
	Text string `json:"text"` // The final AI response text
}

CursorAfterAgentResponseEvent represents Cursor's afterAgentResponse hook event This is the recommended hook for voice synthesis as it provides the AI response directly

type CursorBeforeSubmitPromptEvent added in v0.1.11

type CursorBeforeSubmitPromptEvent struct {
	CursorHookEvent
	Prompt string `json:"prompt"`
}

CursorBeforeSubmitPromptEvent represents Cursor's beforeSubmitPrompt hook event

type CursorHookEvent added in v0.1.11

type CursorHookEvent struct {
	ConversationID string   `json:"conversation_id"`
	GenerationID   string   `json:"generation_id"`
	Model          string   `json:"model"`
	HookEventName  string   `json:"hook_event_name"`
	CursorVersion  string   `json:"cursor_version"`
	WorkspaceRoots []string `json:"workspace_roots"`
	UserEmail      string   `json:"user_email,omitempty"`
	TranscriptPath string   `json:"transcript_path,omitempty"`
}

CursorHookEvent represents the common hook event data from Cursor See: https://cursor.com/docs/agent/hooks Note: Cursor uses conversation_id instead of session_id, and camelCase event names

type CursorSessionStartEvent added in v0.1.11

type CursorSessionStartEvent struct {
	CursorHookEvent
}

CursorSessionStartEvent represents Cursor's sessionStart hook event

type CursorStopEvent added in v0.1.11

type CursorStopEvent struct {
	CursorHookEvent
	Status    string `json:"status,omitempty"` // completed/aborted/error
	LoopCount int    `json:"loop_count,omitempty"`
}

CursorStopEvent represents Cursor's stop hook event

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

func ParseHookEvent(r io.Reader) (*HookEvent, error)

ParseHookEvent reads and parses the hook event from stdin

func ReadHookEvent

func ReadHookEvent() (*HookEvent, error)

ReadHookEvent is a convenience function to read hook event from stdin

type NotificationEvent

type NotificationEvent struct {
	HookEvent
	Message string `json:"message"`
}

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

type StopEvent struct {
	HookEvent
	StopHookActive bool `json:"stop_hook_active,omitempty"`
}

StopEvent represents the Stop/SubagentStop hook event

func ParseStopEvent

func ParseStopEvent(r io.Reader) (*StopEvent, error)

ParseStopEvent reads and parses Stop event from stdin

func ReadStopEvent

func ReadStopEvent() (*StopEvent, error)

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", "codex", or "cursor"
	SessionID  string      // Session/Thread/Conversation identifier
	CWD        string      // Current working directory
	EventType  string      // Event type (e.g., "UserPromptSubmit", "agent-turn-complete", "sessionStart")
	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 Claude Code, Codex, and Cursor

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) GetCursorEvent added in v0.1.11

func (e *UnifiedHookEvent) GetCursorEvent() (interface{}, bool)

GetCursorEvent returns the underlying Cursor 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

func (*UnifiedHookEvent) IsCursor added in v0.1.11

func (e *UnifiedHookEvent) IsCursor() bool

IsCursor returns true if the event is from Cursor

type UserPromptSubmitEvent

type UserPromptSubmitEvent struct {
	HookEvent
	Prompt string `json:"prompt"`
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL