Skip to content

docs: Document undocumented hooks (before_agent_start, message_received, etc.) #12436

@ksato8710

Description

@ksato8710

Background

While trying to implement automatic Slack thread context injection for our AI agents, we consulted the hooks documentation (docs/hooks.md). The doc lists message:received under "Future Events", which led us to believe this functionality was not available.

However, after reverse-engineering the implementation (dist/loader-n6BPnYom.js), we discovered that many hooks are already implemented but not documented:

Implemented but Undocumented Hooks

Hook Name Type Status in Code Status in Docs
before_agent_start modifying ✅ Implemented ❌ Not documented
agent_end void ✅ Implemented ❌ Not documented
message_received void ✅ Implemented Listed as "Future"
message_sending modifying ✅ Implemented ❌ Not documented
message_sent void ✅ Implemented Listed as "Future"
before_tool_call modifying ✅ Implemented ❌ Not documented
after_tool_call void ✅ Implemented ❌ Not documented
session_start void ✅ Implemented Listed as "Future"
session_end void ✅ Implemented Listed as "Future"

Key Discovery: before_agent_start Hook

This hook is particularly powerful:

async function runBeforeAgentStart(event, ctx) {
  return runModifyingHook("before_agent_start", event, ctx, (acc, next) => ({
    systemPrompt: next.systemPrompt ?? acc?.systemPrompt,
    prependContext: ...
  }));
}

Capabilities:

  • event.prompt — User's message
  • event.messages — Session conversation history
  • ctx.sessionKey — Session key (can identify channel/thread)
  • ctx.agentId — Agent ID
  • ctx.workspaceDir — Workspace directory
  • ctx.messageProvider — Message provider (e.g., "slack")
  • Returns prependContext to inject context before the prompt
  • Returns systemPrompt to modify system prompt

This allows fetching external context (e.g., Slack thread history) and injecting it before the agent processes the message.

Request

Please update docs/hooks.md to document these implemented hooks. Other users may be giving up on features that are actually available.

Environment

  • OpenClaw version: 2026.2.6-3
  • Installation: npm global (homebrew)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions