Documentation
¶
Overview ¶
Package ccswitch reads CC Switch's provider store.
CC Switch is a desktop switcher for Claude Code / Codex / Gemini endpoints: the person keeps a list of providers there (name, endpoint, token, model tiers) and the app rewrites the client's own config to whichever one is current. That list is the interesting thing for discovery — it is every relay the person already configured, not just the one that happens to be live — but it lives in a SQLite file the app owns, so this package only ever opens it read-only and only ever answers two questions: "which providers are configured" and "what is this provider's token".
Two deliberate limits:
- Read-only, always. The file is opened with mode=ro and a busy timeout: CC Switch may be writing while discovery runs, and a scan must never be able to corrupt or block the app that owns the store.
- Nothing secret leaves the process. Read returns the endpoint, the model ids and *whether* a token exists; ResolveKey is the only function that returns a secret, and its only caller is the model client at call time.
Index ¶
Constants ¶
const ( AppClaude = "claude" AppClaudeDesktop = "claude-desktop" AppCodex = "codex" AppGemini = "gemini" )
The app types CC Switch stores. Each one keeps its settings in a different shape under settings_config, which is why the parser branches on this.
const RefPrefix = "ccswitch:"
RefPrefix names a credential that lives in the CC Switch store: "ccswitch:<app_type>:<provider id>". It is stored in config as a reference, so the secret stays in the file that already holds it and a key rotation in CC Switch is picked up without re-importing.
Variables ¶
This section is empty.
Functions ¶
func Describe ¶
Describe is the source's one-line status detail, kept here so the collector does not have to duplicate the counting rules. "Importable" means the row has an endpoint, a model and a token — the three things a registry row cannot invent.
func ResolveKey ¶
ResolveKey returns the token a reference names. It is the only function in this package that returns a secret, and the model client is its only caller. An unreadable store, an unknown id or a provider without a token all answer "" — the client then reports the row as having no key, which is the truth.
Types ¶
type Provider ¶
type Provider struct {
// ID is CC Switch's own row id (a UUID). KeyRef names it.
ID string
// AppType is "claude", "claude-desktop", "codex" or "gemini".
AppType string
// Name is the label the person gave the provider ("Zhipu GLM", "本地").
// It is the most recognisable thing a discovered row can show.
Name string
// BaseURL is the endpoint the provider dials, empty for a vendor-official
// row that leaves the endpoint to the client's default.
BaseURL string
// Models are the model ids the provider pins, in tier order and deduped.
// Claude Desktop rows usually carry none — the client picks the model.
Models []string
// APIType is the wire dialect this row speaks: "anthropic" for the Claude
// apps, "responses" or "openai" for Codex (its wire_api).
APIType string
// HasToken says a credential is stored for this provider. The value never
// leaves ResolveKey.
HasToken bool
// Bearer marks a credential stored as ANTHROPIC_AUTH_TOKEN rather than
// ANTHROPIC_API_KEY: the two headers are not interchangeable on a relay,
// so the imported row has to keep the scheme.
Bearer bool
// Current marks the provider CC Switch has written into the live config.
Current bool
// SortIndex is CC Switch's own ordering; it keeps discovery output stable.
SortIndex int
}
Provider is one configured endpoint, flattened out of the store's settings_config JSON.