hook

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 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               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

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 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" 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

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