Claude Code Outage Recovery

3 hooks that saved my work during the April 6-8 incidents

The problem: Claude Code sessions can die mid-task — from outages, rate limits, or network issues. Uncommitted changes are lost. Auto-compact fires at the worst time and erases context.

Hook 1: Pre-compact checkpoint

Auto-saves all uncommitted changes before /compact runs. During the April 7 outage, this hook had saved 3 checkpoints before the session died.

npx cc-safe-setup --install-example pre-compact-checkpoint
#!/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."

Hook 2: Session state backup

Logs the HEAD commit at session start. When a session dies, you know exactly where to resume.

npx cc-safe-setup --install-example session-backup-on-start
#!/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)"

Hook 3: Periodic auto-commit

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

Quick setup

npx cc-safe-setup

The interactive wizard installs all safety hooks based on your risk profile. 655+ hooks available.

Want to cut token waste too?

The same 800 hours of operation data revealed how to cut token consumption by 40%.

Free Token Checkup | Find hooks for your setup