flake-update-20260201
1package main
2
3import (
4 "fmt"
5 "os"
6 "os/exec"
7)
8
9// isSubagentSession checks if this is a subagent session
10func isSubagentSession() bool {
11 claudeProjectDir := os.Getenv("CLAUDE_PROJECT_DIR")
12 if len(claudeProjectDir) > 0 && (len(claudeProjectDir) < 2 || claudeProjectDir[len(claudeProjectDir)-2:] != "/.") {
13 return true
14 }
15 if os.Getenv("CLAUDE_AGENT_TYPE") != "" {
16 return true
17 }
18 return false
19}
20
21func main() {
22 // Check if this is a subagent session
23 if isSubagentSession() {
24 // Silent exit for subagent sessions
25 os.Exit(0)
26 }
27
28 // Ring terminal bell to notify user (works with kitty bell_on_tab)
29 fmt.Fprint(os.Stderr, "\a")
30
31 // Get session statistics
32 statsCmd := exec.Command("claude-hooks-session-stats")
33 statsCmd.Env = os.Environ()
34 statsOutput, err := statsCmd.Output()
35 if err != nil {
36 // Continue without stats if tool fails
37 fmt.Fprintf(os.Stderr, "[save-session] Warning: Could not get session stats: %v\n", err)
38 }
39
40 // Output directive for Claude to save the session
41 // This will be shown in the conversation
42 fmt.Println("")
43 fmt.Println("---")
44 fmt.Println("")
45 fmt.Println("# Automatic Session Summary")
46 fmt.Println("")
47 fmt.Println("**IMPORTANT**: Please create a session summary and save it to the history directory.")
48 fmt.Println("")
49
50 // Show statistics if available
51 if len(statsOutput) > 0 {
52 fmt.Print(string(statsOutput))
53 }
54
55 fmt.Println("## Instructions")
56 fmt.Println("")
57 fmt.Println("Create a brief summary (2-4 paragraphs) of this session documenting:")
58 fmt.Println("- Primary tasks accomplished")
59 fmt.Println("- Key decisions or solutions")
60 fmt.Println("- Files/systems modified")
61 fmt.Println("- Any remaining work or next steps")
62 fmt.Println("")
63 fmt.Println("Save the summary using the Write tool to:")
64 fmt.Println("`~/.config/claude/history/sessions/<YYYY-MM>/<YYYY-MM-DD>_<brief-slug>.md`")
65 fmt.Println("")
66 fmt.Println("Use the format: `YYYY-MM-DD_<2-4 word slug describing the session>.md`")
67 fmt.Println("")
68 fmt.Println("Example: `~/.config/claude/history/sessions/2025-12/2025-12-10_notification-filtering-arr-completion.md`")
69 fmt.Println("")
70
71 os.Exit(0)
72}