Lifecycle Hooks
botmux can asynchronously invoke external commands when key lifecycle events occur. If a command fails, times out, or doesn't exist, it only writes to the log and never blocks botmux's main flow.
Configuration Location
In order of precedence (highest to lowest):
- The
BOTMUX_HOOKS_JSONenvironment variable (pass a JSON array directly) - The file path specified by
BOTMUX_HOOKS_FILE - The default
~/.botmux/data/hooks.json
Quick Check: Write to a Local Log
The repo ships an example script you can copy and use right away:
After any hook event fires, you'll see the JSON payload in the log. examples/hooks/ also includes examples for macOS Notification Center (osascript-notify.sh) and HTTP webhooks (http-webhook.sh).
Configuration Fields
Supported Events
Payload Fields
Every payload is written to the hook command via stdin, and the environment variable BOTMUX_HOOK_EVENT is also set. Each payload includes event and emittedAt; the event context may include sessionId, chatId, chatType, larkAppId, scope, anchor, title, cliId, workingDir, hasHistory, spawnedAt, and lastMessageAt.
Different events carry extra fields:
By default, content, message, description, finalOutput, and lastScreenContent are truncated to 600 characters, with xxxLength / xxxTruncated added; only events in redact.fullContentEvents pass through the full text.
Writing Your Own Hook
A hook command can be any executable: a bash / Python / Node / Go binary, an internal company CLI, or an HTTP forwarder. A command that does exit 0 is treated as a success; non-zero exits / timeouts / missing commands only write to the botmux log and never affect message send/receive, scheduled tasks, or the session lifecycle.