#!/bin/bash # Standard checkpoint hook functions for Claude settings.json (without GitHub features) # Function to handle pre-edit checkpoints pre_edit_checkpoint() { local tool_input="$1" local file=$(echo "$tool_input" | jq -r '.file_path // empty') if [ -n "$file" ]; then local checkpoint_branch="checkpoint/pre-edit-$(date +%Y%m%d-%H%M%S)" local current_branch=$(git branch --show-current) # Create checkpoint git add -A git stash push -m "Pre-edit checkpoint for $file" >/dev/null 2>&1 git branch "$checkpoint_branch" # Store metadata mkdir -p .claude/checkpoints cat > ".claude/checkpoints/$(date +%s).json" </dev/null 2>&1 || true echo "✅ Created checkpoint: $checkpoint_branch for $file" fi } # Function to handle post-edit checkpoints post_edit_checkpoint() { local tool_input="$1" local file=$(echo "$tool_input" | jq -r '.file_path // empty') if [ -n "$file" ] && [ -f "$file" ]; then # Check if file was modified - first check if file is tracked if ! git ls-files --error-unmatch "$file" >/dev/null 2>&1; then # File is not tracked, add it first git add "$file" fi # Now check if there are changes if git diff --cached --quiet "$file" 2>/dev/null && git diff --quiet "$file" 2>/dev/null; then echo "â„šī¸ No changes to checkpoint for $file" else local tag_name="checkpoint-$(date +%Y%m%d-%H%M%S)" local current_branch=$(git branch --show-current) # Create commit git add "$file" if git commit -m "🔖 Checkpoint: Edit $file Automatic checkpoint created by Claude - File: $file - Branch: $current_branch - Timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ) [Auto-checkpoint]" --quiet; then # Create tag only if commit succeeded git tag -a "$tag_name" -m "Checkpoint after editing $file" # Store metadata mkdir -p .claude/checkpoints local diff_stats=$(git diff HEAD~1 --stat | tr '\n' ' ' | sed 's/"/\"/g') cat > ".claude/checkpoints/$(date +%s).json" < ".claude/checkpoints/task-$(date +%s).json" < "$summary_file" </dev/null) 2>/dev/null || echo "No files tracked") ## Recent Commits $(git log --oneline -10 --grep="Checkpoint" || echo "No checkpoint commits") ## Rollback Instructions To rollback to a specific checkpoint: \`\`\`bash # List all checkpoints git tag -l 'checkpoint-*' | sort -r # Rollback to a checkpoint git checkout checkpoint-YYYYMMDD-HHMMSS # Or reset to a checkpoint (destructive) git reset --hard checkpoint-YYYYMMDD-HHMMSS \`\`\` EOF # Create final checkpoint git add -A git commit -m "🏁 Session end checkpoint: $session_id" --quiet || true git tag -a "session-end-$session_id" -m "End of Claude session" echo "✅ Session summary saved to: $summary_file" echo "📌 Final checkpoint: session-end-$session_id" } # Main entry point case "$1" in pre-edit) pre_edit_checkpoint "$2" ;; post-edit) post_edit_checkpoint "$2" ;; task) task_checkpoint "$2" ;; session-end) session_end_checkpoint ;; *) echo "Usage: $0 {pre-edit|post-edit|task|session-end} [input]" exit 1 ;; esac