hooks

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

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

func DefaultSettingsPath() (string, error)

DefaultSettingsPath is ~/.claude/settings.json.

func Install

func Install(settingsPath, shimPath string) (backup string, err error)

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 InstallStatusline added in v0.5.0

func InstallStatusline(settingsPath, cmdPath string) (backup string, err error)

InstallStatusline sets settings.json's statusLine to our command, backing the file up once. It refuses to clobber a statusLine the user set to something else — callers should check StatuslineInstalled and only offer to install when nothing (or our own) is present. Returns the backup path (empty if no change).

func MarshalIndent

func MarshalIndent(v any) ([]byte, error)

MarshalIndent renders an ordered value with 2-space indentation, matching how Claude Code writes settings.json.

func ParseOrdered

func ParseOrdered(data []byte) (any, error)

ParseOrdered decodes JSON preserving object key order.

func StatuslineInstalled added in v0.5.0

func StatuslineInstalled(settingsPath, cmdPath string) (ours bool, present bool, err error)

StatuslineInstalled reports whether settings.json already has a statusLine command that points at our binary (`… statusline`). A different statusLine command (the user's own) is left alone and reported as not-ours.

func Uninstall

func Uninstall(settingsPath, shimPath string) (removed bool, err error)

Uninstall removes only entries whose command points at our shim, and drops empty containers it leaves behind. Other hooks are untouched. Returns whether anything was removed.

func UninstallStatusline added in v0.5.0

func UninstallStatusline(settingsPath, cmdPath string) (removed bool, err error)

UninstallStatusline removes the statusLine only if it is ours, leaving a user-set statusLine untouched. Returns whether anything was removed.

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 NewObject

func NewObject() *Object

NewObject creates an empty ordered object.

func (*Object) Delete

func (o *Object) Delete(k string)

Delete removes a key.

func (*Object) Get

func (o *Object) Get(k string) (any, bool)

Get returns a value and whether it exists.

func (*Object) Len

func (o *Object) Len() int

Len returns the number of keys.

func (*Object) MarshalJSON

func (o *Object) MarshalJSON() ([]byte, error)

MarshalJSON writes keys in insertion order.

func (*Object) Set

func (o *Object) Set(k string, v any)

Set inserts or replaces a value, appending new keys at the end.

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.

func Inspect

func Inspect(settingsPath, shimPath string) (Status, error)

Inspect reads settings.json and reports which events carry our shim.

func (Status) Complete

func (s Status) Complete() bool

Complete reports whether every event is registered and the shim binary exists.

Jump to

Keyboard shortcuts

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