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 ¶
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.