#!/bin/bash # Stop Hook (Session End) - Persist learnings when session ends # # Runs when Claude session ends. Creates/updates session log file # with timestamp for continuity tracking. # # Configured in .cursor/hooks.json: # sessionEnd -> node .cursor/scripts/hooks/session-end.js # This shell version is a fallback for environments without Node. ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" SESSIONS_DIR="${ROOT}/.cursor/sessions" TODAY=$(date '+%Y-%m-%d') SESSION_FILE="${SESSIONS_DIR}/${TODAY}-session.tmp" mkdir -p "$SESSIONS_DIR" # If session file exists for today, update the end time if [ -f "$SESSION_FILE" ]; then # Update Last Updated timestamp sed -i '' "s/\*\*Last Updated:\*\*.*/\*\*Last Updated:\*\* $(date '+%H:%M')/" "$SESSION_FILE" 2>/dev/null || \ sed -i "s/\*\*Last Updated:\*\*.*/\*\*Last Updated:\*\* $(date '+%H:%M')/" "$SESSION_FILE" 2>/dev/null echo "[SessionEnd] Updated session file: $SESSION_FILE" >&2 else # Create new session file with template cat > "$SESSION_FILE" << EOF # Session: $(date '+%Y-%m-%d') **Date:** $TODAY **Started:** $(date '+%H:%M') **Last Updated:** $(date '+%H:%M') --- ## Current State [Session context goes here] ### Completed - [ ] ### In Progress - [ ] ### Notes for Next Session - ### Context to Load \`\`\` [relevant files] \`\`\` EOF echo "[SessionEnd] Created session file: $SESSION_FILE" >&2 fi