Caricamento in corso...
Caricamento in corso...
Last synced: Today, 22:00
Technical reference for the OpenClaw framework. Real-time synchronization with the official documentation engine.
Use this file to discover all available pages before exploring further.
Plugin hooks are in-process extension points for OpenClaw plugins. Use them when a plugin needs to inspect or change agent runs, tool calls, message flow, session lifecycle, subagent routing, installs, or Gateway startup.
Use internal hooks instead when you want a small operator-installed
HOOK.md/new/reset/stopagent:bootstrapgateway:startupRegister typed plugin hooks with
api.on(...)typescriptimport { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry"; export default definePluginEntry({ id: "tool-preflight", name: "Tool Preflight", register(api) { api.on( "before_tool_call", async (event) => { if (event.toolName !== "web_search") { return; } return { requireApproval: { title: "Run web search", description: `Allow search query: ${String(event.params.query ?? "")}`, severity: "info", timeoutMs: 60_000, timeoutBehavior: "deny", }, }; }, { priority: 50 }, ); }, });
Hook handlers run sequentially in descending
priorityapi.on(name, handler, opts?)prioritytimeoutMsEach hook receives
event.context.pluginConfigHooks are grouped by the surface they extend. Names in bold accept a decision result (block, cancel, override, or require approval); all others are observation-only.
Agent turn
before_model_resolveagent_turn_preparebefore_prompt_buildbefore_agent_startbefore_agent_replybefore_agent_finalizeagent_endheartbeat_prompt_contributionConversation observation
model_call_startedmodel_call_endedllm_inputllm_outputTools
before_tool_callafter_tool_calltool_result_persistbefore_message_writeMessages and delivery
inbound_claimmessage_receivedmessage_sendingmessage_sentbefore_dispatchreply_dispatchSessions and compaction
session_startsession_endbefore_compactionafter_compactionbefore_reset/resetSubagents
subagent_spawningsubagent_delivery_targetsubagent_spawnedsubagent_endedLifecycle
gateway_startgateway_stopcron_changedbefore_installbefore_tool_callevent.toolNameevent.paramsevent.runIdevent.toolCallIdctx.agentIdctx.sessionKeyctx.sessionIdctx.runIdctx.jobIdctx.traceIt can return:
typescripttype BeforeToolCallResult = { params?: Record<string, unknown>; block?: boolean; blockReason?: string; requireApproval?: { title: string; description: string; severity?: "info" | "warning" | "critical"; timeoutMs?: number; timeoutBehavior?: "allow" | "deny"; pluginId?: string; onResolution?: ( decision: "allow-once" | "allow-always" | "deny" | "timeout" | "cancelled", ) => Promise<void> | void; }; };
Rules:
block: trueblock: falseparamsrequireApproval/approveblock: trueonResolutionallow-onceallow-alwaysdenytimeoutcancelledBundled plugins that need host-level policy can register trusted tool policies with
api.registerTrustedToolPolicy(...)before_tool_callbefore_tool_callTool results can include structured
detailsdetailstoolResult.detailsdetailspersistedDetailsTruncated: truetool_result_persistbefore_message_writedetailsdetailscontentUse the phase-specific hooks for new plugins:
before_model_resolveproviderOverridemodelOverrideagent_turn_prepareprependContextappendContextbefore_prompt_buildprependContextappendContextsystemPromptprependSystemContextappendSystemContextheartbeat_prompt_contributionprependContextappendContextbefore_agent_startbefore_agent_startagent_endevent.runIdctx.runIdctx.jobIdagent_endUse
model_call_startedmodel_call_endedrunIdcallIdprovidermodelapitransportdurationMsoutcomeupstreamRequestIdHashbefore_agent_finalize/stop{ action: "revise", reason }{ action: "finalize", reason? }Stopbefore_agent_finalizeNon-bundled plugins that need
llm_inputllm_outputbefore_agent_finalizeagent_endjson{ "plugins": { "entries": { "my-plugin": { "hooks": { "allowConversationAccess": true } } } } }
Prompt-mutating hooks and durable next-turn injections can be disabled per plugin with
plugins.entries.<id>.hooks.allowPromptInjection=falseWorkflow plugins can persist small JSON-compatible session state with
api.registerSessionExtension(...)sessions.pluginPatchpluginExtensionsUse
api.enqueueNextTurnInjection(...)idempotencyKeyCleanup semantics are part of the contract. Session extension cleanup and runtime lifecycle cleanup callbacks receive
resetdeletedisablerestartUse message hooks for channel-level routing and delivery policy:
message_receivedthreadIdmessageIdsenderIdmessage_sendingcontent{ cancel: true }message_sentFor audio-only TTS replies,
contentcontentMessage hook contexts expose stable correlation fields when available:
ctx.sessionKeyctx.runIdctx.messageIdctx.senderIdctx.tracectx.traceIdctx.spanIdctx.parentSpanIdctx.callDepthPrefer typed
threadIdreplyToIdDecision rules:
message_sendingcancel: truemessage_sendingcancel: falsecontentbefore_install{ block: true, blockReason }block: trueblock: falseUse
gateway_startctx.configctx.workspaceDirctx.getCron?.()gateway_stopDo not rely on the internal
gateway:startupcron_changedaddedupdatedremovedstartedfinishedscheduledPluginHookGatewayCronJobstate.nextRunAtMsstate.lastRunStatusstate.lastErrorPluginHookGatewayCronDeliveryStatusnot-requesteddeliverednot-deliveredunknownctx.getCron?.()ctx.configA few hook-adjacent surfaces are deprecated but still supported. Migrate before the next major release:
inbound_claimmessage_receivedBodyForAgentbefore_agent_startbefore_model_resolvebefore_prompt_buildonResolutionbefore_tool_callPluginApprovalResolutionallow-onceallow-alwaysdenytimeoutcancelledstringFor the full list — memory capability registration, provider thinking profile, external auth providers, provider discovery types, task runtime accessors, and the
command-authcommand-status© 2024 TaskFlow Mirror
Powered by TaskFlow Sync Engine