hooks

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 17 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 runs user hook commands on agent events. Hook definitions come from Scribe's config files and from Claude Code-compatible settings.json files, so existing Claude hooks work unchanged.

Trust: the user's own files (global Scribe config and ~/.claude/settings.json) always run. Anything inside a project (its .scribe/config.json and .claude/settings*.json) runs only when the project is trusted.

Index

Constants

This section is empty.

Variables

View Source
var Events = []string{
	evPreTool, evPostTool, evPostToolFailure, evPrompt, evStop, evStopFailure,
	evSessionStart, evSessionEnd, evPreCompact, evPostCompact,
	evSubagentStart, evSubagentStop, evNotification,
}

Events lists every hook event the runner fires, in Claude Code's names. The settings files may name any event; these are the ones that run.

Functions

func LoadConfigHooks

func LoadConfigHooks(root string) (global, project []config.Hook, err error)

LoadConfigHooks reads the hooks arrays of the global and project config files separately, so the caller can gate the project one on trust.

func Trust

func Trust(root string) error

Trust records that the project at root may run its own hooks and MCP servers. Only call this after the user has said yes.

func TrustPath

func TrustPath() string

TrustPath is where the list of trusted project roots is kept.

func Trusted

func Trusted(root string) bool

Trusted reports whether the project at root may run its own hooks and MCP servers (the repo's .claude/settings.json, .scribe/config.json, .mcp.json). A missing or unreadable trust file means untrusted.

func Untrust

func Untrust(root string) error

Untrust removes the project at root from the trust list.

func WithToolUseID

func WithToolUseID(ctx context.Context, id string) context.Context

WithToolUseID returns ctx carrying the provider's id for the tool call about to run. The tool hooks put it in their stdin as tool_use_id, so a hook can tie its record to one call. The agent sets it before it calls the hooks; without it the field is an empty string.

Types

type EventCount

type EventCount struct {
	Event string
	Hooks int
	Off   bool
}

EventCount is one hook event in the configured hooks, with how many hooks it runs and whether it is switched off for this session.

type Options

type Options struct {
	Root      string // project root; hooks run here
	SessionID string
	// ConfigGlobal and ConfigProject are the hooks arrays of the Scribe
	// global and project config files (see LoadConfigHooks).
	ConfigGlobal  []config.Hook
	ConfigProject []config.Hook
	// UserSettings is a Claude settings.json (default ~/.claude/settings.json).
	UserSettings string
	// Trusted allows project-level hooks (project config, repo settings).
	Trusted bool
}

Options configures a Runner. Use NewFromDisk for the normal case.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner runs hooks. It implements agent.Hooks. Methods are safe for concurrent use.

func New

func New(o Options) *Runner

New builds a Runner from explicit options.

func NewFromDisk

func NewFromDisk(root, sessionID string) (*Runner, error)

NewFromDisk builds a Runner from the config files, ~/.claude/settings.json and the project's trust state.

func (*Runner) Count

func (r *Runner) Count() int

Count reports how many hooks will run.

func (*Runner) EventCounts

func (r *Runner) EventCounts() []EventCount

EventCounts lists the events the configured hooks use, in first-seen order.

func (*Runner) Notification

func (r *Runner) Notification(ctx context.Context, msg string)

Notification runs Notification hooks with msg.

func (*Runner) PostCompact

func (r *Runner) PostCompact(ctx context.Context)

PostCompact runs PostCompact hooks once the history has been compacted.

func (*Runner) PostTool

func (r *Runner) PostTool(ctx context.Context, tool string, args json.RawMessage, res tools.Result) string

PostTool implements agent.Hooks. Every matching hook runs; their extra text is joined. Blocks are not meaningful after a call and are ignored.

func (*Runner) PostToolFailure

func (r *Runner) PostToolFailure(ctx context.Context, tool string, args json.RawMessage, res tools.Result) string

PostToolFailure runs the PostToolUseFailure hooks for a call that failed. PostTool calls it for failed calls that reached the tool; the agent calls it directly for a call refused before it ran (unknown tool, blocked by a hook, not available for this step), so every failure is reported once. Extra text is returned for the model, as PostTool's is.

func (*Runner) PreCompact

func (r *Runner) PreCompact(ctx context.Context)

PreCompact runs PreCompact hooks before the history is compacted.

func (*Runner) PreTool

func (r *Runner) PreTool(ctx context.Context, tool string, args json.RawMessage) string

PreTool implements agent.Hooks. Sequential; the first block wins.

func (*Runner) PreToolUpdate

func (r *Runner) PreToolUpdate(ctx context.Context, tool string, args json.RawMessage) (json.RawMessage, string)

PreToolUpdate implements the agent's toolInputRewriter. It runs the same PreToolUse hooks as PreTool, in order, and a hook's hookSpecificOutput.updatedInput replaces the tool input for the hooks after it and for the call. The first block wins, and the input returned is the one the call runs with. An updatedInput that is not a JSON object is ignored with a warning, since a tool takes an object of named arguments.

func (*Runner) Prompt

func (r *Runner) Prompt(ctx context.Context, prompt string) (extra, block string)

Prompt implements agent.Hooks.

func (*Runner) SessionEnd

func (r *Runner) SessionEnd(ctx context.Context)

SessionEnd runs SessionEnd hooks.

func (*Runner) SessionStart

func (r *Runner) SessionStart(ctx context.Context)

SessionStart runs SessionStart hooks.

func (*Runner) SetEventOff

func (r *Runner) SetEventOff(event string, off bool)

SetEventOff switches every hook of one event off, or back on, for this runner only. Nothing is written to any config file.

func (*Runner) SetStatus

func (r *Runner) SetStatus(f func(string))

SetStatus sets where a hook's statusMessage goes while the hook runs. The app shows it as a notice in the transcript. Nil turns it off.

func (*Runner) Stop

func (r *Runner) Stop(ctx context.Context, stats agent.TurnStats)

Stop implements agent.Hooks. All hooks run; blocks are ignored.

func (*Runner) SubagentStart

func (r *Runner) SubagentStart(ctx context.Context, role, task string)

SubagentStart runs SubagentStart hooks as a subagent of role begins task.

func (*Runner) SubagentStop

func (r *Runner) SubagentStop(ctx context.Context, role, task, errText string)

SubagentStop runs SubagentStop hooks when that subagent ends. errText is empty when it finished normally.

func (*Runner) Warnings

func (r *Runner) Warnings() []string

Warnings returns and clears the warnings collected so far: skipped hooks, non-zero exits, timeouts. The UI shows them.

Jump to

Keyboard shortcuts

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