hook

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 24 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 hook handles the Claude Code hook events SessionStart, UserPromptSubmit, PermissionRequest, Stop and SessionEnd: it keeps each session's notes, state word and queue current, answers the + commands, and starts the summarizer. A hook must never fail or swallow a user's prompt (invariant 4), so Run reports nothing and recovers from everything.

Index

Constants

View Source
const (
	EventSessionStart     = "SessionStart"
	EventUserPromptSubmit = "UserPromptSubmit"
	EventPermissionReq    = "PermissionRequest"
	EventStop             = "Stop"
	EventSessionEnd       = "SessionEnd"
)

The events that a hook handles. hooks/hooks.json names the same ones, and a test fails when the two differ.

View Source
const Deadline = 60 * time.Second

Deadline is how long the summarizer may take.

Variables

Events is every event that run handles.

Functions

func ReadPending

func ReadPending(path string) (due int64, nonce string, ok bool)

ReadPending reads a pending file: when the run is due, and the nonce of the child that owns it.

Types

type Hook

type Hook struct {
	Store     state.Store
	ConfigDir string // Claude Code's folder, for transcripts
	Getenv    func(string) string
	Clock     clock.Clock
	Out       io.Writer // where a block answer goes
	// CheckUpdates lets an event start the daily look for a newer release; the zero value does not.
	CheckUpdates bool
	// QueueNudge lets a session start and a prompt print one line that tells Claude how many items the queue holds; the zero value does not.
	QueueNudge bool
	// Spawn starts `sitrep <args>` detached from the hook, which must not wait for it.
	Spawn func(args ...string) error
	// Log records the changes the hook makes; the zero Log is off.
	Log histlog.Log
}

Hook handles events for one state folder.

func (Hook) Run

func (h Hook) Run(in io.Reader)

Run handles one event read from in. It never fails and never panics.

type Opts

type Opts struct {
	Wait  int
	Nonce string // names the pending file this run owns; the run stops if another has taken it
	Since string
}

Opts say when to run. Wait is the seconds to sleep first (the deferred run); Since is the prompt count the summary is for, and when it is empty it is read after the wait.

type Summarizer

type Summarizer struct {
	Hook
	Run   runner.Runner
	Sleep func(ctx context.Context, d time.Duration) // waits for d, or until ctx is done
	Env   []string                                   // the environment of the claude call, without SITREP_SUMMARIZING
	Limit time.Duration                              // how long claude may take; Deadline when zero
	// SummaryLang is SITREP_SUMMARY_LANG: a language tag for the three lines. Empty, or not a tag, means the language of the user's messages.
	SummaryLang string
}

Summarizer runs the Haiku summarizer for one session. It is the detached child of the hook.

func (Summarizer) Do

func (z Summarizer) Do(ctx context.Context, id state.ID, tp string, o Opts)

Do waits if asked, summarizes the end of the transcript, and writes Progress and Now (and the Objective, unless it is pinned). A summary made for an older prompt than the newest is dropped.

Jump to

Keyboard shortcuts

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