#11339: fix: resolve bundled hooks path on npm global install
stale
Cluster:
Hooks Enhancements and Fixes
## Summary
Fixes #11331 (path resolution). The related build/packaging issue is tracked separately in #11348.
## Problem
On npm global installs, the build bundles bundled-dir.ts into a flat chunk in dist/, so import.meta.url resolves to dist/ rather than dist/hooks/bundled-dir.js. The existing code does path.join(moduleDir, "bundled") which looks for dist/bundled, but the hooks live at dist/hooks/bundled.
This causes all four bundled hooks (session-memory, boot-md, command-logger, soul-evil) to be undiscoverable.
## Fix
One-line change: add "hooks" to the path join so it correctly resolves to dist/hooks/bundled.
## Verification
Setting OPENCLAW_BUNDLED_HOOKS_DIR to the correct path manually confirms the gateway discovers all four hook directories. This fix makes that the default behavior.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Updates `resolveBundledHooksDir()` to look for bundled hooks under `dist/hooks/bundled` when `import.meta.url` resolves to the flattened `dist/` directory (observed on npm global installs).
However, the new join logic uses `path.join(moduleDir, "hooks", "bundled")`, which breaks the standard (non-flattened) layout where `import.meta.url` points at `dist/hooks/bundled-dir.js` (it would resolve to `dist/hooks/hooks/bundled`). The resolver should account for both layouts (or resolve from the package root) to avoid regressing non-global installs.
<h3>Confidence Score: 2/5</h3>
- Not safe to merge as-is due to a likely regression in bundled hook discovery for non-flattened installs.
- The change appears to fix the flattened dist/ bundle case, but it deterministically mis-resolves paths when `import.meta.url` points at `dist/hooks/bundled-dir.js` (standard output), causing bundled hooks to become undiscoverable in that scenario.
- src/hooks/bundled-dir.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#9914: fix(hooks): resolve bundled hook dist paths and packaging checks
by zimmra · 2026-02-05
84.3%
#11817: fix(build): compile bundled hook handlers into dist
by AnonO6 · 2026-02-08
83.9%
#16960: perf: skip cache-busting for bundled hooks, use mtime for workspace...
by mudrii · 2026-02-15
80.9%
#14746: fix(hooks): use globalThis for handler registry to survive bundler ...
by openperf · 2026-02-12
80.2%
#19021: fix(hooks): reject path traversal in hook pack manifest entries dur...
by moxunjinmu · 2026-02-17
79.1%
#13471: fix: security audit distinguishes internal hooks from external webh...
by jarvisz8 · 2026-02-10
77.4%
#23019: fix(hooks): use globalThis singleton for internal hooks handlers Map
by karmafeast · 2026-02-21
77.3%
#20541: fix(hooks): clear internal hooks before plugins register
by ramarnat · 2026-02-19
74.8%
#9603: fix: initialize global hook runner on plugin registry cache hit
by kevins88288 · 2026-02-05
74.3%
#17930: fix: evaluate tool_result_persist hooks lazily to avoid race condition
by TheArkifaneVashtorr · 2026-02-16
74.1%