claudesignin

package
v0.7.11-dev.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package claudesignin is "Use your Claude subscription (runs Claude Code)": Claude Code's own sign-in into a config directory of Agentry's, and its removal. The CLI (`agentry model-signins add|remove claude`, `agentry setup`) and the desktop's model setup both call it, so there is one implementation per machine.

Anthropic forbids a third party to "collect, store, or intermediate Claude.ai credentials or session tokens", so Agentry never runs this sign-in: it starts the unmodified Claude Code's own `claude auth login` against a config directory of Agentry's own, never the person's ~/.claude, and Claude Code keeps and refreshes its credentials there. Agentry never reads that directory. Each Claude Code signs in where it runs: the image (the default) in its docker volume, through the person's browser with Claude Code's callback relayed into the container (browser.go), pasting the code Anthropic's page shows only where that cannot work; the installed Claude Code in a directory under the model sign-in store, with its own browser and callback.

Index

Constants

View Source
const Timeout = 15 * time.Minute

Timeout bounds one sign-in, browser included.

View Source
const Volume = "agentry-claude-signin"

Volume is the Claude Code image's config directory: a docker volume of Agentry's own (engine.OwnSignInDir), labelled as the sign-in's.

Variables

This section is empty.

Functions

func AnthropicSignInURL

func AnthropicSignInURL(raw string) bool

AnthropicSignInURL reports whether raw is a sign-in page of Anthropic's own, the only kind of address Agentry opens from Claude Code's output.

func CallbackPort added in v0.7.6

func CallbackPort(raw string) (int, bool)

CallbackPort is the port of Claude Code's own callback in a sign-in address, false for an address that is not one of Anthropic's sign-in pages redirecting there: what a relay elsewhere listens on.

func DefaultPolicy

func DefaultPolicy() (*policy.Policy, error)

DefaultPolicy is the operator policy a sign-in prepares its image under when none is given: the default file, written from defaults when absent.

func Forward added in v0.7.6

func Forward(ctx context.Context, ex dockerx.Execer, container string, port int, in io.Reader, out io.Writer) error

Forward relays one connection's bytes, in and out, to Claude Code's callback on the container's own loopback at port, through exec, unread. It returns when either side closes.

func HostDir

func HostDir(home string) string

HostDir is the installed Claude Code's config directory: under the model sign-in store, so the engine admits it (engine.OwnSignInDir).

func Kept

func Kept(home string) string

Kept is the account the image's sign-in names, for "Signed in as …": "" when there is none (the image's sign-in is the default adapter's).

Types

type Person

type Person struct {
	// In is what Claude Code's prompt reads: the code the person pastes
	// from Anthropic's page, passed to Claude Code unread, where the
	// browser cannot hand the sign-in back (the fallback). nil gives it no
	// input, and a sign-in that would need a paste ends instead.
	In io.Reader
	// Out receives Claude Code's output and the sign-in's own sentences.
	Out io.Writer
	// Open opens an address in the person's browser. It is only ever
	// handed one of Anthropic's own sign-in pages (AnthropicSignInURL);
	// nil opens nothing, and the person opens the printed address.
	// Through the image, the page's answer comes back to this computer and
	// is relayed into the container (browser.go).
	Open func(url string)
	// Step, when set, is told each step of the sign-in as it starts, so a
	// person waiting on it can be shown where it is; detail is the Claude
	// Code version for StepBuild and "" otherwise.
	Step func(step Step, detail string)
}

Person is the person's side of a sign-in.

type SignIn

type SignIn struct {
	// Home is the runner home (the model sign-in store's parent).
	Home string
	// Policy is the operator policy the image is prepared under; nil
	// resolves the default policy file, writing it from defaults when
	// absent.
	Policy *policy.Policy
	// PolicyPath is the file Policy was read from, beside which the image
	// built from Claude Code's newest release is recorded; "" with a Policy
	// given records nothing and takes the tested image.
	PolicyPath string
	// Docker is the daemon the image's sign-in runs on; nil is dockerx.New.
	Docker func() dockerx.Client
	// Keys is the keychain the sign-in store uses; nil keeps nothing there.
	Keys connection.Keychain
	// Relay, when set, takes the browser's answer to the container in place
	// of a listener on this computer's loopback: for a sign-in on a server
	// whose person's browser is on another machine, which listens there and
	// hands each connection to Forward. It is told the login container and
	// Claude Code's callback port before the address is opened, and stop
	// ends every connection it relays.
	Relay func(ctx context.Context, container string, port int) (stop func(), err error)
}

SignIn signs a Claude Code in for this machine.

func (SignIn) End

func (s SignIn) End(out io.Writer) func(context.Context, modelsignin.Record) (string, error)

End is the store's EndClaude: Claude Code's own logout in each of the sign-in's directories, then the directory deleted. A logout that cannot run (no image, no installed Claude Code, no network) does not keep the sign-in here: deleting the directory ends it on this computer, and the outcome says what Anthropic still holds. Only the volume and directory this package makes are ever deleted, whatever a record says.

func (SignIn) Run

func (s SignIn) Run(ctx context.Context, p Person, installed bool) (*modelsignin.Record, error)

Run signs in the image's Claude Code, or the installed one, and keeps the record beside the other's sign-in if there is one. A failed first sign-in leaves nothing behind; a failed sign-in again leaves the kept one alone.

type Step added in v0.7.4

type Step string

Step is one step of a sign-in, in the order they come. A sign-in through the installed Claude Code has no image, so it starts at StepStart.

const (
	// StepImage: looking for the Claude Code image on the docker daemon.
	StepImage Step = "image"
	// StepBuild: building the Claude Code image on this computer, which
	// downloads Claude Code and takes a few minutes.
	StepBuild Step = "build"
	// StepStart: starting Claude Code's own sign-in.
	StepStart Step = "start"
	// StepBrowser: Anthropic's page is open in the person's browser, and the
	// sign-in waits for them there.
	StepBrowser Step = "browser"
	// StepKeep: asking Claude Code who signed in, and keeping the sign-in.
	StepKeep Step = "keep"
)

func (Step) Sentence added in v0.7.4

func (s Step) Sentence(detail string) string

Sentence is how the step is said to the person, with detail as Step gives it.

Jump to

Keyboard shortcuts

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