Documentation
¶
Overview ¶
Package claude provides an adapter for Claude Code hooks configuration.
Claude hooks are configured in the "hooks" section of settings.json files:
- Project: .claude/settings.json
- User: ~/.claude/settings.json
- Local: .claude/settings.local.json
- Enterprise: /Library/Application Support/ClaudeCode/managed-settings.json
Claude hook events:
- PreToolUse: Before tool execution (can block with exit code 2)
- PostToolUse: After tool execution
- PermissionRequest: When permission dialog is shown
- UserPromptSubmit: When user submits a prompt
- Stop: When agent stops
- SessionStart: At session start
- SessionEnd: At session end
- Notification: When notifications are sent
- PreCompact: Before context compaction
- SubagentStop: When subagent stops
Index ¶
- Constants
- func ReadProjectConfig() (*core.Config, error)
- func ReadUserConfig() (*core.Config, error)
- type Adapter
- func (a *Adapter) DefaultPaths() []string
- func (a *Adapter) FromCore(cfg *core.Config) *Config
- func (a *Adapter) Marshal(cfg *core.Config) ([]byte, error)
- func (a *Adapter) Name() string
- func (a *Adapter) Parse(data []byte) (*core.Config, error)
- func (a *Adapter) ReadFile(path string) (*core.Config, error)
- func (a *Adapter) SupportedEvents() []core.Event
- func (a *Adapter) ToCore(claudeCfg *Config) *core.Config
- func (a *Adapter) WriteFile(cfg *core.Config, path string) error
- type ClaudeEvent
- type Config
- type Hook
- type HookEntry
Constants ¶
const ( // AdapterName is the identifier for this adapter. AdapterName = "claude" // SettingsFileName is the settings file name containing hooks. SettingsFileName = "settings.json" // SettingsLocalFileName is the local settings file name. SettingsLocalFileName = "settings.local.json" // ProjectConfigDir is the project config directory. ProjectConfigDir = ".claude" // ManagedSettingsFileName is the enterprise managed settings file. ManagedSettingsFileName = "managed-settings.json" )
Variables ¶
This section is empty.
Functions ¶
func ReadProjectConfig ¶
ReadProjectConfig reads the project-level .claude/settings.json hooks.
func ReadUserConfig ¶
ReadUserConfig reads the user-level ~/.claude/settings.json hooks.
Types ¶
type Adapter ¶
type Adapter struct{}
Adapter implements core.Adapter for Claude Code hooks.
func (*Adapter) DefaultPaths ¶
DefaultPaths returns the default config file paths for Claude hooks.
func (*Adapter) SupportedEvents ¶
SupportedEvents returns the events supported by Claude.
type ClaudeEvent ¶
type ClaudeEvent string
ClaudeEvent represents Claude-specific hook event names.
const ( PreToolUse ClaudeEvent = "PreToolUse" PostToolUse ClaudeEvent = "PostToolUse" PermissionRequest ClaudeEvent = "PermissionRequest" UserPromptSubmit ClaudeEvent = "UserPromptSubmit" Stop ClaudeEvent = "Stop" SessionStart ClaudeEvent = "SessionStart" SessionEnd ClaudeEvent = "SessionEnd" Notification ClaudeEvent = "Notification" PreCompact ClaudeEvent = "PreCompact" SubagentStop ClaudeEvent = "SubagentStop" )
type Config ¶
type Config struct {
Hooks map[ClaudeEvent][]HookEntry `json:"hooks,omitempty"`
DisableAllHooks bool `json:"disableAllHooks,omitempty"`
AllowManagedHooksOnly bool `json:"allowManagedHooksOnly,omitempty"`
}
Config represents the hooks section of Claude's settings.json.
type Hook ¶
type Hook struct {
// Type is "command" or "prompt".
Type string `json:"type"`
// Command is the shell command to execute (for command type).
Command string `json:"command,omitempty"`
// Prompt is the LLM prompt for context-aware decisions (for prompt type).
Prompt string `json:"prompt,omitempty"`
// Timeout in seconds for hook execution.
Timeout int `json:"timeout,omitempty"`
}
Hook represents a single Claude hook definition.
type HookEntry ¶
type HookEntry struct {
// Matcher filters which tools trigger this hook.
// Examples: "Bash", "Write", "Edit", "Read", "Bash|Write"
Matcher string `json:"matcher,omitempty"`
// Hooks is the list of hooks to execute.
Hooks []Hook `json:"hooks"`
}
HookEntry represents a Claude hook entry with matcher and hooks.