3 hooks that saved my work during the April 6-8 incidents
Auto-saves all uncommitted changes before /compact runs. During the April 7 outage, this hook had saved 3 checkpoints before the session died.
#!/bin/bash
# PreCompact hook — auto-commit before context compression
cd "$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0
if [ -n "$(git status --porcelain)" ]; then
git add -A
git commit -m "checkpoint: pre-compact $(date +%Y%m%d-%H%M%S)" --no-verify 2>/dev/null
echo "Checkpoint saved."
fi
echo "Context compressed. Wait for instructions before resuming."
Logs the HEAD commit at session start. When a session dies, you know exactly where to resume.
#!/bin/bash
# SessionStart hook — log recovery point
echo "$(date +%Y-%m-%dT%H:%M:%S) $(git rev-parse HEAD 2>/dev/null)" \
>> /tmp/cc-sessions.log
echo "Recovery point: $(git rev-parse --short HEAD 2>/dev/null)"
Creates a checkpoint every 50 tool calls. Insurance against unexpected disconnections during long autonomous sessions.
#!/bin/bash
# PostToolUse hook — auto-commit every 50 operations
counter="/tmp/cc-autocommit-$$"
count=0
[ -f "$counter" ] && count=$(cat "$counter")
count=$((count + 1))
echo "$count" > "$counter"
if [ $((count % 50)) -eq 0 ]; then
cd "$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0
if [ -n "$(git status --porcelain)" ]; then
git add -A
git commit -m "auto: checkpoint at $count tool calls" --no-verify 2>/dev/null
fi
fi
The interactive wizard installs all safety hooks based on your risk profile. 892 example hooks available.
Want to cut token waste too?
The same 800 hours of operation data revealed how to cut token consumption by 40%.