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
- func AnthropicSignInURL(raw string) bool
- func CallbackPort(raw string) (int, bool)
- func DefaultPolicy() (*policy.Policy, error)
- func Forward(ctx context.Context, ex dockerx.Execer, container string, port int, ...) error
- func HostDir(home string) string
- func Kept(home string) string
- type Person
- type SignIn
- type Step
Constants ¶
const CheckTimeout = 2 * time.Minute
CheckTimeout bounds the save check's one message, once the image is here.
const Timeout = 15 * time.Minute
Timeout bounds one sign-in, browser included.
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 ¶
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
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 ¶
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.
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) CheckModel ¶ added in v0.7.38
func (s SignIn) CheckModel(ctx context.Context, model string) (modelcheck.ClaudeAnswer, error)
CheckModel sends the Claude Code the sign-in is kept for the save check's one message on model (modelcheck.ClaudeArgs), in the sign-in's own directory: the image's on its volume, else the installed one's. The image's container is given no variable of the person's; the installed Claude Code none of their ANTHROPIC_* or CLAUDE_CODE_* ones. No sign-in kept is an answer, NotSignedIn, not an error.
func (SignIn) End ¶
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.
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" )