keep-auth-alive.sh (802B)
1 #!/usr/bin/env bash 2 # Keep OAuth token fresh by running a trivial claude command every 5 minutes. 3 # Run this in the background before starting a sweep: 4 # bash harness/lib/keep-auth-alive.sh & 5 # KEEP_AUTH_PID=$! 6 # python3 harness/run.py grid.yaml main_effects -j 2 7 # kill $KEEP_AUTH_PID 8 9 INTERVAL=${1:-300} # seconds, default 5 minutes 10 11 echo "[keep-auth] Starting token refresh loop (every ${INTERVAL}s)" 12 echo "[keep-auth] PID: $$" 13 14 while true; do 15 sleep "$INTERVAL" 16 # Run a trivial non-bare command so claude refreshes the OAuth token 17 claude -p "reply with ok" --max-turns 1 --output-format json > /dev/null 2>&1 18 if [ $? -eq 0 ]; then 19 echo "[keep-auth] Token refreshed at $(date -u +%H:%M:%S)" 20 else 21 echo "[keep-auth] WARNING: refresh failed at $(date -u +%H:%M:%S)" 22 fi 23 done