fix(sessions): make session hooks actually persist and load context (#187)

session-end.js: Extract meaningful summaries from CLAUDE_TRANSCRIPT_PATH
instead of writing blank template files. Pulls user messages, tools used,
and files modified from the session transcript JSONL.

session-start.js: Output the latest session summary to stdout (via the
output() helper) so it gets injected into Claude's conversation context,
instead of only logging to stderr which just shows briefly in the terminal.
This commit is contained in:
Affaan Mustafa
2026-02-11 23:56:41 -08:00
parent 5febfc84f5
commit 87d19f97a6
2 changed files with 132 additions and 29 deletions

View File

@@ -4,16 +4,20 @@
*
* Cross-platform (Windows, macOS, Linux)
*
* Runs when a new Claude session starts. Checks for recent session
* files and notifies Claude of available context to load.
* Runs when a new Claude session starts. Loads the most recent session
* summary into Claude's context via stdout, and reports available
* sessions and learned skills.
*/
const fs = require('fs');
const {
getSessionsDir,
getLearnedSkillsDir,
findFiles,
ensureDir,
log
readFile,
log,
output
} = require('../lib/utils');
const { getPackageManager, getSelectionPrompt } = require('../lib/package-manager');
const { listAliases } = require('../lib/session-aliases');
@@ -27,13 +31,19 @@ async function main() {
ensureDir(learnedDir);
// Check for recent session files (last 7 days)
// Match both old format (YYYY-MM-DD-session.tmp) and new format (YYYY-MM-DD-shortid-session.tmp)
const recentSessions = findFiles(sessionsDir, '*-session.tmp', { maxAge: 7 });
if (recentSessions.length > 0) {
const latest = recentSessions[0];
log(`[SessionStart] Found ${recentSessions.length} recent session(s)`);
log(`[SessionStart] Latest: ${latest.path}`);
// Read and inject the latest session content into Claude's context
const content = readFile(latest.path);
if (content && !content.includes('[Session context goes here]')) {
// Only inject if the session has actual content (not the blank template)
output(`Previous session summary:\n${content}`);
}
}
// Check for learned skills