OpenProgram Docs

Auth storage

AuthStore (models/auth/store.py): ~/.openprogram/auth/<provider_id>/credentials.json, one ordered list per provider, atomic write, a cross-process lock held from read to write (mutate), reload when the file changes underneath. An API key's secret is in its company's file, auth/_keys/<company>.json, written the same way.

What requests count (uses, last use, uses today, the rotation cursor) lives beside it in usage.json, so a request never rewrites the secrets file. CredentialProvider serves what is on disk and never re-discovers; import is an explicit step.

ProviderLogin methodStorageRefresh
openai-codexpkce_oauth, or a copy of ~/.codex/auth.jsoncopy, or delegated pointerOpenProgram through ~/.codex/auth.json (see Refresh)
github-copilotdevice_codecopyOpenProgram
xai-subscriptionpkce_oauth, import_from_cli (~/.grok/auth.json), paste_tokenstoreper method
anthropicapi_keycopynone. Subscription credentials are refused.
gemini-subscriptionimport_from_cli (~/.gemini/oauth_creds.json)delegated pointerexternal CLI; gemini auth login when stale
other key providersapi_keycopynone

Bedrock and Vertex use the cloud SDK's own chain. qwen has a credential source but no runtime, so no login is offered. claude-code and related ids are unsupported.

Credential kinds

kindSecret storage
api_keycopy of the key
oauth, device_codecopy: access, refresh, expires_at_ms, client id, token endpoint
importpointer only: store_path and key paths, re-read each use
credential_processargv run on demand

methods/cli_import.py has mode="link" (default) and mode="copy", which builds a writable store-owned oauth credential.

Login registry

auth/login/login_method_registry.py is the one provider → [method] table; the first entry is the default, and the CLI, web and TUI all render it. Handlers are in auth/methods/ and auth/login/. Google's Code-Assist OAuth embeds a client secret OpenProgram cannot ship, so that provider stays delegated; Anthropic has no published third-party OAuth client.

Each method carries a title and a one-line description in English and Chinese, and an import names the file it reads; the web setup dialog shows them as its list of ways in.

Refresh

A refresh token rotates: the first holder to spend it gets a new pair, and any later spend of the old one is refused (invalid_grant), which signs that holder out. So a refresh is spent by one process at a time, and each process re-reads the login after it gets the lock.

RuleBehaviour
Before sendingCredentialProvider.prepare refreshes a login whose expires_at_ms is within 60 s; the request goes out with a token that has not expired
Cross-process lockrefresh_lock.py: an advisory lock on <file>.refresh.lock beside the provider's list, separate from its write lock. Two workers, or a worker and its cron subprocess, take turns
Inside the lockRe-read the file. A login another process refreshed meanwhile is used as is; only a still-stale one is refreshed and saved
Rejected before expiryAn HTTP 401 refreshes that login once and sends the same request again at once, without a transport retry. One INFO line records the refresh

One ChatGPT login per machine

A ChatGPT sign-in is one refresh-token family, and on a machine it lives in the Codex CLI's ~/.codex/auth.json (or $CODEX_HOME). The Codex CLI refreshes it, an import credential reads it (the development instance has only this one), and an OpenProgram oauth login of the same account keeps a copy. All of them take that file's refresh lock.

HolderRefresh
importReads the file for every request. When the token's own exp is within 60 s, or the backend answers 401, it spends the file's refresh token and writes the new tokens back to the file, as the Codex CLI does
oauth copyBefore each request, adopts a later login of the same account found in the file and saves it to the store. When it must refresh, it first re-reads the file under the lock and adopts a later login there instead of spending a refresh token another holder already spent; otherwise it refreshes and mirrors the result into the file
Different account in the fileNeither adopted nor overwritten
Writing the fileCreated owner-only (0600), synced to disk, then renamed over the file: for a delegated reader it holds the only copy of the rotated refresh token. A write that fails is logged as a warning naming the path, never a token
Saving an adoptionOnly while the store still holds the token it was adopted over. A refresh that saved a newer login in between keeps it

The credential layer makes the chosen login ready (prepare) in a worker thread, never on the event loop, since it can wait for another process's refresh lock and a refresh request.

Unreadable is not empty

StepBehaviour
Write (credentials/io._atomic_write)Keeps the replaced file as <file>.bak when it is valid JSON (state/last_good.keep_previous)
Read of invalid JSON (last_good.load_json)Copies the bytes once to <file>.bad-<UTC time>-<digest>, answers the valid .bak, else nothing
Usersread_config, update_config, the auth store
A key removed or replacedIts list's .bak and .bad- copies are deleted too, so the old key leaves the disk
Backups (operations/backup.py)Leave out .bak and .bad- copies, so redaction cannot be bypassed

Follows magpie's lastgood (yetone/magpie, MIT).

Peers
ProjectDesign
opencodeOwn PKCE and auth.json, no adoption. provider → AuthHook with method:"auto" or "code"; on-demand single-flight refresh. Anthropic and Google are API key only.
openclawauth-profiles.json by <provider>:<label>; rotation state in a sibling file; oauth, api_key, token; refresh under a cross-process lock that re-reads inside the lock (the part worth copying); one handler picks browser or paste. Reads other CLIs' files directly, which this design does not.
Implementation status

Not in place: copying the Gemini subscription token into the store as the default import.

Provider keys and failover

Last updated · 2026-11-25