Documentation
¶
Overview ¶
Package hooks provides a unified interface for managing hook configurations across multiple AI coding assistants.
Hooks are automation callbacks that execute at defined stages of the agent loop. They can observe, block, or modify agent behavior.
Supported tools:
- Claude Code (.claude/settings.json)
- Cursor IDE (.cursor/hooks.json)
- Windsurf / Codeium (.windsurf/hooks.json)
The package provides:
- A canonical Config type that represents hook configuration
- Adapters for reading/writing tool-specific formats
- Conversion between different tool formats
Example usage:
// Read Claude hooks config
cfg, err := claude.ReadProjectConfig()
if err != nil {
log.Fatal(err)
}
// Write to Cursor format
err = cursor.WriteProjectConfig(cfg)
// Or use the adapter registry for dynamic conversion
data, err := hooks.Convert(jsonData, "claude", "cursor")
Index ¶
Constants ¶
const ( HookTypeCommand = core.HookTypeCommand HookTypePrompt = core.HookTypePrompt )
Hook type constants
const ( BeforeFileRead = core.BeforeFileRead AfterFileRead = core.AfterFileRead BeforeFileWrite = core.BeforeFileWrite AfterFileWrite = core.AfterFileWrite )
Event constants - File operations
const ( BeforeCommand = core.BeforeCommand AfterCommand = core.AfterCommand )
Event constants - Command operations
const ( BeforeMCP = core.BeforeMCP AfterMCP = core.AfterMCP )
Event constants - MCP operations
const ( BeforePrompt = core.BeforePrompt OnStop = core.OnStop OnSessionStart = core.OnSessionStart OnSessionEnd = core.OnSessionEnd )
Event constants - Prompt/Lifecycle
const ( AfterResponse = core.AfterResponse // Cursor AfterThought = core.AfterThought // Cursor OnPermission = core.OnPermission // Claude OnNotification = core.OnNotification // Claude BeforeCompact = core.BeforeCompact // Claude OnSubagentStop = core.OnSubagentStop // Claude BeforeTabRead = core.BeforeTabRead // Cursor AfterTabEdit = core.AfterTabEdit // Cursor )
Event constants - Tool-specific
Variables ¶
This section is empty.
Functions ¶
func AdapterNames ¶
func AdapterNames() []string
AdapterNames returns the names of all registered adapters.
func Convert ¶
Convert converts configuration data between formats. Example: Convert(data, "claude", "cursor")
func SupportedTools ¶
func SupportedTools() []string
SupportedTools returns a list of tools that support hooks.
Types ¶
type Adapter ¶
Adapter is the interface for tool-specific adapters.
func GetAdapter ¶
GetAdapter returns an adapter by name from the default registry. Supported names: "claude", "cursor", "windsurf"
type Hook ¶
Hook is a single hook definition.
func NewCommandHook ¶
NewCommandHook creates a new command-type hook.
func NewPromptHook ¶
NewPromptHook creates a new prompt-type hook (Claude-specific).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package claude provides an adapter for Claude Code hooks configuration.
|
Package claude provides an adapter for Claude Code hooks configuration. |
|
Package core provides the canonical types for hook configuration that can be converted to/from various AI assistant formats.
|
Package core provides the canonical types for hook configuration that can be converted to/from various AI assistant formats. |
|
Package cursor provides an adapter for Cursor IDE hooks configuration.
|
Package cursor provides an adapter for Cursor IDE hooks configuration. |
|
Package windsurf provides an adapter for Windsurf (Codeium) hooks configuration.
|
Package windsurf provides an adapter for Windsurf (Codeium) hooks configuration. |