# Credentials and the keychain

> Where zelk keeps sign-ins and API keys, how to move them into the system keychain, and how zelk reaches the network through a proxy.

zelk keeps a few secrets of its own: sign-ins, tokens and API keys. By
default they are files in its config directory, readable by you alone. You
can keep them in the system keychain instead.

## What zelk keeps

| Document | Holds | File |
|---|---|---|
| `chatgpt` | the ChatGPT plan sign-in | `chatgpt.json` |
| `mcp` | MCP servers' OAuth clients and tokens | `mcp-oauth.json` |
| `browser` | the pairing with zelk's extension in your browser | `browser.json` |
| `provider-keys` | API keys typed into **Providers…** in the terminal UI | `provider-keys.json` |

The files are in `~/.config/zelk` (`$XDG_CONFIG_HOME/zelk` when that is
set). Never share or print them. A provider key written as `$NAME` isn't
stored at all: zelk reads the variable `NAME` each time.

`zelk credentials` lists where each document is, and whether that place can
be used, without showing any credential:

```text
$ zelk credentials
chatgpt        ChatGPT sign-in  none
mcp            MCP sign-ins     none
browser        browser pairing  none
provider-keys  provider keys    none
New credentials go to: file
```

## Use the keychain

The keychain is the Secret Service on Linux (GNOME Keyring, KWallet,
KeePassXC), the login keychain on macOS and the Credential Manager on
Windows. To keep new credentials there,
save `"credential_store": "keychain"` in `~/.config/zelk/config.json`, set it
in **Settings…**, or pass `-credential-store keychain`. A document in the
keychain leaves only a small marker in its file, naming the keychain item.

zelk never falls back to a file: where no keychain can be used, saving a
credential fails and says why. Credentials you already have stay where they
are until you move them:

```sh
zelk credentials move -to keychain           # every document
zelk credentials move -to keychain chatgpt   # just one
zelk credentials move -to file               # back to files
```

Moving `provider-keys` to the keychain also moves API keys typed straight
into `providers.json`. A document in the keychain is read from there
whatever the setting says.

To delete a document wherever it is, which signs you out of what it held:

```sh
zelk credentials purge mcp
```

### The Credential Manager on Windows

zelk keeps each document as credentials named `zelk:` and a long hex id, which
you can see under Windows Credentials in the Control Panel's Credential
Manager (or with `cmdkey /list:zelk:*`). A document of any size works: the
Credential Manager holds 2,560 bytes per credential, so zelk spreads a
larger document over several, and a document that can't be read back whole
is reported as lost, never read as a partial or empty one.

- **They stay on this computer.** zelk saves them as local-machine
  credentials, which survive logoff and restarts and are not roamed to your
  other computers. A copy of your config folder on another computer does
  not carry them.
- **There is no prompt.** The Credential Manager is never locked and asks
  nothing, so every command can use it.
- **A session without a credential set can't use it.** Windows gives none
  to a network logon; there zelk says the keychain is unavailable and never
  falls back to a file.
- Don't delete the `zelk:` credentials by hand: the document's file names
  them, and a document whose credential is gone reads as lost until you
  `zelk credentials purge` it and sign in again.

## When zelk may prompt

Unlocking the keychain, or allowing zelk to use an item, can show a prompt
from your system (not on Windows, which never asks). Only commands you run yourself may show one: the terminal
UI, `zelk providers login`, `zelk mcp login`, `zelk browser pair` and
`zelk credentials`. `zelk -p`, `zelk exec` and `zelk acp` never prompt: if
the keychain is locked or refuses, they fail and say which command to run.
`zelk credentials` is also where you approve a new build of zelk that the
keychain doesn't trust yet.

## What it protects

With the keychain, no file in zelk's config directory holds a secret in
plain text, nor do backups of that directory. Backups taken before a move
still hold the old files.

Commands the agent runs outside a sandbox can still reach an unlocked
keychain, as any program of yours can. On Windows, MXC denies access to
Credential Manager. On macOS, seatbelt denies access to the keychain, and
on Linux, bwrap cuts commands off from
the session bus, unless the network is `full` and the bus is an abstract
socket, or the bus socket lies under a path the sandbox binds. zelk warns
when it starts under bwrap in either of those cases.

## Required by policy

A [managed policy](/cli/policy/) with `"credential_store": "keychain"`
requires the keychain: new credentials go there whatever you chose, with a
warning if you chose `file`, and a document still in a file, including a
literal key in `providers.json`, is refused until
`zelk credentials move -to keychain` moves it.

## Proxies and certificates

zelk's own connections (model providers, MCP servers, sign-ins, WebFetch,
the browser download) go through the proxy the environment names:
`HTTPS_PROXY`, `HTTP_PROXY` and `NO_PROXY`, or their lower-case forms, read
as curl reads them. An http, https or socks5 proxy works. Loopback
addresses are never proxied, so a model server on your machine is reached
directly.

A proxy that inspects TLS signs with its own certificate authority. Put its
certificates, PEM-encoded, in a file and name it:

```sh
export ZELK_EXTRA_CA_CERTS=/etc/ssl/corp-ca.pem
```

They are trusted alongside the system's. When `ZELK_EXTRA_CA_CERTS` is
unset, zelk reads `NODE_EXTRA_CA_CERTS`, so a setup made for Node tools
carries over. A proxy that isn't a URL, or a certificate file that can't be
read, stops zelk at start rather than leaving it to connect directly.

Commands the agent runs inherit the environment as usual. Under
`-network allowlist`, the sandbox connects to the allowed hosts directly,
not through the proxy.

## Where to go deeper

- [The keychain contract](/internals/keychain/): markers, locking, and what each crash leaves
- [`zelk credentials`](/reference/cli/#zelk-credentials) in the CLI reference
- [Settings](/reference/settings/): `credential_store` and the rest of `config.json`
