Rename stderr-test-hook to user-message-hook for production

Changes:
- Renamed src/hooks/stderr-test-hook.ts to user-message-hook.ts
- Updated user-message-hook with production-ready messaging
- Updated scripts/build-hooks.js to build user-message-hook
- Updated plugin/hooks/hooks.json to reference user-message-hook.js
- Cleaned up old stderr-test-hook.js files
- Built and deployed user-message-hook.js to plugin directory

This hook displays context information to users via stderr, which is
currently the only way to show messages in Claude Code UI. It runs in
parallel with context-hook during SessionStart.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Alex Newman
2025-10-26 23:14:19 -04:00
parent 056cd12558
commit 15c55a57a3
7 changed files with 43 additions and 28 deletions
+4 -10
View File
@@ -399,23 +399,17 @@ function contextHook(input?: SessionStartInput, useColors: boolean = false, useI
} else {
output.push(`*Use claude-mem MCP search to access records with the given ID*`);
}
output.push('');
}
// Footer
if (useColors) {
output.push(`${colors.gray}${'─'.repeat(60)}${colors.reset}`);
output.push('');
}
db.close();
return output.join('\n');
return output.join('\n').trimEnd();
}
// Entry Point - handle stdin/stdout
const useIndexView = process.argv.includes('--index');
const forceColors = process.argv.includes('--colors'); // Add this line
if (stdin.isTTY) {
if (stdin.isTTY || forceColors) { // Modify this line to include forceColors
// Running manually from terminal - print formatted output with colors
const contextOutput = contextHook(undefined, true, useIndexView);
console.log(contextOutput);
@@ -436,4 +430,4 @@ if (stdin.isTTY) {
console.log(JSON.stringify(result));
process.exit(0);
});
}
}
-10
View File
@@ -1,10 +0,0 @@
/**
* Test hook to verify if stderr messages appear in Claude Code UI
* This hook simply outputs a message via console.error()
*/
// Output a test message to stderr
console.error('🧪 TEST: This is a stderr message from the claude-mem hook');
// Exit successfully
process.exit(0);
+26
View File
@@ -0,0 +1,26 @@
/**
* User Message Hook - SessionStart
* Displays context information to the user via stderr
*
* This hook runs in parallel with context-hook to show users what context
* has been loaded into their session. Uses stderr as the communication channel
* since it's currently the only way to display messages in Claude Code UI.
*/
import { execSync } from "child_process";
try {
const output = execSync("node ~/.claude/plugins/marketplaces/thedotmack/plugin/scripts/context-hook.js --colors", {
encoding: 'utf8'
});
console.error(
"\n\n📝 Claude-Mem Context Loaded\n" +
" ️ Note: This appears as stderr but is informational only\n\n" +
output
);
} catch (error) {
console.error(`❌ Failed to load context display: ${error}`);
}
process.exit(3);