#Hooks not firing properly, logs not explaining why.

1 messages · Page 1 of 1 (latest)

pliant ruin
#

Has anyone else had issues with before_agent_start and before_prompt_build hooks not firing? I’m running into an issue where it says that it’s registered, but it literally just doesn’t fire on agent turns.

We set up a few separate debug codes but nothing is showing up in any logs.

crude jettyBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> âś… Mark Solution

analog wolf
#

True

fierce shellBOT
#

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?

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

  1. openclaw --version
  2. A tiny snippet of how you register the hooks (just the api.on(...) / api.registerHook(...) lines)
  3. The relevant plugins.entries.<id> config block (especially hooks.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:

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:

  1. openclaw --version
  2. 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
pliant ruin
#

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.