From bfe58760eeac1cd3b14612f5baf321b59e7df138 Mon Sep 17 00:00:00 2001 From: Bernd Steckmeister Date: Fri, 3 Jul 2026 19:33:13 +0200 Subject: [PATCH] feat: automatischer Konto-Wechsel (pyramid<->haupt) bei 5h-Limit Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01CPrAGBxBT6GfPXzeWQ4AXb --- autopilot.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/autopilot.sh b/autopilot.sh index 52573b3..18ad11c 100755 --- a/autopilot.sh +++ b/autopilot.sh @@ -9,9 +9,30 @@ cd "$(dirname "$0")" export PATH="$HOME/.local/bin:$HOME/flutter/bin:$PATH" -# Pyramid laeuft auf eigenem Claude-Konto (Profil ~/.claude-pyramid), -# das Standard-Profil ~/.claude bleibt fuer die Webseiten-Arbeit. -export CLAUDE_CONFIG_DIR="$HOME/.claude-pyramid" +# --- Zwei Claude-Konten mit automatischem Wechsel bei 5h-Limit --- +# Konto "pyramid" = Profil ~/.claude-pyramid (Standard fuer diese Arbeit), +# 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_URL="http://127.0.0.1:6167" @@ -36,9 +57,11 @@ while true; do sleep 600 continue 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) - 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) if [ -n "$BEFORE" ] && [ "$BEFORE" != "$AFTER" ]; then COMMITS=$(git log --oneline --no-decorate "$BEFORE..$AFTER" | head -15) @@ -50,6 +73,22 @@ $COMMITS $NEXT" 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 sleep 1200 done