#Hooks not firing properly, logs not explaining why.
1 messages · Page 1 of 1 (latest)
True
before_prompt_build / before_agent_start are plugin lifecycle hooks, not “internal hooks” (the openclaw hooks … system). So the #1 failure mode I’ve seen is folks registering them in the wrong hook system (or having prompt injection blocked), which makes them look “registered” but they’ll never fire on turns.
A quick sanity checklist:
1) Are you writing an internal hook pack or an extension plugin?
- Internal hooks (
openclaw hooks install,HOOK.md, etc.) only get events likecommand:new,agent:bootstrap,message:preprocessed, etc. (no per-turnbefore_prompt_build).
Docs: https://docs.openclaw.ai/automation/hooks#event-types - Plugin hooks (per-turn prompt/model/tool lifecycle) are registered via
api.on(...).
Docs: https://docs.openclaw.ai/tools/plugin#agent-lifecycle-hooks-api-on
Agent loop overview: https://docs.openclaw.ai/concepts/agent-loop#plugin-hooks-agent--gateway-lifecycle
If you’re currently doing something like api.registerHook("before_prompt_build", ...), that won’t ever trigger — registerHook is for the internal event strings (e.g. command:new), while before_prompt_build must be api.on("before_prompt_build", ...).
2) Check allowPromptInjection
If your plugin config has:
plugins: {
entries: {
"<yourPluginId>": {
hooks: { allowPromptInjection: false }
}
}
}
then core will block before_prompt_build entirely, and it will appear as “not firing”. (It will also constrain legacy before_agent_start prompt fields.)
Config reference: https://docs.openclaw.ai/gateway/configuration-reference (see plugins.entries.<id>.hooks.allowPromptInjection)
3) Logging expectations
Inside a plugin, prefer api.logger.info(...) over console.log, and tail logs with:
openclaw logs --follow
Docs: https://docs.openclaw.ai/logging
What I need from you to pinpoint it
openclaw --version- A tiny snippet of how you register the hooks (just the
api.on(...)/api.registerHook(...)lines) - The relevant
plugins.entries.<id>config block (especiallyhooks.allowPromptInjection)
Also: since you asked “has anyone else…”, you’ll probably get more “yep, same here” reports in #users-helping-users, but we can get you unblocked here with the concrete details above.
If by “True” you mean you’re using the internal hooks system (openclaw hooks … / HOOK.md), then yep — that’s the issue:
before_prompt_build/before_agent_startwill never fire from internal hooks. Internal hooks only get events likecommand:new,agent:bootstrap,message:preprocessed, etc.
Docs: https://docs.openclaw.ai/automation/hooks#event-types
To run before_prompt_build you need an extension plugin and register it via api.on("before_prompt_build", ...) (not api.registerHook(...)).
Docs: https://docs.openclaw.ai/tools/plugin#agent-lifecycle-hooks-api-on
Two quick things to paste so we can zero in fast:
openclaw --version- The exact registration snippet you have (the lines where you call
registerHook(...)/on(...)) + your plugin config block if applicable (plugins.entries.<id>...), especially whether you set:
plugins.entries.<id>.hooks.allowPromptInjection: false
(because that blocks before_prompt_build entirely)
Also tail logs while reproducing:
openclaw logs --follow
Thank you. Our problem was that the allowPromptInjection apparently wasn’t standard in the config, so we had to add it as it defaults to off or undefined, i think?
Also, we changed api.registerhook to api.on
I don’t know which specifically fixed it because both changes were made concurrently. Could have been one or both. But, the problem got solved.