feat: automatischer Konto-Wechsel (pyramid<->haupt) bei 5h-Limit

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CPrAGBxBT6GfPXzeWQ4AXb
This commit is contained in:
Bernd Steckmeister
2026-07-03 19:33:13 +02:00
parent 87ff15d760
commit bfe58760ee
+44 -5
View File
@@ -9,9 +9,30 @@
cd "$(dirname "$0")" cd "$(dirname "$0")"
export PATH="$HOME/.local/bin:$HOME/flutter/bin:$PATH" export PATH="$HOME/.local/bin:$HOME/flutter/bin:$PATH"
# Pyramid laeuft auf eigenem Claude-Konto (Profil ~/.claude-pyramid), # --- Zwei Claude-Konten mit automatischem Wechsel bei 5h-Limit ---
# das Standard-Profil ~/.claude bleibt fuer die Webseiten-Arbeit. # Konto "pyramid" = Profil ~/.claude-pyramid (Standard fuer diese Arbeit),
export CLAUDE_CONFIG_DIR="$HOME/.claude-pyramid" # Konto "haupt" = Profil ~/.claude (springt ein, wenn pyramid am Limit ist).
ACCOUNT_FILE="$HOME/.claude-accounts/active"
get_account() { cat "$ACCOUNT_FILE" 2>/dev/null || echo pyramid; }
apply_account() {
if [ "$(get_account)" = "haupt" ]; then
export CLAUDE_CONFIG_DIR="$HOME/.claude"
else
export CLAUDE_CONFIG_DIR="$HOME/.claude-pyramid"
fi
}
switch_account() {
local cur next
cur=$(get_account)
if [ "$cur" = "pyramid" ]; then next=haupt; else next=pyramid; fi
mkdir -p "$HOME/.claude-accounts"
echo "$next" > "$ACCOUNT_FILE"
notify_matrix "🔺 Autopilot: 5h-Limit auf Konto '$cur' erreicht wechsle auf Konto '$next' und arbeite direkt weiter."
}
JUST_SWITCHED=0
# --- Matrix-Statusberichte (Raum "🔺 Pyramid Autopilot", Token vom Gatus-Bot) --- # --- Matrix-Statusberichte (Raum "🔺 Pyramid Autopilot", Token vom Gatus-Bot) ---
MATRIX_URL="http://127.0.0.1:6167" MATRIX_URL="http://127.0.0.1:6167"
@@ -36,9 +57,11 @@ while true; do
sleep 600 sleep 600
continue continue
fi fi
echo "===== $(date '+%F %T') Neue Claude-Session =====" | tee -a autopilot.log apply_account
echo "===== $(date '+%F %T') Neue Claude-Session (Konto $(get_account)) =====" | tee -a autopilot.log
BEFORE=$(git rev-parse HEAD 2>/dev/null) BEFORE=$(git rev-parse HEAD 2>/dev/null)
claude -p "$PROMPT" --model claude-fable-5 --dangerously-skip-permissions 2>&1 | tee -a autopilot.log SESSION_OUT=$(mktemp)
claude -p "$PROMPT" --model claude-fable-5 --dangerously-skip-permissions 2>&1 | tee -a autopilot.log "$SESSION_OUT"
AFTER=$(git rev-parse HEAD 2>/dev/null) AFTER=$(git rev-parse HEAD 2>/dev/null)
if [ -n "$BEFORE" ] && [ "$BEFORE" != "$AFTER" ]; then if [ -n "$BEFORE" ] && [ "$BEFORE" != "$AFTER" ]; then
COMMITS=$(git log --oneline --no-decorate "$BEFORE..$AFTER" | head -15) COMMITS=$(git log --oneline --no-decorate "$BEFORE..$AFTER" | head -15)
@@ -50,6 +73,22 @@ $COMMITS
$NEXT" $NEXT"
fi fi
# 5h-Limit erkannt? -> sofort aufs andere Konto wechseln statt zu warten
if grep -qiE "hit your.*limit|usage limit|session limit" "$SESSION_OUT"; then
rm -f "$SESSION_OUT"
if [ "$JUST_SWITCHED" != "1" ]; then
switch_account
JUST_SWITCHED=1
continue
fi
JUST_SWITCHED=0
echo "===== $(date '+%F %T') Beide Konten am Limit - naechster Versuch in 20 Minuten =====" | tee -a autopilot.log
sleep 1200
continue
fi
rm -f "$SESSION_OUT"
JUST_SWITCHED=0
echo "===== $(date '+%F %T') Session beendet - Neustart in 20 Minuten (Strg+C zum Stoppen) =====" | tee -a autopilot.log echo "===== $(date '+%F %T') Session beendet - Neustart in 20 Minuten (Strg+C zum Stoppen) =====" | tee -a autopilot.log
sleep 1200 sleep 1200
done done