633b5953bb
When Claude Code refuses an operator chat's turn for a usage limit and the server does not continue it on another account, the server now queues a durable prompt (auto-continue-<refusal id>, sent as Pipelines (automatic)) for a minute after the reset: the refused operator message when the turn did no work, else "continue". The reset comes from the refusal's text, else the rejected rate_limit_event. Refusals of turns Claude Code started itself are handled too, with no client attached; a restarted server or a device scheduling the same refusal adds nothing. The choice is kept per Claude home beside auto-switch (or by the server for chats without one), read and set with chat_auto_continue, on by default. The app's limit banner now finds the refusal as the latest turn, ignoring notices, agent reports and activity rows after it, reads and writes the server's choice, and only schedules its own prompt for older servers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
4.1 KiB
Go
92 lines
4.1 KiB
Go
package protocol
|
|
|
|
// Claude account switching for a chat whose directory selects its own Claude
|
|
// Code home (CLAUDE_CONFIG_DIR, for example from a direnv .envrc). Each request
|
|
// body is ClaudeAccountRequest naming the chat; the server resolves the chat's
|
|
// directory environment to that config directory and replies with
|
|
// ClaudeAccountList. Saved accounts live in <config dir>/pipelines-accounts/.
|
|
// Using one changes the same files `/login` changes, in place, so running
|
|
// Claude Code processes continue on the new account without a restart. No
|
|
// reply or log ever carries a token.
|
|
const (
|
|
// ClaudeAccounts lists the saved accounts and the active login.
|
|
ClaudeAccounts = "claude_accounts"
|
|
// ClaudeAccountSave snapshots the active login as a saved account; Name
|
|
// defaults to its email.
|
|
ClaudeAccountSave = "claude_account_save"
|
|
// ClaudeAccountUse makes the saved account Name the active login, first
|
|
// writing the current login's refreshed tokens back to its own slot.
|
|
ClaudeAccountUse = "claude_account_use"
|
|
// ClaudeAccountRemove deletes the saved account Name. The active login is
|
|
// unchanged.
|
|
ClaudeAccountRemove = "claude_account_remove"
|
|
// ClaudeAccountAutoSwitch sets whether a chat on this Claude home that
|
|
// runs out of usage is switched to another saved account with usage left
|
|
// and continued automatically (AutoSwitch; on by default).
|
|
ClaudeAccountAutoSwitch = "claude_account_auto_switch"
|
|
)
|
|
|
|
// ClaudeAccountRequest is the body of every claude_account* request.
|
|
type ClaudeAccountRequest struct {
|
|
SessionID string `json:"session_id"`
|
|
// Name is the saved account (its name, slug or email); for a save, the
|
|
// name to save under ("" uses the email).
|
|
Name string `json:"name,omitempty"`
|
|
// AutoSwitch is the new automatic-switch choice of a
|
|
// claude_account_auto_switch request.
|
|
AutoSwitch *bool `json:"auto_switch,omitempty"`
|
|
}
|
|
|
|
// ClaudeAccount describes one Claude login without its credentials.
|
|
type ClaudeAccount struct {
|
|
Name string `json:"name"`
|
|
Email string `json:"email,omitempty"`
|
|
Organization string `json:"organization,omitempty"`
|
|
// Plan is the subscription type the login reports ("max", "pro").
|
|
Plan string `json:"plan,omitempty"`
|
|
// Active is set on the account the config directory is signed in with.
|
|
Active bool `json:"active,omitempty"`
|
|
// Saved is false for an active login that has no saved slot yet.
|
|
Saved bool `json:"saved"`
|
|
}
|
|
|
|
// ClaudeAccountList is the reply to every claude_account* request.
|
|
type ClaudeAccountList struct {
|
|
// ConfigDir is the Claude Code home the chat's directory selects.
|
|
ConfigDir string `json:"config_dir"`
|
|
// Active is the current login (saved or not); nil when signed out.
|
|
Active *ClaudeAccount `json:"active,omitempty"`
|
|
// Accounts are the saved accounts, sorted by name.
|
|
Accounts []ClaudeAccount `json:"accounts"`
|
|
// Usage is the newly active account's latest known quota after a
|
|
// claude_account_use (see ChatAccountUsage.SwitchedAt).
|
|
Usage *ChatAccountUsage `json:"usage,omitempty"`
|
|
// AutoSwitch reports whether running out of usage switches the Claude
|
|
// home to another saved account and continues the chat automatically.
|
|
AutoSwitch bool `json:"auto_switch"`
|
|
}
|
|
|
|
// ChatAutoContinueType reads (AutoContinue nil) or sets the "Auto-continue
|
|
// when limits reset" choice that applies to a chat: when a usage limit
|
|
// refuses one of its turns, the server queues a prompt to send a minute after
|
|
// the reset. The choice is kept per Claude home (beside auto_switch) for a
|
|
// chat whose directory selects one, else by the server for every other chat;
|
|
// it is on by default. The reply carries the current choice.
|
|
const ChatAutoContinueType = "chat_auto_continue"
|
|
|
|
// Scopes of a ChatAutoContinue reply.
|
|
const (
|
|
ChatAutoContinueClaudeHome = "claude_home"
|
|
ChatAutoContinueServer = "server"
|
|
)
|
|
|
|
// ChatAutoContinue is the chat_auto_continue body and reply.
|
|
type ChatAutoContinue struct {
|
|
SessionID string `json:"session_id"`
|
|
// AutoContinue is the new choice of a request (nil reads it) and the
|
|
// current choice in the reply.
|
|
AutoContinue *bool `json:"auto_continue,omitempty"`
|
|
// Scope says where the choice is kept: claude_home or server (reply).
|
|
Scope string `json:"scope,omitempty"`
|
|
}
|