claude

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package claude manages Claude Code profiles: separate CLAUDE_CONFIG_DIR directories, each signed in to one Claude account.

Anthropic doesn't allow third-party tools to handle Claude sign-in or store Claude credentials, so this package never does. Signing in, reading usage and signing out all run the unmodified `claude` binary, which keeps its credentials to itself.

Index

Constants

View Source
const (
	// ConfigDirEnvVar selects a Claude Code profile.
	ConfigDirEnvVar = "CLAUDE_CONFIG_DIR"
	// DefaultLabel names the sign-in Claude Code uses without CLAUDE_CONFIG_DIR.
	DefaultLabel = "default"
)

Variables

This section is empty.

Functions

func ValidLabel

func ValidLabel(label string) error

ValidLabel reports whether label can name a profile directory.

Types

type CLI

type CLI struct {
	Bin     string   // path to `claude`
	Environ []string // environment to start from
}

CLI runs the Claude Code binary.

func (*CLI) Command

func (c *CLI) Command(ctx context.Context, p Profile, args ...string) (*exec.Cmd, error)

Command returns a command that starts Claude Code in p, keeping the rest of the caller's environment.

func (*CLI) Login

func (c *CLI) Login(ctx context.Context, p Profile, email string, stdin io.Reader, stdout, stderr io.Writer) error

Login runs `claude auth login` interactively: Claude Code shows its own sign-in link and asks for the code.

func (*CLI) Logout

func (c *CLI) Logout(ctx context.Context, p Profile) error

Logout runs `claude auth logout`.

func (*CLI) Status

func (c *CLI) Status(ctx context.Context, p Profile) (*Status, error)

Status runs `claude auth status`.

func (*CLI) Usage

func (c *CLI) Usage(ctx context.Context, p Profile, now time.Time) (*Usage, error)

Usage runs Claude Code's `/usage` command headlessly. It's answered locally from Claude Code's own usage data: no model request is made.

type Profile

type Profile struct {
	Label string
	Dir   string // CLAUDE_CONFIG_DIR; empty for the default sign-in
}

Profile is one Claude Code sign-in.

func Profiles

func Profiles(root string) ([]Profile, error)

Profiles lists the profile directories under root, sorted by name.

func (Profile) IsDefault

func (p Profile) IsDefault() bool

IsDefault reports whether p is Claude Code's default sign-in.

type Status

type Status struct {
	LoggedIn         bool   `json:"loggedIn"`
	AuthMethod       string `json:"authMethod"`
	Email            string `json:"email"`
	OrgName          string `json:"orgName"`
	SubscriptionType string `json:"subscriptionType"`
}

Status is the output of `claude auth status`.

func (*Status) Subscription

func (s *Status) Subscription() bool

Subscription reports whether the profile is signed in with a Claude plan (rather than an API key or not at all).

type Usage

type Usage struct {
	Session *Window  // the 5-hour window
	Week    *Window  // the weekly window across all models
	Models  []Window // weekly windows for single models
	Notes   []string // lines this parser doesn't recognise
}

Usage is what Claude Code's `/usage` command reports.

func ParseUsage

func ParseUsage(text string, now time.Time) (*Usage, error)

ParseUsage reads the text of Claude Code's `/usage` command, e.g.

Current session: 4% used · resets Sep 28, 6pm (UTC)
Current week (all models): 27% used · resets Sep 29, 10pm (UTC)
Current week (Fable): 0% used · resets Sep 29, 10pm (UTC)

type Window

type Window struct {
	Model       string // set for windows that count one model only
	UsedPercent float64
	ResetsAt    time.Time // zero if not reported (e.g. no session in progress)
}

Window is one usage window from `/usage`.

Jump to

Keyboard shortcuts

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