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
- func ValidLabel(label string) error
- type CLI
- func (c *CLI) Command(ctx context.Context, p Profile, args ...string) (*exec.Cmd, error)
- func (c *CLI) Login(ctx context.Context, p Profile, email string, stdin io.Reader, ...) error
- func (c *CLI) Logout(ctx context.Context, p Profile) error
- func (c *CLI) Status(ctx context.Context, p Profile) (*Status, error)
- func (c *CLI) Usage(ctx context.Context, p Profile, now time.Time) (*Usage, error)
- type Profile
- type Status
- type Usage
- type Window
Constants ¶
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 ¶
ValidLabel reports whether label can name a profile directory.
Types ¶
type CLI ¶
CLI runs the Claude Code binary.
func (*CLI) Command ¶
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.
type Profile ¶
Profile is one Claude Code 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 ¶
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 ¶
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)