flake-update-20260505
 1#!/usr/bin/env bun
 2/**
 3 * SessionStart hook — initialise a Claude Code session.
 4 *
 5 * • Skips subagent sessions
 6 * • Debounces duplicate triggers (2 s)
 7 * • Sets terminal tab title
 8 * • Logs session start to unified AI storage
 9 */
10
11import {
12  isSubagent,
13  shouldDebounce,
14  setTerminalTitle,
15  sessionLogPath,
16  appendLog,
17  localTimestamp,
18  host,
19  now,
20} from "./lib.ts";
21
22function main() {
23  if (isSubagent()) {
24    process.stderr.write("🤖 Subagent session — skipping initialisation\n");
25    process.exit(0);
26  }
27
28  if (shouldDebounce("session-start")) {
29    process.stderr.write("⏱ Debouncing duplicate SessionStart\n");
30    process.exit(0);
31  }
32
33  const title = "Claude Ready";
34  setTerminalTitle(title);
35  process.stderr.write(`🚀 Session initialised: "${title}" on ${host()}\n`);
36
37  // Attempt to inject CORE skill loading instruction into conversation
38  process.stdout.write("Load CORE skill now: Read ~/.config/claude/skills/CORE/SKILL.md\n");
39
40  // Ring terminal bell
41  process.stderr.write("\x07");
42
43  // Append to unified session log (same format as pi ai-storage)
44  try {
45    const d = now();
46    const entry = `${localTimestamp(d)} - Session started (claude) on ${host()}\n`;
47    appendLog(sessionLogPath(d), entry);
48  } catch (err) {
49    process.stderr.write(`[initialize-session] Warning: ${err}\n`);
50  }
51
52  process.exit(0);
53}
54
55main();