ccswitch

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 7 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 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

View Source
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.

View Source
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

func Describe(providers []Provider) string

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 MakeRef

func MakeRef(appType, id string) string

MakeRef builds the reference for one provider.

func Path

func Path(home string) string

Path returns the store's default location under home.

func ResolveKey

func ResolveKey(ref, home string) string

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.

func Read

func Read(path string) ([]Provider, error)

Read returns every provider in the store, ordered the way CC Switch orders them. A store that does not exist yields (nil, nil): absence is a status, not a failure.

Jump to

Keyboard shortcuts

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