fedora-csb-system-manager
 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	// Send desktop notification
29	cmd := exec.Command("notify-send", "-u", "low", "Claude Code", "Session ending")
30	if err := cmd.Run(); err != nil {
31		// Silent failure - don't break workflow
32		fmt.Fprintf(os.Stderr, "[save-session] Warning: Could not send notification: %v\n", err)
33	}
34
35	// Get session statistics
36	statsCmd := exec.Command("claude-hooks-session-stats")
37	statsCmd.Env = os.Environ()
38	statsOutput, err := statsCmd.Output()
39	if err != nil {
40		// Continue without stats if tool fails
41		fmt.Fprintf(os.Stderr, "[save-session] Warning: Could not get session stats: %v\n", err)
42	}
43
44	// Output directive for Claude to save the session
45	// This will be shown in the conversation
46	fmt.Println("")
47	fmt.Println("---")
48	fmt.Println("")
49	fmt.Println("# Automatic Session Summary")
50	fmt.Println("")
51	fmt.Println("**IMPORTANT**: Please create a session summary and save it to the history directory.")
52	fmt.Println("")
53
54	// Show statistics if available
55	if len(statsOutput) > 0 {
56		fmt.Print(string(statsOutput))
57	}
58
59	fmt.Println("## Instructions")
60	fmt.Println("")
61	fmt.Println("Create a brief summary (2-4 paragraphs) of this session documenting:")
62	fmt.Println("- Primary tasks accomplished")
63	fmt.Println("- Key decisions or solutions")
64	fmt.Println("- Files/systems modified")
65	fmt.Println("- Any remaining work or next steps")
66	fmt.Println("")
67	fmt.Println("Save the summary using the Write tool to:")
68	fmt.Println("`~/.config/claude/history/sessions/<YYYY-MM>/<YYYY-MM-DD>_<brief-slug>.md`")
69	fmt.Println("")
70	fmt.Println("Use the format: `YYYY-MM-DD_<2-4 word slug describing the session>.md`")
71	fmt.Println("")
72	fmt.Println("Example: `~/.config/claude/history/sessions/2025-12/2025-12-10_notification-filtering-arr-completion.md`")
73	fmt.Println("")
74
75	os.Exit(0)
76}