-
Notifications
You must be signed in to change notification settings - Fork 526
Expand file tree
/
Copy pathauto-checkpoint.sh
More file actions
executable file
·38 lines (30 loc) · 1.11 KB
/
auto-checkpoint.sh
File metadata and controls
executable file
·38 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# .claude/hooks/auto-checkpoint.sh
# Event: Stop
# Auto-creates git stash checkpoint when Claude Code session ends
# Inspired by checkpoint pattern for safe experimentation
set -euo pipefail
INPUT=$(cat)
# Extract session metadata
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // "unknown"')
TIMESTAMP=$(date +"%Y%m%d-%H%M%S")
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
# Check if there are uncommitted changes
if ! git diff-index --quiet HEAD -- 2>/dev/null; then
# Create descriptive stash name
STASH_NAME="claude-checkpoint-${BRANCH}-${TIMESTAMP}"
# Stash with descriptive message
git stash push -u -m "$STASH_NAME" >/dev/null 2>&1
# Log checkpoint creation
LOG_DIR="$HOME/.claude/logs"
mkdir -p "$LOG_DIR"
echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] Created checkpoint: $STASH_NAME (session: $SESSION_ID)" \
>> "$LOG_DIR/checkpoints.log"
# Notify user
cat << EOF
{
"systemMessage": "✓ Checkpoint created: $STASH_NAME\n\nRestore with:\n git stash list # find the checkpoint\n git stash apply stash@{N} # restore it"
}
EOF
fi
exit 0