Skip to main content
Hooks are small scripts that run when something happens inside the Gateway. They can be discovered from directories and inspected with fluffbuzz hooks. The Gateway loads internal hooks only after you enable hooks or configure at least one hook entry, hook pack, legacy handler, or extra hook directory. There are two kinds of hooks in FluffBuzz:
  • Internal hooks (this page): run inside the Gateway when agent events fire, like /new, /reset, /stop, or lifecycle events.
  • Webhooks: external HTTP endpoints that let other systems trigger work in FluffBuzz. See Webhooks.
Hooks can also be bundled inside plugins. fluffbuzz hooks list shows both standalone hooks and plugin-managed hooks.

Quick start

Event types

Writing hooks

Hook structure

Each hook is a directory containing two files:

HOOK.md format

Metadata fields (metadata.fluffbuzz):

Handler implementation

Each event includes: type, action, sessionKey, timestamp, messages (push to send to user), and context (event-specific data).

Event context highlights

Command events (command:new, command:reset): context.sessionEntry, context.previousSessionEntry, context.commandSource, context.workspaceDir, context.cfg. Message events (message:received): context.from, context.content, context.channelId, context.metadata (provider-specific data including senderId, senderName, guildId). Message events (message:sent): context.to, context.content, context.success, context.channelId. Message events (message:transcribed): context.transcript, context.from, context.channelId, context.mediaPath. Message events (message:preprocessed): context.bodyForAgent (final enriched body), context.from, context.channelId. Bootstrap events (agent:bootstrap): context.bootstrapFiles (mutable array), context.agentId. Session patch events (session:patch): context.sessionEntry, context.patch (only changed fields), context.cfg. Only privileged clients can trigger patch events. Compaction events: session:compact:before includes messageCount, tokenCount. session:compact:after adds compactedCount, summaryLength, tokensBefore, tokensAfter.

Hook discovery

Hooks are discovered from these directories, in order of increasing override precedence:
  1. Bundled hooks: shipped with FluffBuzz
  2. Plugin hooks: hooks bundled inside installed plugins
  3. Managed hooks: ~/.fluffbuzz/hooks/ (user-installed, shared across workspaces). Extra directories from hooks.internal.load.extraDirs share this precedence.
  4. Workspace hooks: <workspace>/hooks/ (per-agent, disabled by default until explicitly enabled)
Workspace hooks can add new hook names but cannot override bundled, managed, or plugin-provided hooks with the same name. The Gateway skips internal hook discovery on startup until internal hooks are configured. Enable a bundled or managed hook with fluffbuzz hooks enable <name>, install a hook pack, or set hooks.internal.enabled=true to opt in. When you enable one named hook, the Gateway loads only that hook’s handler; hooks.internal.enabled=true, extra hook directories, and legacy handlers opt into broad discovery.

Hook packs

Hook packs are npm packages that export hooks via fluffbuzz.hooks in package.json. Install with:
Npm specs are registry-only (package name + optional exact version or dist-tag). Git/URL/file specs and semver ranges are rejected.

Bundled hooks

Enable any bundled hook:

session-memory details

Extracts the last 15 user/assistant messages, generates a descriptive filename slug via LLM, and saves to <workspace>/memory/YYYY-MM-DD-slug.md. Requires workspace.dir to be configured.

bootstrap-extra-files config

Paths resolve relative to workspace. Only recognized bootstrap basenames are loaded (AGENTS.md, SOUL.md, TOOLS.md, IDENTITY.md, USER.md, HEARTBEAT.md, BOOTSTRAP.md, MEMORY.md).

command-logger details

Logs every slash command to ~/.fluffbuzz/logs/commands.log.

boot-md details

Runs BOOT.md from the active workspace when the gateway starts.

Plugin hooks

Plugins can register hooks through the Plugin SDK for deeper integration: intercepting tool calls, modifying prompts, controlling message flow, and more. The Plugin SDK exposes 28 hooks covering model resolution, agent lifecycle, message flow, tool execution, subagent coordination, and gateway lifecycle. For the complete plugin hook reference including before_tool_call, before_agent_reply, before_install, and all other plugin hooks, see Plugin Architecture.

Configuration

Per-hook environment variables:
Extra hook directories:
The legacy hooks.internal.handlers array config format is still supported for backwards compatibility, but new hooks should use the discovery-based system.

CLI reference

Best practices

  • Keep handlers fast. Hooks run during command processing. Fire-and-forget heavy work with void processInBackground(event).
  • Handle errors gracefully. Wrap risky operations in try/catch; do not throw so other handlers can run.
  • Filter events early. Return immediately if the event type/action is not relevant.
  • Use specific event keys. Prefer "events": ["command:new"] over "events": ["command"] to reduce overhead.

Troubleshooting

Hook not discovered

Hook not eligible

Check for missing binaries (PATH), environment variables, config values, or OS compatibility.

Hook not executing

  1. Verify the hook is enabled: fluffbuzz hooks list
  2. Restart your gateway process so hooks reload.
  3. Check gateway logs: ./scripts/flufflog.sh | grep hook