Claude accounts: switch a chat refused for usage to another saved account and continue it
When Claude Code refuses an operator chat's turn for a usage limit, the server marks the refused account until its reset and, if the chat's Claude home allows it (claude_account_auto_switch / `pipelines claude-account auto on|off`, on by default, kept in pipelines-accounts/settings.json), switches the home to the saved account with the most usage left through the claude_account_use path. Switches of one home are serialized, so chats refused together switch once. Each refused chat gets one queued prompt, marked as sent automatically, that asks the agent to check it is on track before continuing; the app's auto-continue-at-reset prompt for the refusal is removed (and refused if it arrives later), and the operator gets a low-priority notification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+22
@@ -79,6 +79,9 @@ def user_message(text):
|
||||
if "background" in text:
|
||||
background(message_id)
|
||||
return
|
||||
if "usage-limit" in text:
|
||||
refused(message_id)
|
||||
return
|
||||
if "notify" in text:
|
||||
send({"type": "system", "subtype": "task_notification", "task_id": "b1",
|
||||
"tool_use_id": "toolu_bg_fake", "status": "completed", "summary": "Background command completed (exit code 0)"})
|
||||
@@ -175,6 +178,25 @@ def background(message_id):
|
||||
finish(message_id)
|
||||
|
||||
|
||||
def refused(message_id):
|
||||
"""A turn refused for a usage limit, as Claude Code 2.1 ends one: a rejected
|
||||
rate_limit_event, a synthetic assistant API-error message and an is_error
|
||||
result repeating its text."""
|
||||
text = "You've hit your 5-hour limit · resets 5:20pm (Europe/London) · out of usage credits"
|
||||
send({"type": "rate_limit_event", "uuid": "rate-%d" % state["turn"], "session_id": state["session"],
|
||||
"rate_limit_info": {"status": "rejected", "resetsAt": 1900000000, "rateLimitType": "five_hour",
|
||||
"isUsingOverage": False, "overageStatus": "rejected",
|
||||
"overageDisabledReason": "out_of_credits"}})
|
||||
refusal_id = "refusal-%d" % state["turn"]
|
||||
message = {"id": refusal_id, "role": "assistant", "model": "<synthetic>",
|
||||
"content": [{"type": "text", "text": text}]}
|
||||
append({"type": "assistant", "uuid": refusal_id, "timestamp": stamp(), "error": "rate_limit",
|
||||
"isApiErrorMessage": True, "message": message})
|
||||
send({"type": "assistant", "uuid": refusal_id, "error": "rate_limit", "message": message})
|
||||
send({"type": "result", "subtype": "success", "is_error": True, "result": text,
|
||||
"session_id": state["session"]})
|
||||
|
||||
|
||||
def finish(message_id):
|
||||
# Shape of SDKRateLimitEvent in Claude Code 2.1.316 (synthetic numbers).
|
||||
if os.environ.get("FAKE_CLAUDE_RATE_LIMIT"):
|
||||
|
||||
Reference in New Issue
Block a user