Documentation
¶
Overview ¶
Package hooks installs and removes the caprock-hook shim in Claude Code's user-level settings.json, non-destructively. See .ai/03-contracts.md § Hook shim.
Index ¶
- Constants
- Variables
- func DefaultSettingsPath() (string, error)
- func Install(settingsPath, shimPath string) (backup string, err error)
- func MarshalIndent(v any) ([]byte, error)
- func ParseOrdered(data []byte) (any, error)
- func Uninstall(settingsPath, shimPath string) (removed bool, err error)
- type Object
- type Status
Constants ¶
const ShimTimeoutSeconds = 5
ShimTimeoutSeconds is the per-hook timeout written into settings.json. The shim itself exits within ~1s; 5s is headroom for a slow disk, and it bounds the Phase 2 Stop request-response (5s) too.
Variables ¶
var Events = []string{"SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "Stop", "SubagentStop", "PreCompact", "StopFailure"}
Events the shim registers for (Phase 0). Order is the order written.
Functions ¶
func DefaultSettingsPath ¶
DefaultSettingsPath is ~/.claude/settings.json.
func Install ¶
Install merges our entries into settings.json (creating the file if absent), backing the original up once before the first write. Returns the backup path ("" when nothing was written or no original existed).
func MarshalIndent ¶
MarshalIndent renders an ordered value with 2-space indentation, matching how Claude Code writes settings.json.
func ParseOrdered ¶
ParseOrdered decodes JSON preserving object key order.
Types ¶
type Object ¶
type Object struct {
Keys []string
Values map[string]any // values are: *Object, []any, string, float64, bool, nil
}
Object is a JSON object with stable key order.
func (*Object) MarshalJSON ¶
MarshalJSON writes keys in insertion order.
type Status ¶
type Status struct {
SettingsPath string `json:"settings_path"`
ShimPath string `json:"shim_path"`
Installed []string `json:"installed"` // events with our entry present
Missing []string `json:"missing"` // events from Events without our entry
ShimExists bool `json:"shim_exists"`
}
Status describes what is registered.