profile

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultName = "default"

DefaultName is the reserved synthetic profile that points at ~/.claude (Claude Code's default config dir when CLAUDE_CONFIG_DIR is unset).

Variables

View Source
var (
	// ErrInvalidName is returned when a profile name fails validation.
	ErrInvalidName = errors.New("invalid profile name")

	// ErrReservedName is returned when a caller tries to use a reserved name
	ErrReservedName = errors.New("reserved profile name")
)
View Source
var (
	// ErrNotFound is returned when a profile name is not in the store.
	ErrNotFound = errors.New("profile not found")

	// ErrAlreadyExists is returned by Add when a profile with the given name is already registered.
	ErrAlreadyExists = errors.New("profile already exists")
)

Functions

func ClaudeDir

func ClaudeDir(name string) (string, error)

ClaudeDir returns the directory for a named profile.

macOS, Linux: $HOME/.claude-<name>
Windows:      %USERPROFILE%\.claude-<name>

func DefaultClaudeDir

func DefaultClaudeDir() (string, error)

DefaultClaudeDir returns the path Claude Code uses when CLAUDE_CONFIG_DIR is unset: $HOME/.claude (or %USERPROFILE%\.claude). Used by `ccswitch list` to report the synthetic "default" row's existence.

func IsReserved

func IsReserved(name string) bool

IsReserved reports whether name is reserved by ccswitch and cannot be used

func MetadataPath

func MetadataPath() (string, error)

MetadataPath returns the path to ccswitch's profiles.json.

Linux:   $XDG_CONFIG_HOME/ccswitch/profiles.json, falling back to $HOME/.config/ccswitch/profiles.json
macOS:   $HOME/.config/ccswitch/profiles.json
Windows: %APPDATA%\ccswitch\profiles.json

func ValidateName

func ValidateName(name string) error

ValidateName checks a profile name against the allowed pattern. Returns ErrInvalidName wrapped with a descriptive message on failure.

Types

type Profile

type Profile struct {
	Name string `json:"name"`
	// Dir is stored as an absolute path so profiles survive $HOME changes.
	Dir string `json:"dir"`

	CreatedAt time.Time `json:"created_at"`
}

Profile is a user-created profile entry persisted in profiles.json.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the in-memory representation of profiles.json.

func Load

func Load(path string) (*Store, error)

Load reads profiles.json from path. A missing file is not an error — it returns an empty store rooted at path, ready for Save to create the file.

func (*Store) Add

func (s *Store) Add(p Profile) error

Add appends a new profile. Returns ErrAlreadyExists if a profile with the same name is already registered.

func (*Store) All

func (s *Store) All() []Profile

All returns the profiles in stored order.

func (*Store) Get

func (s *Store) Get(name string) (Profile, error)

Get returns the profile with the given name, or ErrNotFound.

func (*Store) Remove

func (s *Store) Remove(name string) error

Remove deletes the profile with the given name. Returns ErrNotFound if no such profile is registered.

func (*Store) Save

func (s *Store) Save() error

Save writes the store to disk atomically: write to a sibling temp file, then rename over the destination.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL