#!/usr/bin/env python3 """ CC Session Saver Quickly save a session with memory updates and git commit """ import json import subprocess from datetime import datetime from pathlib import Path ZONE = Path(__file__).parent MEMORY_FILE = ZONE / "memory.json" SESSIONS_DIR = ZONE / "sessions" def save_session(project_name, what_we_did, whats_next): """Save current session""" # Load memory with open(MEMORY_FILE, 'r') as f: memory = json.load(f) # Update memory today = datetime.now().strftime('%Y-%m-%d') memory['last_session'] = today memory['sessions_count'] = memory.get('sessions_count', 0) + 1 memory['quick_context'] = f"Last session: {project_name}" memory['next_up'] = whats_next if isinstance(whats_next, list) else [whats_next] # Update project if exists if project_name in memory.get('project_notes', {}): memory['project_notes'][project_name]['last_updated'] = today # Save memory with open(MEMORY_FILE, 'w') as f: json.dump(memory, f, indent=2) # Create session log session_file = SESSIONS_DIR / f"{today}_{project_name.replace(' ', '-').lower()}.md" session_content = f"""# Session: {today} - {project_name} ## What We Built {what_we_did} ## What's Next {chr(10).join(f'- {item}' for item in (whats_next if isinstance(whats_next, list) else [whats_next]))} ## Notes Session saved automatically with save_session.py """ with open(session_file, 'w') as f: f.write(session_content) print(f"āœ… Session saved!") print(f"šŸ“ Memory updated: {MEMORY_FILE}") print(f"šŸ“„ Session log: {session_file}") # Git commit option print("\nšŸ”„ Commit to git? (y/n): ", end='') if input().lower() == 'y': subprocess.run(['git', 'add', '.'], cwd=ZONE) commit_msg = f"Session: {project_name} ({today})\n\n{what_we_did}\n\nšŸ¤– Generated with Claude Code\n\nCo-Authored-By: Claude " subprocess.run(['git', 'commit', '-m', commit_msg], cwd=ZONE) print("āœ… Committed to git!") if __name__ == "__main__": import sys if len(sys.argv) < 4: print("Usage: python save_session.py ") print("\nExample:") print(' python save_session.py "Nova" "Built genetics system" "Build fitness function"') sys.exit(1) project = sys.argv[1] what_we_did = sys.argv[2] whats_next = sys.argv[3] save_session(project, what_we_did, whats_next)