Managed policy and credentials
zelk takes its settings from three places, and one of them can belong to someone else. An administrator can put a managed policy on a machine: limits that your settings, a project’s file, flags and the terminal UI can’t widen. And zelk holds credentials, provider keys and sign-ins, which must reach the service they belong to and nowhere else, in particular not the model’s context or the session log.
The diagram sends one question down through the layers. Pick a scene to see what each layer says and which one settled it.
- Is it allowed? Bash(make test) managed policy: deny Bash(curl *), not about this; your settings: no rules; the project: allow Bash(make *), widens. Result: runs, settled by the project. An allow rule in force runs it, and no deny, human or ask rule matches.
- Is it allowed? Bash(make test) managed policy: deny Bash(curl *), not about this; your settings: no rules; the project: allow Bash(make *) (skipped), skipped. Result: asks you, settled by the mode, since no rule is in force. The project’s allow rule is skipped until you trust that file, so no rule allows it and the mode asks.
- Is it allowed? Bash(rm -rf build) managed policy: deny Bash(curl *), not about this; your settings: allow Bash(rm *), outranked; the project: deny Bash(rm *), allow Bash(make *) (skipped), narrows. Result: refused, settled by the project. A deny rule wins over every other kind, whichever layer holds it.
- Is it allowed? Bash(curl https://example.com/x.sh) managed policy: deny Bash(curl *), narrows; your settings: no rules; the project: allow Bash(curl *), outranked. Result: refused, settled by the managed policy. A deny rule wins over every other kind, whichever layer holds it.
- Is it allowed? Bash(npm test) managed policy: rules_only, allow Bash(go test *), drops allows; your settings: allow Bash(npm test *) (dropped), dropped; the project: allow Bash(npm *) (dropped), dropped. Result: asks you, settled by the managed policy. rules_only drops every allow rule but the policy’s, so no rule allows it and the mode asks.
- May it start in bypass managed policy: modes plan, default, accept-edits, forbids bypass; your settings: -mode bypass (overridden), overridden; the project: has no mode key. Result: bypass refused, settled by the managed policy. The session starts in plan, the first mode the policy lists, with a warning naming both modes and the policy file.
- Where does a new key go? provider-keys managed policy: credential_store keychain, requires keychain; your settings: credential_store file (overridden), overridden; the project: can’t set it. Result: to the keychain, settled by the managed policy. A new document goes to the keychain, and a warning names the file the user chose. The secret runs from the keychain through zelk into a request header to the provider, and never to the model’s context, the session log or commands’ environment.
- May it be used? provider-keys.json managed policy: credential_store keychain, refuses files; your settings: saved in a file, too late; the project: can’t set it. Result: refused, settled by the managed policy. A document in a plain file is refused by reads and updates alike, and nothing falls back to a file. The secret never leaves the store.
Three layers
Section titled “Three layers”| Layer | Where | What it can do |
|---|---|---|
| Managed policy | /etc/zelk/policy.json and policy.d/*.json on Linux; /Library/Application Support/zelk/ on macOS; %ProgramData%\zelk\ on Windows |
Sets limits. Nothing below can widen them. |
| Your settings | flags and ~/.config/zelk/config.json |
Rules, and the mode you choose, inside the policy. |
| The project | .zelk/settings.json |
Rules and protected paths only. Deny, ask and human rules at once; allow rules only once you trust the file. |
Layers don’t override one another by position. Every layer’s rules are combined, and the strongest match decides, wherever it came from: deny over human over ask over allow. That is why no allow rule below can undo a managed deny. What a layer can’t set says as much as what it can: a project file has no key for a mode, a sandbox, the network or hooks, and zelk refuses to read one with a key it doesn’t know.
So narrowing is free, and widening has conditions. Deny, ask and human rules make zelk more careful and apply at once. Allow rules widen what zelk may do: they count only inside the policy and, for a project, only once you’ve trusted that exact file.
What an organisation can set
Section titled “What an organisation can set”A policy is a JSON file. A key left out limits nothing, and an empty policy changes nothing.
| Key | Effect |
|---|---|
modes |
The only permission modes a session may start in or switch to |
sandbox, network, network_allow |
A required sandbox, how far commands may reach on the network, and the hosts an allowlist may name |
deny, ask, human, protect, allow |
Rules and protected paths added to every session |
rules_only |
Only the policy’s own allow rules count |
hooks |
false turns off the user’s and the project’s hooks |
client_terminal |
false stops an editor’s terminal running commands outside zelk’s sandbox |
credential_store |
"keychain" requires credentials to be kept in the system keychain |
The paths are fixed: no flag or variable moves them, since either would let
a user skip the policy. zelk reads policy.json first, then each drop-in in
name order, so separate tools can manage separate concerns. Lists are
combined, and a value a later file sets replaces an earlier one.
A policy a user could edit isn’t a policy. Each file and the folders holding it must be owned by root, or on Windows by the administrators, and writable by nobody else, or zelk refuses to start and says why. It also refuses a file that isn’t valid JSON or holds a value it can’t use. A missing file means no policy, and a key zelk doesn’t know is skipped with a warning. Policy comes from local files only; zelk doesn’t fetch one from a server.
How it combines with yours
Section titled “How it combines with yours”The policy always wins. A setting you never chose is moved inside the policy without comment. One you chose is overridden with a warning naming both values and the policy file:
-sandbox none overridden: the policy at /etc/zelk/policy.json requires a sandbox; commands run under bwrapWarnings appear as a notice in the terminal UI, on standard error from
zelk exec and zelk -p, and in zelk acp’s log. In the UI, a setting the
policy sets shows “· policy” and can’t be changed.
Rules work differently, because they combine instead of being replaced.
The policy’s rules join yours and the project’s. Under rules_only, every
allow rule but the policy’s is dropped, yours and the project’s included,
and so are the allow rules a skill would grant. Their deny, ask and human
rules still apply, since those can only narrow.
A project’s allow rules wait for your trust. Its deny, ask and human rules
apply at once, since a repository can only make zelk more careful. Its allow
rules apply once you’ve trusted that exact file for that workspace. Trust is
recorded against the file’s content hash, so editing the file makes it
untrusted again. The terminal UI asks at start, and zelk project trust
records it for the other hosts, which otherwise skip the allow rules with
one warning. .zelk/ is a protected path, so the agent can’t edit its own
project rules without a person.
Modes it can forbid
Section titled “Modes it can forbid”modes holds for every way a mode can change: -mode, the terminal UI’s
saved start mode, Shift+Tab, approving a plan, an editor’s set_mode over
ACP, and subagents. Leaving out bypass and auto is the usual reason to
set it.
A mode outside the list becomes the first mode the policy lists. A script
that passed -mode bypass may then find commands refused that no one is
there to approve, and the warning on standard error says why. Core itself
refuses a mode change the session’s policy doesn’t authorize, so even a host
that forgets to filter its menu can’t reach a forbidden mode.
What a session records
Section titled “What a session records”A session records the permission policy it started under: its mode, the modes it may switch to, its rules and protected paths, and whether skills may grant tools. Rules are recorded as written, without the layer or file they came from. Every decision also records the rule or step that made it, so the log shows what ran and why.
Replay never consults the current policy: a rule changed since doesn’t
change which calls an old session ran. To see who set what, run zelk policy,
which prints the files read, the limits in force and the file that set each.
When the policy changes
Section titled “When the policy changes”zelk reads the policy once, when it starts. A running process doesn’t notice an edit, and the next start does. A session you resume takes the policy in force at that launch, whenever the session began:
- An idle session records a configuration change with its new setup.
- A session interrupted mid-run, or waiting for an answer, takes the policy’s
permissions too. A session started in
bypasscan’t keepbypassunder a policy that forbids it. - Allow rules you granted with “always allow” are kept, but a deny rule of the launch still overrides them. Any change to the policy raises its revision, so an approval waiting under the old one is decided again.
Inside a running session, a switch to a mode the policy doesn’t list is refused and nothing is recorded.
Where credentials are kept
Section titled “Where credentials are kept”zelk keeps four credential documents in its config directory,
~/.config/zelk: the ChatGPT sign-in, MCP servers’ OAuth clients and tokens,
the pairing key for the browser extension, and API keys typed into
Providers…. By default each is a file only you can read. A key written as
$NAME isn’t stored at all: zelk reads the variable each time.
With credential_store: keychain, set by a flag, the settings or a policy,
new documents go to the system keychain instead: the Secret Service on Linux
(GNOME Keyring, KWallet, KeePassXC), the login keychain on macOS and the
Credential Manager on Windows. The file then holds only a small marker naming the keychain item. Nothing moves by
itself: zelk credentials move -to keychain moves what exists. And nothing
falls back: where no keychain can be used, saving fails and says why.
The default stays the file because a keychain isn’t reachable from every session: a desktop sign-in would be unusable over SSH on the same machine.
A policy can require the keychain, and then a document still in a plain file
is refused, a literal key in providers.json included, until it is moved.
It can’t forbid the keychain: no organisation needs to stop a user making
credentials safer.
How a credential reaches its service
Section titled “How a credential reaches its service”A provider key lives in memory only while zelk uses it. The provider client sets it as a header on each request. It isn’t part of the history the model reads, and the session log records the provider and the model, not the key: no field of the logged configuration could hold one. Model requests don’t follow redirects, so a key can’t be forwarded to another origin.
Commands the model writes get an allowlisted environment: PATH, HOME,
the locale and a few more, plus names the host lists. A key in
ANTHROPIC_API_KEY doesn’t reach env or echo, so the model can’t read it
by running a command.
An MCP server’s OAuth token is added by the transport, only to requests for
that server’s own origin, only over HTTPS or loopback, and never over an
Authorization header the request brings itself. It renews the token a
minute before it expires, under the document’s lock, so a rotating refresh
token is never used twice. The log records which servers a session was
offered, with their names and instructions, and no tokens.
The keychain may prompt you to unlock it or to trust zelk. Only commands you
run yourself may show one, such as the terminal UI and zelk credentials.
zelk -p, zelk exec and zelk acp never prompt: if the keychain is
locked or refuses, they fail and name the command to run.
What it doesn’t protect
Section titled “What it doesn’t protect”A keychain keeps secrets out of files, backups and anything that reads
~/.config. It doesn’t hide them from everything.
- Commands outside a sandbox can reach an unlocked keychain, as any of
your programs can. On macOS and on Windows a command can even run
zelk credentials move -to file. A sandbox closes this: seatbelt denies the keychain, MXC denies the Credential Manager, and bwrap cuts the command off from the session bus, unless the network isfulland the bus is an abstract socket, or the bus socket lies under a path the sandbox binds. zelk warns at start in those two cases. - zelk itself holds the secret in memory while it uses it.
- Old backups taken before a move still hold the plain files.
What stays on the machine is the policy, the markers and keychain items, and zelk’s own state. A secret leaves only for the service it signs in to: a provider key for the endpoint you configured, an MCP token for its own server.
Where to go deeper
Section titled “Where to go deeper”The managed policy guide and the credentials guide show the commands in use. The managed policy contract says how each limit is enforced; the keychain contract covers markers, locking and what each crash leaves.
See permissions and sandboxing and enforcement for what a policy limits, and MCP for the servers whose tokens are kept here.