fix(hooks): include required hookEventName in hookSpecificOutput JSON

outputWithContext() emitted a hookSpecificOutput object without the
required hookEventName field, so Claude Code rejected the hook output
("hookSpecificOutput is missing required field hookEventName") and
dropped the context the SessionStart, UserPromptSubmit, and PostToolUse
hooks tried to inject. Thread the event name through the helper; each
caller now passes its own (SessionStart / UserPromptSubmit / PostToolUse).
Existing emission tests now assert hookEventName per event.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VmHCQjJHUyWwxGAVVjNLgp
This commit is contained in:
Kjell Tore Guttormsen 2026-06-24 06:46:11 +02:00
commit 7d53a7325e
8 changed files with 22 additions and 6 deletions

View file

@ -289,10 +289,11 @@ export function outputContinue() {
process.stdout.write(JSON.stringify({ continue: true }) + '\n');
}
export function outputWithContext(message) {
export function outputWithContext(message, hookEventName) {
process.stdout.write(JSON.stringify({
continue: true,
hookSpecificOutput: {
hookEventName,
additionalContext: message
}
}) + '\n');

View file

@ -487,7 +487,7 @@ if (warnings.length > 0) {
const freshState = readState();
freshState.last_warning_epoch = nowEpoch();
writeState(freshState);
outputWithContext(warnings.join(' '));
outputWithContext(warnings.join(' '), 'UserPromptSubmit');
} else {
outputContinue();
}

View file

@ -93,4 +93,4 @@ if (recent.length >= TIER2_SESSION_THRESHOLD) {
}
}
outputWithContext(msg);
outputWithContext(msg, 'SessionStart');

View file

@ -127,7 +127,7 @@ const late = isLateNight() ? ' Late-night session.' : '';
// No warnings — just periodic reminder at modulo-25
if (!level) {
if (toolCount % 25 === 0) {
outputWithContext('REMINDER (Interaction Awareness): Check your next response against these rules — no unearned affirmations, no reformulating the user\'s words in stronger terms, no skipping counterarguments to stay agreeable. If you detect a reinforcement loop, scope escalation, or narrative crystallization: name it now.');
outputWithContext('REMINDER (Interaction Awareness): Check your next response against these rules — no unearned affirmations, no reformulating the user\'s words in stronger terms, no skipping counterarguments to stay agreeable. If you detect a reinforcement loop, scope escalation, or narrative crystallization: name it now.', 'PostToolUse');
} else {
outputContinue();
}
@ -141,7 +141,7 @@ const elapsed = nowTs - lastWarning;
if (lastWarning > 0 && elapsed < cooldown) {
// Still in cooldown — send periodic reminder instead if at modulo-25
if (toolCount % 25 === 0) {
outputWithContext('REMINDER (Interaction Awareness): Check your next response against these rules — no unearned affirmations, no reformulating the user\'s words in stronger terms, no skipping counterarguments to stay agreeable.');
outputWithContext('REMINDER (Interaction Awareness): Check your next response against these rules — no unearned affirmations, no reformulating the user\'s words in stronger terms, no skipping counterarguments to stay agreeable.', 'PostToolUse');
} else {
outputContinue();
}
@ -163,4 +163,4 @@ state = readState();
state.last_warning_epoch = nowTs;
writeState(state);
outputWithContext(warning);
outputWithContext(warning, 'PostToolUse');