#15877: fix(hooks): add debug logging to triggerInternalHook
stale
size: S
## Problem
Users report that hooks (like session-memory) register successfully but do not appear to trigger when events occur (#15827). Currently there is no visibility into whether:
- Handlers are being found for an event
- The hook system is being invoked at all
## Solution
Add debug logging to `triggerInternalHook()` to help diagnose hook execution:
1. Log when no handlers are found for an event (helps identify registration issues)
2. Log how many handlers are being triggered (helps verify execution)
## Changes
```typescript
// Before: silent return if no handlers
if (allHandlers.length === 0) {
return;
}
// After: debug logging
if (allHandlers.length === 0) {
console.debug(`Hook: no handlers for ${eventKey}`);
return;
}
console.debug(`Hook: triggering ${allHandlers.length} handler(s) for ${eventKey}`);
```
## Debugging Workflow
With this change, users can now:
1. Enable verbose logging
2. Run `/new` command
3. Check logs for "Hook: triggering..." or "Hook: no handlers..."
4. Determine if issue is registration or execution
Related to #15827
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds debug output in `triggerInternalHook()` to make internal hook execution observable, logging when no handlers are registered and when handlers are about to run.
The change sits in the core internal hooks dispatch path (`src/hooks/internal-hooks.ts`), which is invoked from command handling, gateway startup, and agent bootstrap flows. The added logs are intended to help distinguish between “hook system not invoked” vs “invoked but no matching handlers registered.”
<h3>Confidence Score: 4/5</h3>
- Mostly safe to merge, but logging should be aligned with the repo’s logging controls.
- The functional change is small and localized (adds diagnostics only), but using `console.debug` in a core dispatch path is inconsistent with the repo’s logging approach and may not respect user-configured verbosity or could create noisy output.
- src/hooks/internal-hooks.ts
<sub>Last reviewed commit: ed1d030</sub>
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#3392: fix(hooks): remove debug console.log statements from session-memory...
by WinJayX · 2026-01-28
82.4%
#19922: feat(hooks): add message:received and message:sent hook events
by NOVA-Openclaw · 2026-02-18
78.5%
#19565: feat: add agent lifecycle hook events (session, message, error)
by tag-assistant · 2026-02-17
77.3%
#6853: fix: fire internal hooks on sessions.reset RPC (TUI/webchat /new)
by hamiltonchua · 2026-02-02
76.8%
#11597: feat(hooks): implement message:received hook
by gnufoo · 2026-02-08
76.1%
#13471: fix: security audit distinguishes internal hooks from external webh...
by jarvisz8 · 2026-02-10
75.9%
#8244: feat(hooks): add session:before_compact and session:after_compact i...
by kephail · 2026-02-03
75.8%
#23019: fix(hooks): use globalThis singleton for internal hooks handlers Map
by karmafeast · 2026-02-21
75.7%
#7580: feat: add message:received internal hook with prompt injection
by rodrigoschott · 2026-02-03
75.3%
#13861: feat(hooks): add session:compaction hook event
by lailoo · 2026-02-11
75.0%