openclaw - ✅(Solved) Fix Plugin hooks (before_prompt_build, agent_end) never dispatch when using claude-cli provider [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#65157Fetched 2026-04-12 13:25:16
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×2cross-referenced ×1referenced ×1

Memory plugins that register before_prompt_build and agent_end hooks via api.on() never have those hooks dispatched when sessions use the claude-cli provider.

The hooks are correctly registered (confirmed via openclaw plugins info showing all typed hooks), the plugin loads successfully ([plugins] Honcho memory plugin loaded / Honcho memory ready in gateway.log), and gateway_start hooks fire normally. However, per-request hooks (before_prompt_build, agent_end) are never called.

Investigation of the gateway source reveals that these hooks are dispatched only within pi-embedded (the native runner at pi-embedded-*.js:30075 and :32688 via getGlobalHookRunner()), but cli-runner (used by claude-cli provider) does not invoke hook dispatch points during the request lifecycle.

This means all memory plugins (including openclaw-honcho) are non-functional when using claude-cli as the execution provider, since they rely on before_prompt_build for context injection and agent_end for message capture.

Additionally, allowPromptInjection in the plugin hooks config must be explicitly set to true for before_prompt_build to be allowed by the loader (loader-*.js:1341), but this is not documented in the plugin installation guide.

Environment: OpenClaw v2026.4.9 (0512059), macOS, plugin openclaw-honcho v1.3.2, @honcho-ai/sdk v2.1.1

Root Cause

Memory plugins that register before_prompt_build and agent_end hooks via api.on() never have those hooks dispatched when sessions use the claude-cli provider.

The hooks are correctly registered (confirmed via openclaw plugins info showing all typed hooks), the plugin loads successfully ([plugins] Honcho memory plugin loaded / Honcho memory ready in gateway.log), and gateway_start hooks fire normally. However, per-request hooks (before_prompt_build, agent_end) are never called.

Investigation of the gateway source reveals that these hooks are dispatched only within pi-embedded (the native runner at pi-embedded-*.js:30075 and :32688 via getGlobalHookRunner()), but cli-runner (used by claude-cli provider) does not invoke hook dispatch points during the request lifecycle.

This means all memory plugins (including openclaw-honcho) are non-functional when using claude-cli as the execution provider, since they rely on before_prompt_build for context injection and agent_end for message capture.

Additionally, allowPromptInjection in the plugin hooks config must be explicitly set to true for before_prompt_build to be allowed by the loader (loader-*.js:1341), but this is not documented in the plugin installation guide.

Environment: OpenClaw v2026.4.9 (0512059), macOS, plugin openclaw-honcho v1.3.2, @honcho-ai/sdk v2.1.1

Fix Action

Fix / Workaround

Memory plugins that register before_prompt_build and agent_end hooks via api.on() never have those hooks dispatched when sessions use the claude-cli provider.

Investigation of the gateway source reveals that these hooks are dispatched only within pi-embedded (the native runner at pi-embedded-*.js:30075 and :32688 via getGlobalHookRunner()), but cli-runner (used by claude-cli provider) does not invoke hook dispatch points during the request lifecycle.

  1. Install openclaw-honcho v1.3.2: openclaw plugins install @honcho-ai/openclaw-honcho
  2. Run openclaw honcho setup with a self-hosted Honcho server on localhost:8000
  3. Set plugins.slots.memory = "openclaw-honcho" and plugins.allow = ["openclaw-honcho"] in openclaw.json
  4. Set plugins.entries.openclaw-honcho.hooks.allowPromptInjection = true
  5. Gateway reloads, plugin shows Status: loaded with all hooks registered
  6. Open any chat session (provider = claude-cli)
  7. Send messages and close the session
  8. Check gateway.log: zero occurrences of agent_end, zero hook dispatch entries
  9. Check /tmp/honcho.log: no new API calls from the plugin after initial gateway_start
  10. Open a new session: no Honcho context injected (before_prompt_build never ran)

PR fix notes

PR #65167: fix: dispatch plugin hooks (before_prompt_build, agent_end) in cli-runner

Description (problem / solution / changelog)

Summary

Fixes plugin hooks (before_prompt_build, agent_end) not being dispatched when using the claude-cli provider.

Root cause

The cli-runner did not invoke hook dispatch points during the request lifecycle, while pi-embedded correctly dispatches all hooks. This means memory plugins that rely on these hooks were non-functional with claude-cli.

Fix

  • Added before_prompt_build hook dispatch before the CLI prompt is sent, using resolvePromptBuildHookResult() (same pattern as pi-embedded runner)
  • Added agent_end hook dispatch after the CLI response is received (fire-and-forget, same as pi-embedded)
  • Hook results (prependContext, systemPrompt) are applied to the CLI prompt/context
  • Uses the same getGlobalHookRunner() pattern as pi-embedded

Testing

  • Verified TypeScript compilation passes (no type errors in changed file)
  • Ran cli-runner test suite: cli-runner.reliability.test.ts (5 pass), cli-runner.helpers.test.ts (4 pass), cli-runner.session.test.ts (2 pass), cli-runner.spawn.test.ts (pass)
  • Ran hook phase tests: hooks.phase-hooks.test.ts (3 pass)
  • Ran pi-embedded attempt tests: attempt.test.ts (93 pass)

Fixes openclaw/openclaw#65157

Changed files

  • src/agents/cli-runner.error-sanitize.test.ts (added, +50/-0)
  • src/agents/cli-runner.ts (modified, +87/-2)
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

Memory plugins that register before_prompt_build and agent_end hooks via api.on() never have those hooks dispatched when sessions use the claude-cli provider.

The hooks are correctly registered (confirmed via openclaw plugins info showing all typed hooks), the plugin loads successfully ([plugins] Honcho memory plugin loaded / Honcho memory ready in gateway.log), and gateway_start hooks fire normally. However, per-request hooks (before_prompt_build, agent_end) are never called.

Investigation of the gateway source reveals that these hooks are dispatched only within pi-embedded (the native runner at pi-embedded-*.js:30075 and :32688 via getGlobalHookRunner()), but cli-runner (used by claude-cli provider) does not invoke hook dispatch points during the request lifecycle.

This means all memory plugins (including openclaw-honcho) are non-functional when using claude-cli as the execution provider, since they rely on before_prompt_build for context injection and agent_end for message capture.

Additionally, allowPromptInjection in the plugin hooks config must be explicitly set to true for before_prompt_build to be allowed by the loader (loader-*.js:1341), but this is not documented in the plugin installation guide.

Environment: OpenClaw v2026.4.9 (0512059), macOS, plugin openclaw-honcho v1.3.2, @honcho-ai/sdk v2.1.1

Steps to reproduce

  1. Install openclaw-honcho v1.3.2: openclaw plugins install @honcho-ai/openclaw-honcho
  2. Run openclaw honcho setup with a self-hosted Honcho server on localhost:8000
  3. Set plugins.slots.memory = "openclaw-honcho" and plugins.allow = ["openclaw-honcho"] in openclaw.json
  4. Set plugins.entries.openclaw-honcho.hooks.allowPromptInjection = true
  5. Gateway reloads, plugin shows Status: loaded with all hooks registered
  6. Open any chat session (provider = claude-cli)
  7. Send messages and close the session
  8. Check gateway.log: zero occurrences of agent_end, zero hook dispatch entries
  9. Check /tmp/honcho.log: no new API calls from the plugin after initial gateway_start
  10. Open a new session: no Honcho context injected (before_prompt_build never ran)

Expected: Hooks fire on every request (before_prompt_build) and after every turn (agent_end) Actual: Hooks never fire. Gateway log only shows [agent] cli exec: provider=claude-cli with no hook-related entries.

Expected behavior

When a memory plugin (e.g. openclaw-honcho) registers before_prompt_build and agent_end hooks, those hooks should fire during every request cycle regardless of which provider/runner is active. Specifically: before_prompt_build should inject retrieved memory context into the prompt, and agent_end should capture the conversation turn for storage. This works correctly with the pi-embedded runner.

Actual behavior

Neither before_prompt_build nor agent_end hooks fire when using the claude-cli provider. The cli-runner (cli-runner-DgGAOeQQ.js) does not contain any hook dispatch calls — only the pi-embedded runner dispatches these hooks (at lines ~30075 and ~32688 in pi-embedded-*.js). As a result, all memory plugins are non-functional with claude-cli. The gateway_start hook fires normally (gateway-level), confirming the plugin loads correctly but per-request hooks are skipped entirely.

OpenClaw version

2026.4.9 (0512059)

Operating system

macOS (Apple Silicon / Homebrew)

Install method

npm global

Model

anthropic/claude-sonnet-4-6

Provider / routing chain

openclaw → claude-cli → anthropic

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

The claude-cli provider does not dispatch before_prompt_build and agent_end hooks to memory plugins, rendering them non-functional.

Guidance

  • Investigate modifying the cli-runner to include hook dispatch calls for before_prompt_build and agent_end, similar to the pi-embedded runner.
  • Verify that allowPromptInjection is set to true in the plugin hooks config to ensure before_prompt_build is allowed by the loader.
  • Consider updating the plugin installation guide to include documentation on setting allowPromptInjection to true.
  • Check if there are any existing issues or pull requests related to hook dispatch in the cli-runner that may provide a solution or workaround.

Example

No code snippet is provided as the issue requires investigation and modification of the cli-runner code.

Notes

The issue is specific to the claude-cli provider and does not affect the pi-embedded runner. The gateway_start hook fires normally, indicating that the plugin loads correctly, but per-request hooks are skipped entirely.

Recommendation

Apply a workaround by modifying the cli-runner to include hook dispatch calls for before_prompt_build and agent_end, as the pi-embedded runner does, to enable memory plugins to function with the claude-cli provider.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

When a memory plugin (e.g. openclaw-honcho) registers before_prompt_build and agent_end hooks, those hooks should fire during every request cycle regardless of which provider/runner is active. Specifically: before_prompt_build should inject retrieved memory context into the prompt, and agent_end should capture the conversation turn for storage. This works correctly with the pi-embedded runner.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Plugin hooks (before_prompt_build, agent_end) never dispatch when using claude-cli provider [1 pull requests, 1 participants]