hook

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package hook implements normalized Claude Code and Codex hook handlers. This is the hot path: it runs on every prompt the user types.

The two contracts that own this package (see /project-rule):

  • C1 fail-open (14.40): any error ⇒ log + empty stdout + exit 0. stdout belongs to the hook JSON protocol; the ONLY stdout write is the single success emit in Run.
  • C2 deadline (14.41): all work runs under a context deadline below the settings.json hook timeout; a fired deadline logs a breadcrumb so silent degradation stays observable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(args []string, in io.Reader, out io.Writer) (code int)

Run executes one hook event, reading stdin JSON from in and writing the protocol response to out. ALWAYS returns 0.

Types

type Input

type Input struct {
	SessionID      string          `json:"session_id"`
	TranscriptPath string          `json:"transcript_path"`
	CWD            string          `json:"cwd"`
	Prompt         string          `json:"prompt"`
	HookEventName  string          `json:"hook_event_name"`
	Source         string          `json:"source"` // SessionStart: startup|resume|clear|compact
	Harness        harness.Harness `json:"-"`      // adapter identity, not hook-provided JSON
}

Input is the normalized hook event. Claude Code's stdin JSON maps directly; other harnesses become adapters onto this struct (ecosystem learning: normalized event seam from day one).

Jump to

Keyboard shortcuts

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