claude

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
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

func ReadProjectConfig() (*core.Config, error)

ReadProjectConfig reads the project-level .claude/settings.json hooks.

func ReadUserConfig

func ReadUserConfig() (*core.Config, error)

ReadUserConfig reads the user-level ~/.claude/settings.json hooks.

Types

type Adapter

type Adapter struct{}

Adapter implements core.Adapter for Claude Code hooks.

func NewAdapter

func NewAdapter() *Adapter

NewAdapter creates a new Claude hooks adapter.

func (*Adapter) DefaultPaths

func (a *Adapter) DefaultPaths() []string

DefaultPaths returns the default config file paths for Claude hooks.

func (*Adapter) FromCore

func (a *Adapter) FromCore(cfg *core.Config) *Config

FromCore converts canonical config to Claude format.

func (*Adapter) Marshal

func (a *Adapter) Marshal(cfg *core.Config) ([]byte, error)

Marshal converts canonical config to Claude format.

func (*Adapter) Name

func (a *Adapter) Name() string

Name returns the adapter name.

func (*Adapter) Parse

func (a *Adapter) Parse(data []byte) (*core.Config, error)

Parse parses Claude hooks config data into the canonical format.

func (*Adapter) ReadFile

func (a *Adapter) ReadFile(path string) (*core.Config, error)

ReadFile reads a Claude hooks config file.

func (*Adapter) SupportedEvents

func (a *Adapter) SupportedEvents() []core.Event

SupportedEvents returns the events supported by Claude.

func (*Adapter) ToCore

func (a *Adapter) ToCore(claudeCfg *Config) *core.Config

ToCore converts Claude hooks config to canonical format.

func (*Adapter) WriteFile

func (a *Adapter) WriteFile(cfg *core.Config, path string) error

WriteFile writes canonical config to a Claude format file.

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.

func NewConfig

func NewConfig() *Config

NewConfig creates a new empty Claude hooks config.

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.

Jump to

Keyboard shortcuts

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