Files
Michael Neale 83c0dcfebf feat: add lifecycle hooks system
Adds a hooks module that lets users extend goose at key lifecycle points
via shell commands or HTTP endpoints, configured in config.yaml.

Hook events:
  - before_tool_call: fires before tool execution, can block (exit 2)
  - after_tool_call: fires after tool dispatch
  - before_reply: fires when user message arrives
  - after_reply: available via emit_hook() for callers
  - on_session_start / on_session_end: available via emit_hook()

Configuration (in ~/.config/goose/config.yaml):
  hooks:
    before_tool_call:
      - matcher: "bash|write_file"
        hooks:
          - command: "~/.config/goose/hooks/safety-check.sh"
            timeout: 5
    after_tool_call:
      - hooks:
          - url: "http://localhost:9000/hook"

Wire protocol:
  - Shell: JSON on stdin, optional JSON on stdout
  - HTTP: JSON POST body, optional JSON response
  - Exit code 2 = block (Claude Code convention)
  - Supports Claude Code (decision/reason), Hermes (action/message),
    and direct (block/reason) response formats

Design principles:
  - Fail-open: broken hooks log warnings, never crash the agent
  - Matcher filtering: regex against tool name for tool events
  - Short-circuit: first block wins for before_tool_call
  - Zero overhead: has_hooks() fast-path skips when no hooks configured

Signed-off-by: Michael Neale <michael.neale@gmail.com>
2026-04-24 22:55:37 -07:00
..
2026-04-24 22:55:37 -07:00