Documentation
¶
Overview ¶
Package switcher swaps which account Claude Code is logged in as.
ccswap owns only the claudeAiOauth key of Claude Code's entry. Vault invariant: nothing refreshes a vault copy of the chain in Claude Code's entry; such a copy is parked after a switch until the daemon sees the switch settled and drops it.
Index ¶
- Variables
- type Deps
- type Profiler
- type Switcher
- func (s *Switcher) Adopt(ctx context.Context, name string, priority int) error
- func (s *Switcher) ForgetLocked(name string)
- func (s *Switcher) Freeze(names []string, until time.Time)
- func (s *Switcher) Frozen(name string) bool
- func (s *Switcher) Identify(ctx context.Context) (string, bool, claudecode.Credentials, error)
- func (s *Switcher) LastWrite() time.Time
- func (s *Switcher) Locked(fn func() error) error
- func (s *Switcher) Switch(ctx context.Context, to string, force bool) (warning error, err error)
- func (s *Switcher) SwitchFrom(ctx context.Context, from, to string) (warning error, err error)
- func (s *Switcher) Thaw(names []string)
Constants ¶
This section is empty.
Variables ¶
var ( ErrNearRefresh = errors.New("access token is about to be refreshed by Claude Code") // ErrTargetRefreshing: the target's vault copy has no access token yet; the daemon is refreshing it. ErrTargetRefreshing = errors.New("the target login is still being refreshed") ErrUnknownActive = errors.New("the current Claude Code login is not a known account") ErrNeedsLogin = errors.New("account needs a fresh login") ErrNoSuchAccount = errors.New("no such account") ErrCannotIdentify = errors.New("cannot identify the current Claude Code login") ErrHolderChanged = errors.New("the Claude Code login changed since the decision") // ErrEntryChanged: Claude Code kept rewriting its login while the switch was ready to write. ErrEntryChanged = errors.New("the Claude Code login kept changing during the switch") // ErrEntryExpired: Claude Code has not run for a while, so its access token expired and the // profile cannot name the login. It is an ErrCannotIdentify. ErrEntryExpired = fmt.Errorf("%w: Claude Code's access token has expired", ErrCannotIdentify) // ErrFrozen: a migrate export holds the account, so no switch may reach it. ErrFrozen = errors.New("the account is being moved to another machine") )
Functions ¶
This section is empty.
Types ¶
type Switcher ¶
type Switcher struct {
// contains filtered or unexported fields
}
func (*Switcher) Adopt ¶
Adopt registers the login currently in Claude Code's entry as account name and marks it active. It writes metadata only: the active account has no vault item.
func (*Switcher) ForgetLocked ¶
ForgetLocked drops the fingerprint when it names name (the account is being removed). The caller holds Locked.
func (*Switcher) Identify ¶
func (s *Switcher) Identify(ctx context.Context) (string, bool, claudecode.Credentials, error)
Identify names the account whose login is in Claude Code's entry, and returns the entry as it read it.
func (*Switcher) LastWrite ¶
LastWrite is when ccswap last wrote Claude Code's entry (zero: not since start).
func (*Switcher) Locked ¶
Locked runs fn under the switcher's mutex; every vault refresh must go through it.
func (*Switcher) Switch ¶
Switch puts to's login in Claude Code's entry. A switch that landed but left something undone returns a warning: an *i18n.Error, or several of them joined (errors.Join).
func (*Switcher) SwitchFrom ¶
SwitchFrom is Switch(to, false) that writes nothing (ErrHolderChanged) unless Claude Code's entry still holds from: an automatic decision made for from is void once someone else switched.