subs

package
v0.172.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 16 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 subs is Settings → Subscriptions (ADR-048): more than one sign-in to Claude Code or Codex on one machine, each in a configuration directory of its own, and a session started on the one the user picks.

The owner's request that started it (2026-10-10, translated): "make subscription management so several subscriptions can be authorised and you can work through them."

It rests on what both agents document, read 2026-10-10:

  • Claude Code: "To stay signed in to multiple accounts at once … give each account its own configuration directory … Each directory has its own settings, session history, and claude.ai login or API key", and with CLAUDE_CONFIG_DIR set it "keys the macOS Keychain entry to that directory too, so a session with a different CLAUDE_CONFIG_DIR reads a different entry" (code.claude.com/docs/en/authentication). The path must be absolute (code.claude.com/docs/en/env-vars).
  • Codex: "Codex stores its local state under CODEX_HOME" and `file` credentials are "auth.json under CODEX_HOME" (developers.openai.com/codex/config-advanced, /codex/auth). Its keyring entry is keyed by a hash of the CODEX_HOME path (github.com/openai/codex, codex-rs/login/src/auth/storage.rs, compute_store_key).

Caprock never signs anyone in. Adding a subscription makes the directory and types the agent's own sign-in command into a shell tab, not run; the user presses Enter. Nothing here starts an agent, reads a credential's secret or touches the Keychain: whether a directory is signed in is read from files the agent wrote (see Status).

Index

Constants

View Source
const (
	AgentClaude = "claude"
	AgentCodex  = "codex"
)

Agents that have subscriptions: the two whose sign-in lives in a directory an environment variable can move.

View Source
const DeepSeekID = "deepseek"

DeepSeekID names Claude Code on DeepSeek: a Claude Code session in the user's own configuration directory whose model calls go to DeepSeek's Anthropic-compatible API on the user's DeepSeek key (Settings → Subscriptions). It is offered beside the sign-ins once a key is set, and recorded on its sessions like one, so their plan windows, if any arrive, are filed under its own prefix and never over the Default sign-in's, and the plan-window stop leaves them alone. It is not a directory and not a sign-in, so it never counts toward FreePerAgent. NewID's hex ids can never spell it.

View Source
const DefaultID = "default"

DefaultID is how the API names the user's normal sign-in. Sessions on it store "" in sessions.subscription, as every session did before this.

View Source
const FreePerAgent = 3

FreePerAgent is how many subscriptions per agent are free, the Default one included; a fourth and more need a licence (owner decision, 2026-10-10).

View Source
const KimiID = "kimi"

KimiID names Claude Code on Kimi: the same as DeepSeekID, on Moonshot's Anthropic-compatible API with the user's Kimi platform key. Not hex, so it cannot collide with a subscription id either.

View Source
const MaxLabel = 40

MaxLabel bounds a label.

Variables

This section is empty.

Functions

func CleanLabel

func CleanLabel(s string) (string, error)

CleanLabel trims a label and refuses an empty or overlong one.

func Count

func Count(list []config.Subscription, agent string) int

Count is how many subscriptions agent has, the Default one included.

func CredentialEnv added in v0.133.0

func CredentialEnv(agent string) []string

CredentialEnv is what, in a session's environment, makes the agent use a credential other than the sign-in its configuration directory holds. A session Caprock starts on a subscription runs without these, so it runs on the sign-in the user picked and not on whatever the login shell exports (ADR-048, amended 2026-10-18). A session on the user's own sign-in keeps them: that is how their own terminal runs too.

  • Claude Code ranks ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY, CLAUDE_CODE_OAUTH_TOKEN, a named ANTHROPIC_PROFILE, the federation variables and a cloud provider switch above the directory's /login (code.claude.com/docs/en/authentication, "Authentication precedence", read 2026-10-18). CLAUDE_SECURESTORAGE_CONFIG_DIR, which Claude Code sets for the teammates it starts, replaces the directory its Keychain entry and .credentials.json are keyed to (the 2.1.302 bundle: the service is "Claude Code-credentials-" plus the first eight hex digits of SHA-256 of that directory instead of CLAUDE_CONFIG_DIR's).
  • Codex takes CODEX_API_KEY and CODEX_ACCESS_TOKEN over its stored credentials (github.com/openai/codex codex-rs/login/src/auth/manager.rs, read 2026-10-18). OPENAI_API_KEY is not read there, so it stays: tools a session runs may want it.

func CredentialEnvSet added in v0.133.0

func CredentialEnvSet(agent string, env []string) []string

CredentialEnvSet names the CredentialEnv variables env sets to something other than blank, in CredentialEnv's order: what Settings tells the user a session on a subscription runs without. Names only; a value never leaves.

func Dir

func Dir(dataDir, id string) string

Dir is one subscription's configuration directory. Absolute whenever dataDir is, which Claude Code requires.

func EnvVar

func EnvVar(agent string) string

EnvVar is the variable that moves agent's configuration directory.

func Find

func Find(list []config.Subscription, id string) (config.Subscription, bool)

Find returns the subscription with id.

func IsProvider added in v0.171.0

func IsProvider(id string) bool

IsProvider reports whether id is one of the entries that are an API key rather than a sign-in (DeepSeekID, KimiID).

func KeychainService added in v0.133.0

func KeychainService(dir string) string

KeychainService is the macOS Keychain item Claude Code keeps a sign-in in when it runs with CLAUDE_CONFIG_DIR=dir ("" is the user's own sign-in): "Claude Code-credentials", and with the variable set, "-" and the first eight hex digits of SHA-256 of the directory, normalised to NFC, after it. Read from the Claude Code 2.1.302 bundle on 2026-10-18; the docs say only that the entry is keyed to the directory (code.claude.com/docs/en/ authentication). Caprock names it so the user can find it in Keychain Access; it never reads, writes or deletes it.

func LimitPrefix

func LimitPrefix(id string) string

LimitPrefix is the rate_limit_latest key prefix for a subscription's plan windows: `sub:<id>:five_hour`. The Default one keeps the keys it always had — `five_hour` for Claude Code, `codex_five_hour` for Codex — so nothing already stored moves.

func LoginCommand

func LoginCommand(agent, dir, goos string) string

LoginCommand is the agent's own sign-in, pointed at dir, for a shell tab: typed, never run. A POSIX shell gets the variable for that one command; on Windows Caprock's shell tab is PowerShell, which sets it for the tab.

`claude auth login` and `codex login` are each agent's documented sign-in (code.claude.com/docs/en/cli-reference, developers.openai.com/codex/auth, read 2026-10-10).

func LoginCommandHere

func LoginCommandHere(agent, dir string) string

LoginCommandHere is LoginCommand for this machine.

func LogoutCommand added in v0.133.0

func LogoutCommand(agent, dir, goos string) string

LogoutCommand is the agent's own sign-out, pointed at dir, typed into a shell tab like LoginCommand. It is how a subscription's credential leaves the macOS Keychain or the OS keyring, which Caprock never touches itself: removing a subscription deletes its folder, and a Keychain entry is not in it. `claude auth logout` and `codex logout` are each agent's own (`claude auth --help`, `codex logout --help`, read 2026-10-18).

func LogoutCommandHere added in v0.133.0

func LogoutCommandHere(agent, dir string) string

LogoutCommandHere is LogoutCommand for this machine.

func NewID

func NewID() (string, error)

NewID makes a subscription id: eight lowercase hex digits.

func Of

func Of(dataDir, path string) string

Of names the subscription a transcript belongs to, from its path: a file under profiles/<id>/ is that subscription's, anything else is "" (the Default one, or a directory Caprock does not manage).

func OfDir

func OfDir(dataDir, dir string) string

OfDir names the subscription whose directory dir is, or "" when it is none of Caprock's (the status line forwards the CLAUDE_CONFIG_DIR it ran under).

func Prepare

func Prepare(agent, dir, shimCmd, statuslineCmd, defaultSettings string) error

Prepare makes a subscription's directory and, for Claude Code, gives it what Caprock needs to see the sessions run on it.

A new CLAUDE_CONFIG_DIR is a new ~/.claude: "All settings, session history, and plugins are stored under this path" (env-vars, read 2026-10-10). So its settings.json would carry none of Caprock's hooks and no status line, and a session on it would be invisible to the dashboard and its plan windows unknown. Prepare writes them — the same entries `caprock hooks install` writes into ~/.claude/settings.json — and, when the user has already accepted Claude Code's bypass warning in their own settings, that answer too (ADR-041): it is the user's consent, not an account's. Nothing else of the user's settings is copied; the directory is Caprock's, and so is every file in it Caprock wrote. Safe to call again: each write is idempotent.

func ProfilesDir

func ProfilesDir(dataDir string) string

ProfilesDir is where every subscription's directory lives.

func Remove

func Remove(dataDir, id string) error

Remove deletes a subscription's directory — and only a directory directly under profiles/, whatever id says.

func Supported

func Supported(agent string) bool

Supported reports whether agent has subscriptions.

func ValidID

func ValidID(id string) bool

ValidID reports whether id could have come from NewID — the check that keeps a request from naming a directory outside profiles/.

Types

type Paths

type Paths struct {
	Agent string
	// Dir is the configuration directory: ~/.claude, ~/.codex or a profile.
	Dir string
	// GlobalConfig is Claude Code's .claude.json for that directory:
	// ~/.claude.json for the default, <dir>/.claude.json for a profile.
	GlobalConfig string
}

Paths is where an agent keeps what Status reads, for one directory.

func DefaultPaths

func DefaultPaths(agent, home string, getenv func(string) string) Paths

DefaultPaths is the user's normal sign-in, honouring a CLAUDE_CONFIG_DIR or CODEX_HOME their login shell already sets.

func ProfilePaths

func ProfilePaths(agent, dir string) Paths

ProfilePaths is a subscription's.

type SignIn

type SignIn struct {
	// SignedIn is true when the agent left a sign-in there.
	SignedIn bool `json:"signed_in"`
	// Account is the account's e-mail address, when the agent wrote it down
	// in a file that is not the credential itself; "" otherwise.
	Account string `json:"account,omitempty"`
}

SignIn is what Caprock can tell about a directory's sign-in from the files in it.

func Status

func Status(p Paths) SignIn

Status reads a directory's sign-in. Nothing is run and no secret is kept:

  • Claude Code writes the account it signed in to as `oauthAccount` in .claude.json (beside trust decisions and MCP servers), and keeps the credential itself in the Keychain on macOS or in .credentials.json elsewhere (authentication, read 2026-10-10). Either counts.
  • Codex keeps `file` credentials in auth.json; its id token names the account's e-mail address, which is decoded here and nothing else of the file is kept. A Codex set to the OS keyring leaves no auth.json and reads as not signed in until a session on it reports plan windows.

Jump to

Keyboard shortcuts

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