Documentation
¶
Overview ¶
Package claudeprofile keeps more than one Claude Code account on one machine. A profile is a config directory of its own (CLAUDE_CONFIG_DIR) holding its own `claude auth login`, so every account runs with its full login rather than an inference-only token. The default profile, Personal, is whatever Claude Code reads without lich's help: CLAUDE_CONFIG_DIR from lich's environment, else ~/.claude.
A profile directory is never moved once it exists. On macOS Claude Code files the login in the Keychain under a service named after a hash of the directory string (internal/quota/claude_storage.go), so Dir must return the same bytes for a slug on every call, and renaming a profile changes its display name only.
Index ¶
- Constants
- Variables
- func ConfigDir(slug string) (string, error)
- func Delete(slug string) error
- func Dir(slug string) (string, error)
- func EnsureShared(slug string) error
- func Env(base []string, dir string) []string
- func InheritTrust(dir, top, origin string) error
- func IsPersonal(slug string) bool
- func MoveConversation(conversationID, toSlug string) error
- func PersonalDir() (string, error)
- func PluginStore(dir string) string
- func PluginsDir(slug, dir string) string
- func Root() (string, error)
- type BinResolver
- type Info
- type LoginEvent
- type Plugin
- type PluginResult
- type Profile
- type Service
- func (s *Service) CancelLogin(_ context.Context, opts api.ProfileSlugOptions) (api.None, error)
- func (s *Service) CreateProfile(_ context.Context, opts api.CreateProfileOptions) (Profile, error)
- func (s *Service) DeleteProfile(ctx context.Context, opts api.ProfileSlugOptions) (api.None, error)
- func (s *Service) InstallPlugins(_ context.Context, opts api.InstallPluginsOptions) ([]PluginResult, error)
- func (s *Service) Login(_ context.Context, opts api.ProfileSlugOptions) (api.None, error)
- func (s *Service) LoginCode(_ context.Context, opts api.LoginCodeOptions) (api.None, error)
- func (s *Service) LoginCommand(_ context.Context, opts api.ProfileSlugOptions) (string, error)
- func (s *Service) Plugins(_ context.Context, opts api.ProfileSlugOptions) ([]Plugin, error)
- func (s *Service) Profiles(_ context.Context, _ api.None) ([]Info, error)
- func (s *Service) SetLichPlugin(install func(slug string) error, key string)
- func (s *Service) SetSessions(inUse func(slug string) int, forget func(slug string) error)
- func (s *Service) UpdateProfile(_ context.Context, opts api.UpdateProfileOptions) (Profile, error)
Constants ¶
const Personal = profilestore.Personal
Personal is the slug of the default profile. It is reserved: no profile lich creates can take it, which is what lets a project setting name Personal explicitly where an empty value means "inherit the global one".
Variables ¶
var ErrProfileGone = profilestore.ErrGone
ErrProfileGone is the error a spawn returns for a session born in a profile that was deleted since. The window matches it to offer a new session in the project's own profile instead.
Functions ¶
func ConfigDir ¶
ConfigDir is a profile's config directory, Personal's included. A profile that does not exist answers ErrProfileGone.
func Delete ¶
Delete removes a profile's directory and its login with it. Personal cannot be deleted.
func Dir ¶
Dir is the CLAUDE_CONFIG_DIR of a profile lich created. It does not check that the profile exists; ConfigDir does.
func EnsureShared ¶
EnsureShared links into a profile the shared entries Personal gained since the profile was made, which runs before every spawn into it.
func Env ¶
Env is base with a profile's directory as CLAUDE_CONFIG_DIR and the variables that would override its login removed.
func InheritTrust ¶
InheritTrust records in the global config of the profile whose directory is dir that the checkout top is trusted, when the person trusted it or origin, the main checkout top is a worktree of, in Personal. Personal ("") is the source and has nothing to inherit. Nothing is written when the profile already trusts either, has no global config yet, or Personal trusts neither: it never trusts a folder nobody trusted.
A profile's global config is a copy of Personal's made once (layout.go), so every folder trusted in Personal after that asks again in the profile. Claude Code finds the answer for a subfolder in its checkout's top and for a linked worktree in its main checkout (measured on 2.1.302), which is why the two are all this asks about.
Claude Code re-reads the file before each write of its own (measured on 2.1.302), so a running session keeps the entry. What one writes between this read and the rename is lost; the same window its own writes have.
func IsPersonal ¶
IsPersonal reports whether slug names the default profile. Empty does too: it is what every session row born before profiles carries.
func MoveConversation ¶
MoveConversation moves everything Claude Code keyed by a conversation id from one profile to another: the transcript, its subagent directory and any file a hook filed beside it under the same name, and the per-conversation state directories. The conversation resumes in the target with its history and its checkpoints (measured round trip on 2.1.296). A hook's file the target already holds is replaced: an async hook outlives Claude Code (its SessionEnd hook runs in a session of its own, measured on 2.1.304), so one can file again in the profile the conversation just left.
What stays behind is what is not keyed by the id: the prompt history (history.jsonl) and the project's lastSessionId, which `claude --continue` in the source profile then points at a conversation it no longer holds.
func PersonalDir ¶
PersonalDir is the default profile's config directory: what Claude Code resolves from lich's own environment, CLAUDE_CONFIG_DIR else ~/.claude.
func PluginStore ¶
PluginStore is the store of the profile at dir, which sits under lich's Claude profiles root like every profile lich creates.
func PluginsDir ¶
PluginsDir is the plugins directory of the profile slug whose config directory is dir. Personal's follows pluginsDirVar from lich's environment; a profile's is always inside its own, since its spawn drops the variable.
Types ¶
type BinResolver ¶
BinResolver supplies the Claude Code binary: the configured one, or "" for the default name on PATH. The store implements it.
type Info ¶
type Info = api.ProfileInfo
type LoginEvent ¶
type LoginEvent = api.ProfileLogin
type Plugin ¶
type Plugin = api.ProfilePlugin
type PluginResult ¶
type PluginResult = api.ProfilePluginResult
type Profile ¶
type Profile = profilestore.Profile
Profile is one Claude Code account lich knows about.
func ConfigDirs ¶
func ConfigDirs() []Profile
ConfigDirs is every profile's config directory keyed by slug, Personal first. Every reader of Claude Code's transcripts scans all of them: a conversation lives in exactly one, and which one is what says the profile it belongs to.
func Create ¶
Create makes a profile named name: its directory, laid out against Personal (layout.go), and its sidecar. It does not log in.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the window's door to the profiles: listing them with their accounts, creating, renaming and deleting them, logging one in, and porting plugins between them.
func New ¶
func New(bins BinResolver, emit func(name string, data any)) *Service
New returns a Service that runs the Claude Code binary bins resolves and reports a login's progress through emit.
func (*Service) CancelLogin ¶
CancelLogin answers cancelLogin over RPC.
func (*Service) CreateProfile ¶
CreateProfile makes a profile and lays it out against Personal. The window logs it in next (Login).
func (*Service) DeleteProfile ¶
DeleteProfile removes a profile and its login, and clears every setting that named it, so a project set to it falls back to the global profile. It refuses while a session runs in it. A parked session born in it fails to resume with ErrProfileGone.
func (*Service) InstallPlugins ¶
func (s *Service) InstallPlugins(_ context.Context, opts api.InstallPluginsOptions) ([]PluginResult, error)
InstallPlugins installs each plugin@marketplace into a profile through Claude Code's own `plugin install`, run as that profile so its account's policy applies and Claude Code writes its own paths. One result per key, in order; one refusal does not stop the rest. Run it after the profile is logged in.
A plugin installed by running a command its marketplace declares is refused rather than confirmed: lich never answers that question for the user.
func (*Service) Login ¶
Login runs `claude auth login --claudeai` as a profile. The CLI opens the browser itself; what it prints, the fallback address included, arrives as LoginEvent output, and a code the page shows can be handed back through LoginCode. When the CLI exits, `claude auth status` decides whether the login took, and a logged-in profile gets the lich plugin. It returns once the CLI is started.
func (*Service) LoginCode ¶
LoginCode hands a running login the code the sign-in page showed, for a browser that could not reach the CLI on its own.
func (*Service) LoginCommand ¶
LoginCommand is the command line that logs a profile in from a terminal, for a user who would rather run it in a shell card than through Login.
func (*Service) Plugins ¶
Plugins lists the plugins a profile has installed at user scope, the ones a port can carry to another profile. The lich plugin is not among them.
func (*Service) Profiles ¶
Profiles lists every profile with its account. The statuses are asked for at once, one CLI each.
func (*Service) SetLichPlugin ¶
SetLichPlugin wires the lich plugin: install puts it into a profile and key is the plugin@marketplace it installs. Startup wiring.
func (*Service) SetSessions ¶
SetSessions wires the two questions a delete asks: how many live sessions run in a profile, and how to forget the settings that name it. Startup wiring.
func (*Service) UpdateProfile ¶ added in v0.75.0
UpdateProfile changes a profile's name, color or image and returns it; its directory never moves.