claudesub

package
v0.41.4 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package claudesub turns a Claude Pro/Max subscription into a memcode backend by reusing the login the Claude Code CLI already stored. It reads the OAuth token from ~/.claude/.credentials.json (and, on macOS, the Keychain), reconciles the two, refreshes an expired token, and returns the access token. A running session holds a TokenSource rather than a fixed token, so a token that expires mid-session, or one replaced by a Claude Code re-auth, is picked up on the next request (and a 401 retries once) without restarting memcode. The token is then used through the Anthropic adapter's Claude Code compatibility mode (internal/providers/anthropic/oauth.go), where the actual impersonation lives — this package only resolves the credential.

Consent-gated upstream: it activates only when the user explicitly selects the claude source. It reuses Claude Code's file; refreshed tokens are written back there (never the Keychain), atomically at 0600.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() bool

Available reports whether a Claude Code login is present (file, or the macOS Keychain), for the wizard's menu.

func Resolve

func Resolve() (string, error)

Resolve returns a usable Claude access token, refreshing it if expired. The returned token is an OAuth token (cc-*/eyJ…) that turns on the adapter's compatibility mode.

Types

type TokenSource added in v0.41.0

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

TokenSource hands a long-lived session the CURRENT Claude access token, instead of the one captured at startup. Claude Code tokens live for hours; a session that outlives one (or a user who re-auths Claude Code mid-session) must self-heal without restarting memcode. Token is cheap on the hot path (an in-memory copy until it nears expiry); Rejected is the 401 path.

func NewTokenSource added in v0.41.0

func NewTokenSource(tok string) *TokenSource

NewTokenSource seeds a source with an already-resolved token so the first request needs no extra credential read.

func (*TokenSource) Rejected added in v0.41.0

func (s *TokenSource) Rejected(tok string) (string, error)

Rejected is called when the API refused tok (401). It re-reads the login — picking up a fresh Claude Code sign-in — or refreshes it, and returns the replacement. An error means there is genuinely nothing better to try.

func (*TokenSource) Token added in v0.41.0

func (s *TokenSource) Token() (string, error)

Token returns a usable access token, re-resolving (re-read + refresh) when the cached one is near expiry. exp==0 on a seeded source means "unknown", so the first expiry check after seeding consults the credential store once.

Jump to

Keyboard shortcuts

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