#!/bin/bash # Daily maintenance script for Claude Code configuration # Runs via systemd timer or manually set -euo pipefail CLAUDE_DIR="${HOME}/.claude" LOG_DIR="${CLAUDE_DIR}/logs" LOG_FILE="${LOG_DIR}/maintenance-$(date +%Y-%m-%d).log" mkdir -p "${LOG_DIR}" log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "${LOG_FILE}" } log "=== Daily Maintenance Started ===" # 1. Validate configuration log "Running validation..." if "${CLAUDE_DIR}/automation/validate-setup.sh" >> "${LOG_FILE}" 2>&1; then log "✓ Validation passed" else log "⚠ Validation had warnings" fi # 2. Clean old files log "Running cleanup..." "${CLAUDE_DIR}/automation/clean.sh" >> "${LOG_FILE}" 2>&1 || true log "✓ Cleanup complete" # 3. Create daily backup log "Creating backup..." if "${CLAUDE_DIR}/automation/backup.sh" >> "${LOG_FILE}" 2>&1; then log "✓ Backup created" else log "⚠ Backup failed" fi # 4. Check for unsummarized sessions log "Checking session history..." unsummarized=$(python3 -c " import json from pathlib import Path idx = Path.home() / '.claude/state/personal-assistant/history/index.json' if idx.exists(): data = json.load(open(idx)) count = sum(1 for s in data.get('sessions', []) if not s.get('summarized', False)) print(count) else: print(0) " 2>/dev/null || echo "0") if [[ "${unsummarized}" -gt 0 ]]; then log "⚠ ${unsummarized} unsummarized session(s) pending" else log "✓ All sessions summarized" fi # 5. Rotate old maintenance logs log "Rotating old logs..." find "${LOG_DIR}" -name "maintenance-*.log" -mtime +30 -delete 2>/dev/null || true log "✓ Log rotation complete" log "=== Daily Maintenance Complete ==="