openclaw - 💡(How to fix) Fix Add UserPromptSubmit and Stop hook event support (Claude Code SDK compatibility)

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…

Fix Action

Fix / Workaround

Workaround in the meantime

Code Example

.claude/settings.json    # declares UserPromptSubmit hooks
.claude/hooks/           # contains executable hook scripts

---

{
  \"hooks\": {
    \"UserPromptSubmit\": [
      { \"hooks\": [{ \"type\": \"command\", \"command\": \"/path/to/script.sh\" }] }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Use case

Users wiring workspace/.claude/settings.json UserPromptSubmit hooks following the Claude Code SDK convention expect them to fire on every user prompt. Today they don't — the hooks exist on disk, are correctly configured, and work when invoked manually, but the OpenClaw harness never invokes them.

This matters for:

  • Auto-firing named skills on natural-language triggers (e.g., "investigate this" → invoke a gstack /investigate skill)
  • Injecting deterministic <system-reminder> blocks for format enforcement, safety gates, role conventions
  • Any pattern where the user wants reliable phrase-based behavior instead of relying on the model to read trigger metadata in long Telegram wrapper headers

Current state in [email protected]

Source search of the dist bundle shows two Claude Code hook event names are emitted by native-hook-relay-*.js:

  • PreToolUse
  • PermissionRequest

Other Claude Code SDK hook events have zero references in the OpenClaw dist:

  • UserPromptSubmit
  • Stop
  • PostToolUse
  • SubagentStop
  • PreCompact

(The substring "Stop" appears 424 times but matches internal OpenClaw lifecycle terms like onStopped, gateway_stop, runDaemonStop — not the Claude Code Stop hook event.)

Reproduction

A workspace at ~/.openclaw/workspace/ with:

.claude/settings.json    # declares UserPromptSubmit hooks
.claude/hooks/           # contains executable hook scripts

Settings file:

{
  \"hooks\": {
    \"UserPromptSubmit\": [
      { \"hooks\": [{ \"type\": \"command\", \"command\": \"/path/to/script.sh\" }] }
    ]
  }
}

Instrument the hook script with `echo "fired $(date)" >> /tmp/hook-test.log` at its very top. Send several user prompts through any OpenClaw channel (Telegram, CLI, etc.). The log file remains empty — the script is never invoked.

The hook script itself works correctly when piped a JSON event manually (`echo '{"prompt":"..."}' | ./script.sh`), confirming the issue is purely that the harness doesn't relay UserPromptSubmit events to user hooks.

Requested scope

Minimum viable addition: support for `UserPromptSubmit` and `Stop` event types from `.claude/settings.json` (both workspace-level at `<workspace>/.claude/settings.json` and user-level at `~/.claude/settings.json`). These two cover ~90% of practical hook use cases — input-side phrase detection (UserPromptSubmit) plus output-side reply linting / format gating (Stop with `{decision: 'block', reason: ...}`).

Stretch: full Claude Code SDK hook surface (`PostToolUse`, `SubagentStop`, `PreCompact`, `SessionStart`, `Notification`).

References

Workaround in the meantime

Users can edit `<workspace>/AGENTS.md` or `<workspace>/CLAUDE.md` to add always-loaded system instructions (the OpenClaw `bootstrap-files` mechanism), but this consumes context tokens on every session and doesn't enforce on the output side. UserPromptSubmit + Stop hooks would be a substantially better fit for many enforcement use cases.

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…

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 - 💡(How to fix) Fix Add UserPromptSubmit and Stop hook event support (Claude Code SDK compatibility)