claudemanaged

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ManagedSettingsPath        = "/Library/Application Support/ClaudeCode/managed-settings.json"
	LinuxManagedSettingsPath   = "/etc/claude-code/managed-settings.json"
	WindowsManagedSettingsPath = `C:\Program Files\ClaudeCode\managed-settings.json`
	DefaultKontextBinary       = "/usr/local/bin/kontext"
	DefaultHookTimeout         = 20
)

Variables

View Source
var SupportedEvents = []Event{
	{Name: hook.HookSessionStart, Alias: "session-start", Async: true},
	{Name: hook.HookPreToolUse, Alias: "pre-tool-use"},
	{Name: hook.HookPostToolUse, Alias: "post-tool-use"},
	{Name: hook.HookPostToolUseFailed, Alias: "post-tool-use-failure"},
	{Name: hook.HookSessionEnd, Alias: "session-end", Async: true},
}

Functions

func AliasForEvent

func AliasForEvent(name hook.HookName) (string, bool)

func BackupUserSettings added in v0.9.0

func BackupUserSettings(path, label string) error

BackupUserSettings copies the file aside (timestamped, same permissions) before a mutation. Missing file is a no-op.

func DefaultManagedSettingsPath

func DefaultManagedSettingsPath() string

func IsGuardHookCommand added in v0.9.0

func IsGuardHookCommand(command string) bool

IsGuardHookCommand reports whether a hook command belongs to Kontext Guard (the local-only enforcement product). Shared with guard/cli so the two installers agree on whose entries are whose.

func IsManagedHookCommand added in v0.9.0

func IsManagedHookCommand(command string) bool

IsManagedHookCommand reports whether a hook command is one of OURS: the flagless managed-observe form `'<binary>' hook '<alias>'`. Guard hooks (`kontext guard hook claude-code`, `kontext hook --agent claude … --mode …`) are deliberately excluded so the two installers never touch each other's entries. Matching on the alias rather than the exact binary path means a re-run after the binary moved (brew prefix change) replaces stale entries.

func MergeManagedHooks added in v0.9.0

func MergeManagedHooks(settings map[string]any, kontextBinary string) ([]string, error)

MergeManagedHooks installs/refreshes the five managed-observe hooks in the settings map: for each supported event it removes any existing Kontext managed handlers (stale binary paths included) and appends the canonical group from Template. Everything else in the map is untouched. Idempotent: merging twice is a fixpoint. Returns non-fatal warnings for conditions the user should know about.

func ParseEventAlias

func ParseEventAlias(value string) (hook.HookName, bool)

func ReadUserSettings added in v0.9.0

func ReadUserSettings(path string) (map[string]any, error)

ReadUserSettings parses the settings file into a generic map so unknown keys survive a read-merge-write round trip. A missing file is an empty map.

func RemoveManagedHooks added in v0.9.0

func RemoveManagedHooks(settings map[string]any) error

RemoveManagedHooks strips OUR handlers (and only ours) from the settings map, pruning groups and event keys that end up empty. Foreign hooks, including Guard's, survive untouched. Idempotent.

func TemplateJSON

func TemplateJSON(kontextBinary string) ([]byte, error)

func UserSettingsPath added in v0.9.0

func UserSettingsPath() (string, error)

UserSettingsPath returns ~/.claude/settings.json, creating ~/.claude.

func Validate

func Validate(data []byte, kontextBinary string) error

func WriteUserSettings added in v0.9.0

func WriteUserSettings(path string, settings map[string]any) error

WriteUserSettings writes the settings back atomically (temp file + rename, so a crash mid-write can never leave a truncated settings.json behind), preserving the existing file's permission bits (a user may keep their settings private); new files are created 0600.

Types

type Event

type Event struct {
	Name  hook.HookName
	Alias string
	Async bool
}

type Handler

type Handler struct {
	Type    string   `json:"type"`
	Command string   `json:"command"`
	Args    []string `json:"args,omitempty"`
	Timeout int      `json:"timeout,omitempty"`
	Async   *bool    `json:"async,omitempty"`
}

type MatcherGroup

type MatcherGroup struct {
	Matcher string    `json:"matcher"`
	Hooks   []Handler `json:"hooks"`
}

type Settings

type Settings struct {
	Hooks                 map[string][]MatcherGroup `json:"hooks"`
	DisableAllHooks       *bool                     `json:"disableAllHooks,omitempty"`
	AllowManagedHooksOnly *bool                     `json:"allowManagedHooksOnly,omitempty"`
}

func Template

func Template(kontextBinary string) Settings

Jump to

Keyboard shortcuts

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