Artifact c43bbc0e51aaaeda36613da68b786944275111aa829fcea244e8955af08e3182:
- File
docs/manual/credentials.md
— part of check-in
[bcb82b941e]
at
2026-11-23 11:55:36
on branch keysource
— Keep the credential store's key in the Keychain or a key file, not behind a passphrase
A new store gets a random 32-byte master key kept in the login Keychain (macOS, /usr/bin/security run as a child with the command on stdin) or the keyring (secret-tool), else ~/.pic/master.key at 0600. The source is recorded in picu_credential_key.source; a passphrase store keeps working as before. pic auth rekey keychain|file|passphrase reseals every sealed row in one transaction, and a typed passphrase is followed once by the offer to stop asking. --passphrase-fd and PIC_PASSPHRASE_COMMAND (setting passphraseCommand) give a passphrase with no terminal. pic remote opens a keychain or file store with no prompt. Every OS service stays in platform.c behind secret_key, secret_keep and secret_drop. (user: dmestas, size: 4038) [annotate] [blame] [check-ins using]
Credentials
API keys come from pic's credential store or from the environment (ANTHROPIC_API_KEY,
OPENAI_API_KEY, OPENROUTER_API_KEY, ...), as in Pi.
pic login anthropic # the key, typed with echo off (or piped on stdin), sealed into ~/.pic/pic.sqlite
pic keys # stored keys: names and dates, never values
pic logout anthropic # remove it
/login [PROVIDER] and /logout [PROVIDER] do the same in the terminal interface. A provider with
a subscription sign-in can use that instead of a key: see subscription sign-in.
The lookup order
As in Pi, a stored credential owns its provider. A request uses the first of these that exists:
- the key chosen for the provider, with
--keyfor one run orpic auth use(or/key) from now on; see several keys; - the credential stored with
pic loginorpic auth login(an API key or a sign-in), else the provider's oldest key stored with--as; - the
apiKeywritten inmodels.json; - the provider's environment variable.
If none exists the request fails with an error naming pic login. A stored credential that cannot
be used (a damaged row, a sign-in whose refresh failed) is an error; pic does not quietly fall
back to the variable. So an exported variable that is out of credit or stale never hides a key you
stored; pic logout PROVIDER returns the provider to its variable.
pic auth status lists every key, marks the one in use, and says of a variable a stored key hides
not used: a stored key wins; the provider list in /login says the same.
The store
Each stored key is sealed with ChaCha20-Poly1305 (the provider's name bound as associated data), so no plaintext key reaches the database, its WAL, a backup or a log. The sealing key is kept apart from the database, in one of three places:
| Where | When | Asks you |
|---|---|---|
your login Keychain (macOS), or your keyring (Linux with secret-tool) |
the default for a new store | nothing |
~/.pic/master.key, readable only by you |
when there is no keychain, or it refuses (locked, over ssh) | nothing |
| a passphrase | when you choose it: pic auth rekey passphrase |
the passphrase, once per process |
pic fetches the key the first time a stored key is needed and keeps it only for the life of the process; the terminal interface hands it to its request processes through an inherited pipe, never argv, the environment's values or a file. A key file is excluded from Time Machine, and pic refuses one that others can read.
What this protects against: a copied pic.sqlite, a backup of it or an exported journal reveals no
key on its own. What it does not: anyone or anything that can act as you while you are logged in
(malware, someone at your unlocked session) can read the Keychain item or the key file and open the
store, as they can with the keys other tools keep. A passphrase also guards against that, at the
cost of typing it; FileVault or disk encryption covers a stolen disk.
Moving the key
pic auth rekey keychain, pic auth rekey file or pic auth rekey passphrase moves the key: every
stored key, sign-in and remote control key is sealed again under a new key in one step, and the old
place is cleared only once that has succeeded. A store with a passphrase keeps working as before.
When you type its passphrase at a prompt, pic asks once whether to stop asking:
Stop asking for this passphrase? pic can keep the key in your Keychain. [y/N]
y moves the key there; anything else keeps the passphrase and is remembered, so it is not asked
again. pic auth rekey passphrase goes back at any time.
A passphrase can also come without a terminal: --passphrase-fd N reads it from descriptor N, and
the command in PIC_PASSPHRASE_COMMAND (or the setting passphraseCommand) prints it, for example
op read op://Private/pic/password.
How the key is derived and where it is kept is in the architecture notes.