3.1.0-beta.10). Features may change before the next stable release.Switch to stable →Guides
Using the secrets vault
Store API keys and tokens in the AgentKit secrets vault, let agents use them by reference, answer approvals, and audit every release.
ak secrets keeps small named values, such as API
keys, tokens, and certificates, in the OS keychain or an age-encrypted vault
file. Coding agents use a value through a ${secret:NAME} reference instead of
an unmanaged .env file or a shell export. This guide explains how the
commands fit together; each command's page has the full flags, defaults, and
exit codes. The Desktop app has its own Secrets page.
A grant trusts the agent with the value
The vault organizes and audits access. It does not seal a value away from an agent you granted it to. Read Limits before you grant a secret.
Commands
| Task | Command |
|---|---|
| Store or replace a value | ak secrets set, ak secrets rotate |
| See what is stored (never the value) | ak secrets list, ak secrets get |
| Describe a secret so it can be found | ak secrets annotate |
| Find a secret by its metadata | ak secrets search |
| Read one secret's profile and provenance (never the value) | ak secrets describe |
| Remove a value | ak secrets delete |
Move a .env file into the vault | ak secrets import-env |
| Let an agent read a secret | ak secrets grant |
| Ask for access ahead of use (agents) | ak secrets request |
| Answer requests agents left waiting | ak secrets approve |
| See or remove grants | ak secrets grants, ak secrets revoke |
| Run one program with a secret in its environment | ak secrets run |
| Point one name at one of several secrets | ak secrets alias |
| Check or re-pin an agent's binary | ak secrets trust |
| Read the access ledger | ak secrets audit |
| Inventory the vault | ak secrets export |
| Manage the file backend's vault and recovery keys | ak secrets recovery |
| Sync the vault across your devices (preview) | ak secrets sync, ak secrets devices; see Cloud sync |
Values are read from --value=- (stdin), --value-file, or a non-echoing
prompt, never from a literal flag value that would land in shell history.
ak secrets get prints [redacted] unless you pass --reveal in a terminal.
A secret's name (its ref) cannot contain /, a NUL byte, a control character,
a bidi override or isolate, or a line separator. ak secrets list and the
approval prompt print the name as written, so such a character could make it
read as a different name. A name stored by an earlier version stays readable,
but cannot be rotated or approved; move its value to a plain name with
ak secrets set, then delete the old one.
Choose a backend
| Backend | Use it when | Agents can resolve |
|---|---|---|
| Keychain (default) | The host has a working OS keychain: macOS Keychain, Windows Credential Manager, or a Secret Service on Linux | Yes |
| File | The host has no usable keychain | No: the vault passphrase is read only from a terminal, so an agent resolve fails (exit 7) |
| Memory | Tests and demos; nothing persists | Process-local only |
The backend comes from --backend, then AGENTKIT_SECRETS_BACKEND, then
backend in the secrets section of $AGENTKIT_HOME/config.yaml, and
otherwise the keychain. A host config that selects the file backend therefore
makes every agent resolve fail, even though no flag says so. Use the keychain
on any host where agents need secrets; the file backend suits a vault only you
read from a terminal.
Each AgentKit home keeps its keychain values under a service of its own,
recorded in $AGENTKIT_HOME/secrets/index.keychain.json before the home's first
secrets write, so a second home for the same OS user cannot read or overwrite
the first home's values. A home that already held secrets from an earlier
version keeps the shared service, so an upgrade moves nothing. Keep
index.keychain.json with index.json when you move or restore a home. An
older ak or Desktop app cannot see the values of a home that recorded its own
service, so use one version per home.
The OS keychain may ask you to allow access the first time ak reads an item,
or after an upgrade changes the binary. That prompt is the keychain's own
access control.
Set up the file backend
ak secrets recovery init --label <label> # create the vault and one recovery key
ak secrets recovery add <age-public-key> --label <label> # enroll another recovery key
ak secrets recovery listrecovery init shows the recovery private key once and stores it nowhere.
Keep it where the host cannot reach it: if you lose the passphrase and every
recovery key, nobody can open the vault. If you forget the passphrase, run a
vault-reading command with --unlock-with-recovery in a terminal, paste the
recovery key, and choose a new passphrase. If sync was set up on this home,
its device keys no longer open after that, even with the same passphrase:
synced secrets are refused until you set the device up again with
ak secrets sync disable --purge, then ak secrets devices add or
ak secrets sync recover. On a synced home, a current AgentKit also rewrites
the sync keystore, and an older AgentKit on the same home then refuses it.
The host remembers the newest vault version it has seen. If the vault on disk
is older (restored from a backup or synced over by a stale copy), commands that
open it fail. Find out why first; to keep the older vault anyway, run
ak secrets recovery accept-rollback.
Writes made after that older copy are lost.
Let agents use a secret
An agent writes a reference into a tool call:
curl -H "Authorization: Bearer ${secret:NAME}" <url>The core Kit's secrets-inject PreToolUse Hook substitutes the value in memory
just before the tool runs. In Claude Code it scans only the Bash and
PowerShell commands and the WebFetch URL. For each reference it runs ak secrets resolve, which
identifies the calling agent by walking the process tree and hashing the
agent's binary; the caller is never taken from a flag. Any failure blocks the
tool call rather than passing the literal reference on.
When ak run starts a Codex or Grok agent, ${secret:NAME} references in the
environment it passes to that agent are resolved the same way, and the run
stops if a value cannot be released.
A resolve succeeds only when a grant matches four fields: the secret, the
project, the agent's binary fingerprint, and the purpose. An empty purpose is a
literal value, not a wildcard, and a block outranks any allow on the same
scope. Get an agent's fingerprint from
ak secrets trust <adapter> --json or from a
waiting request.
ak secrets grant --allow-host <host> restricts an allow to WebFetch URLs
aimed at the listed hosts. A restricted grant refuses any release whose
destination the Hook cannot check, including every Bash or PowerShell
reference. The
restriction applies to the Hook's own substitution path only; see
ak secrets grant for the exact matching
rules.
Answer approvals
When no grant covers a resolve, it does not prompt. It fails closed (exit 8)
and leaves a request for you. Answer it with
ak secrets approve in your own terminal,
or in the approval inbox on the Desktop Secrets page:
| Answer | Effect |
|---|---|
| Deny | Refuses this request and stores nothing; the next resolve asks again |
| Allow once | Releases the secret exactly once |
| Allow for a while | An allow that expires on its own: 24 hours by default in the CLI (--ttl changes it); 15 minutes, 1 hour (default), or 8 hours in Desktop |
| Always allow (allow until revoked) | An allow with no expiry |
When an allow on the same secret exists but does not answer the call, the
refusal names the fields that nearest allow differs in: agent, project,
purpose, scope, exec env, exec program or exec hash. When the scope
matches exactly but a synced policy set the allow aside, it names
policy max ttl or policy fresh allow-once instead. A resolve, a run, and
ak secrets request report it, and the
audit ledger row keeps only the field names, as in mismatch:agent,exec-hash.
It never includes a value.
An agent that keeps asking without a grant is rate-limited per fingerprint and then held in a cool-down (exit 9). A job under a standing grant never reaches the limit.
grant and approve refuse to run (exit 6) when an agent sits above them in
the process tree, and Desktop refuses an answer when an agent started the app.
This stops an agent from approving its own request in the obvious way; it is a
speed bump, not a boundary.
Run approve in a terminal you opened yourself. A command typed through a
coding agent's shell, including Claude Code's ! prefix, still runs under the
agent and is refused.
For a job with several steps (for example an upload followed by a few API
calls), have the agent request every ref the job needs before the first step,
then answer them in one approve session with allow for a while (t in the
CLI prompt). Allow once covers a single run, so the next step would block again.
A grant matches one ref, project, purpose and agent, and for
ak secrets run also one program and environment variable, so the agent
requests each ref once for every program and variable a step uses it with.
With sync on, you can also answer from another of your devices; see Answer a request from another device.
Ask for access ahead of use
An agent that has chosen a credential with ak secrets search and
ak secrets describe can ask for it before using it:
ak secrets request <ref> --purpose "<why it is needed>"
ak secrets request <ref> --exec <program> --env <VAR> # an exec scope for ak secrets runThe request waits in the same inbox a refused resolve files into, for you to
answer with ak secrets approve. A request never reads or releases a value,
never writes a grant, and never spends an allow-once; only your answer grants
anything. It identifies the agent the way resolve does and is refused (exit 6)
when no agent can be named. Repeated requests for one scope are one inbox
entry, and an agent that asks too often is held in its cool-down (exit 9). It
exits 0 when the request is waiting, or when a grant already covers the scope.
Nothing in a secret's profile decides a request: it is answered only by a grant
on exactly the scope it names.
Revoke
ak secrets revoke <ref> --agent sha256:<hash> # one scope, allow or block
ak secrets revoke --agent sha256:<hash> --all # every grant that binary holdsRevoking stops future reads. It does not recall a value the agent already read, so rotate the secret after a panic revoke.
After a release
A released value reaches the tool's process and arguments, and the runtime may
record the executed call, value included, in its session transcript. AgentKit
keeps only a hash and a length of each released value, in release manifests
under $AGENTKIT_HOME/diagnostics/manifests/. Two commands use them to remove
released values later:
ak diagnostics exportremoves them from a support bundle when it can read the manifests.ak sessions redactfinds them in registered Claude Code session files. It is a dry run unless you pass--apply --yes, and it backs up before rewriting.
Run a program with a secret
ak secrets run starts one program with secrets delivered only in the
environment variables --env names:
ak secrets run --env VAR=REF [--env VAR=REF ...] -- <program> [args...]It serves a coding agent. It names the caller the way ak secrets resolve
does, by walking the process tree and hashing the agent's binary, and refuses
(exit 6) when no caller can be named.
Exec grants
Each VAR=REF pair needs an exec grant for the calling agent on exactly this
program: its path with every symlink resolved, and its content hash. Grant one,
or let the agent ask for one with ak secrets request:
ak secrets grant <ref> --agent sha256:<hash> --exec <program> --env <VAR>
ak secrets request <ref> --exec <program> --env <VAR>--exec takes the program by name on PATH or by path, and needs --env. A
program found elsewhere on PATH, or changed since the grant (an upgrade
changes its hash), matches no grant. Each scope nothing covers is filed for
ak secrets approve, and the run exits 8;
narrow the inbox to exec requests with ak secrets approve --env <VAR>. An
ordinary grant never releases here, and an exec grant never releases to
resolve or the inject Hook.
Every scope is checked, and the program hashed again, before any value is read,
so a run a grant check refuses spends no allow-once. If the program still
cannot start after its values were released, the ledger records that it never
started. A REF with no stored value that names an alias
follows it one hop, and the exec grant is checked against the alias's target.
How the program runs
- No shell. The program is started directly, so nothing in its arguments is expanded. Shells and launchers are refused, and so are variables that steer a loader, a runtime or a network endpoint.
- A rebuilt environment. A few variables are copied from
run's own (home, user, locale, terminal, temp dir),PATHis a fixed list of system directories, and the granted variables are added; nothing else, proxies and runtime options included. A program that runs a helper installed outside the system directories must name it by path. - Struck output. The program's output is relayed with every granted value,
and its escaped forms, struck out. The last few bytes are held back until the
program writes more or exits, so a prompt without a newline can appear late.
Output goes to pipes, not a terminal, and
--jsonis not supported. - Signals and exit. Ctrl-C reaches the program from the terminal, and
SIGTERM and SIGHUP are passed on to it.
akwaits for it to exit and never kills it. The program's exit status isrun's (128 plus the signal number if a signal ended it).ak's own failures always print an error startingsecrets run:.
ak secrets run --help lists every exit code.
What an exec grant does not bound
An exec grant bounds which program gets a value, not what the program does with it:
- The program can send the value anywhere, write it to a file, or pass it to a child of its own.
- Arguments are not part of the scope. An interpreter runs whatever script it
is given, and a program such as
curl,wgetorghcan be told by its arguments to send a variable anywhere or to run another program. - Any process of the same user can read the program's environment while it runs.
Grant exec scopes only to programs you would hand the value to yourself. See Limits.
Aliases: one name, several accounts
When you keep one key per account, point a single name at the one you want and switch with one command:
ak secrets alias set CLAUDE_API_KEY CLAUDE_API_KEY_1 # pick account 1
ak secrets alias set CLAUDE_API_KEY CLAUDE_API_KEY_2 # switch to account 2
ak secrets alias list
ak secrets alias unset CLAUDE_API_KEY # the secret itself is untouchedA ${secret:CLAUDE_API_KEY} reference, and the REF of
ak secrets run --env VAR=CLAUDE_API_KEY, then reach whichever secret the
alias points at. The rules:
- A stored secret wins. The alias is used only when no secret of that name is stored.
- One hop. A target that is itself an alias, or that has no stored value, is refused as a missing secret (exit 3). The target does not have to exist when you set the alias; a missing one is a warning, so you can set an alias up before a sync brings the value in.
- An alias grants nothing. Grants, approvals and audit rows name the
target, so grant
CLAUDE_API_KEY_1, notCLAUDE_API_KEY. The audit row records the alias asalias:CLAUDE_API_KEY.
Aliases hold names only and live in $AGENTKIT_HOME/secrets/aliases.json. They
are device-local and not synced: the vault sync carries values, and which
account a machine uses stays that machine's choice.
Because aliases are not synced, a vault member can push a secret whose name is
one of your aliases. From the pull that brings it in, that name releases the
member's secret, not your alias target. No grant widens: the target's grant does
not cover that secret, so a release still waits for an approval. The sync cycle
that starts this reports alias_shadowed under needs attention,
ak secrets alias list marks the alias as shadowed, and ak secrets approve
and the Desktop approval dialog warn on such a request. Deny it unless you
expected that secret, then move the alias to a name of its own.
Describe and find secrets
Each secret can carry an optional profile of searchable metadata: description,
projects, environment, provider, account, tags, and fields that help an agent
choose a credential, such as when to use it. Set it with
ak secrets annotate, then find and inspect secrets without opening a value:
ak secrets annotate <ref> --provider stripe --environment production --tag billing
ak secrets search stripe --environment production --json
ak secrets describe <ref> --jsonak secrets describe <ref> shows everything the index records about one
secret: its profile with each field's origin, writer and time, its source, and
its rotation state. It is the step after ak secrets search, for choosing
between candidate credentials. Both read only the on-disk index: they never
open the backend, never read or print a value, and never prompt. --json adds
untrustedFields, the fields this device's operator did not write, and a fixed
notice.
Profile text is untrusted data, never an instruction. It grants nothing, and a usage host or a listed permission restricts nothing: grants, approvals and resolve never read the profile.
Provenance and profile sync
Each profile field records where it came from as {value, origin, by, at}:
origin | The text was written by |
|---|---|
local | The operator of this device |
import | A directory import, inferred from file and directory names |
sync | Another vault device; by names its device ID and at the time of its record |
Treat a field whose origin is not local as untrusted.
With cloud sync on, the profile travels with the secret,
encrypted like the value. A field you change on one device arrives on the
others with origin sync, and each device keeps its own fields as local.
Each device checks that a field it pulls was written by the device it names; a
field that fails the check is dropped and audited as
profile_provenance_invalid. The import source stays on the device and does
not sync. A device on an older ak build carries no profile.
Rotate
Each secret has a rotation window: 90 days by default, or the value you pass
with ak secrets set <ref> --rotate-ttl <days>d. ak secrets list flags
secrets past their window. Replace a value with ak secrets rotate <ref>; it
fails if the ref does not exist, so a typo does not create a new secret.
Audit releases
Every resolve with an identifiable caller writes one row to the secrets_audit
ledger, for a release and a refusal alike, before any value is returned. A row
records the ref, project, fingerprint, label, purpose, decision, source,
session, error code, and context, never a value. For a WebFetch reference,
the destination host is added to the context. A Desktop reveal requires a
reason, recorded the same way.
Read the ledger with ak secrets audit or on
the Desktop Audit log page. The ledger is kept until you change its
retention with ak data retention --class secrets_audit.
While Desktop is open, each release also shows an in-app notice with a Revoke this agent's grants button, and raises an OS notification titled Secret released while the window is unattended. Neither carries the value; see the Secrets page.
Export
ak secrets export --json # inventory on stdout, no values
ak secrets export --out ./inventory.json # the same, as a file only you can read
ak secrets export --include-values --out ./values.age # confirms, then writes an age-encrypted fileThe default export contains no values. --include-values needs an interactive
terminal and an --out path ending in .age; values never go to stdout. It
asks you to confirm and to choose a passphrase, and nothing on the host keeps
that passphrase, so losing it loses the export. Decrypt with the stock age
CLI, for example age --decrypt values.age | jq ., and treat any decrypted
file like the secrets it contains.
Move from .env
ak secrets import-env <path> # skips keys that already exist
ak secrets import-env <path> --force # overwrites them insteadThe command reports only counts, never values, and reads at most 1 MiB. Then
grant the agents that need each key, change the commands to use
${secret:NAME}, and remove the .env file.
Cloud sync
The vault lives on one host. An opt-in, end-to-end encrypted sync is in
development as ak-vault. Its first stage, sync
across one owner's own devices, is an experimental preview. ak secrets --help
lists it as ak secrets sync with a
(preview) label. Run ak secrets sync status --json to see,
without contacting the server, whether this device already syncs and whether
your sign-in can. The production sync service runs it under
owner waivers, and its security review was the owner's, not an independent
third party's. Sync is pre-release, not generally available, and not yet
recommended for production credentials. Sharing with teammates and CI is not
built yet. The ak-vault
release gates
track its status.
The design keeps the local vault as the source of truth:
- Each device encrypts a secret's name, value, creator, timestamps and rotation interval before upload, so the sync server stores and relays only ciphertext and cannot read a secret. A secret's profile travels encrypted the same way. Grants, trust pins, approvals and the release audit stay on the device.
- Membership changes are signed by the vault owner and hash-chained, so the server cannot add a reader or hide a removal.
- Concurrent edits are kept as conflicts to resolve, never silently overwritten, and a deleted secret cannot be brought back by a stale device.
- A device keeps its own grants: a synced policy can only narrow what an agent may read, never widen it. When a policy requires approval, or the synced record marks the secret high sensitivity, only an allow-once answered in the last 10 minutes releases it; a standing or older allow is set aside.
The protocol and its threat model are public.
With sync enabled, CLI writes such as set, rotate, annotate, delete and import-env queue a background push for an OS-backed vault after the local write succeeds. Pass --no-push for one write or set AGENTKIT_SECRETS_AUTO_PUSH=0 to opt out. The file backend needs a manual sync. If a push does not finish, the change stays queued.
Run ak secrets sync now to push and pull immediately. It honors the server's
Retry-After for up to 15 minutes in total. Use --watch to keep syncing and poll for
remote changes:
ak secrets sync now --watch # keep syncing until interrupted
ak secrets sync now --watch --relay # also answer AI tools connected over remote MCP--watch sends local changes within seconds. It checks the server every
--interval (1 minute by default) while the device has been active in the last
10 minutes (a local change, a sync that pulled or pushed something, or a call from
an AI tool over --relay), and every 5 minutes otherwise. A change made on another
device therefore arrives within about a minute while you work, and within about
5 minutes on an idle device. Each wait varies by up to 10% so devices do not poll
at the same moment.
Once sync is set up on this home, the Desktop app's Secrets page shows the same local state read-only (see Check vault sync).
Turning sync on with ak secrets sync enable under an API-key sign-in creates
a vault with no recovery bundle, so it cannot be recovered if every device is
lost. Seal the first bundle from an email sign-in with
ak secrets sync rotate-recovery. Every step that issues a new recovery key
also rotates the vault's recovery signing key, so an earlier recovery key, or a
copy of the bundle it opened, can no longer sign a new device into the vault.
Answer a request from another device
With sync on, a resolve that no grant covers also sends a sealed, signed request to your account's other devices. The request carries the secret name, project, agent and purpose, never a value. Answer it from any other device that is a human owner or editor, instead of walking back to the machine that asked:
ak secrets approvals list # pending requests from your other devices
ak secrets approvals approve <id> # release once
ak secrets approvals approve <id> --ttl 2h # release for a while
ak secrets approvals deny <id><id> can be a unique prefix of the request id. An id that starts with -
goes after --, as in ak secrets approvals deny -- -r_nM. Without --ttl,
approve allows one release; with it, the allow lasts that long, up to what the
request accepts (24 hours by default). list shows the name, project, agent,
purpose, the device that asked and when the request expires; a request that
fails a local check is left out and counted as skipped.
- Your device signs the answer. The requesting device checks the signature against the vault's membership before it records a grant. A deny, an expiry or any failed check leaves the secret refused.
- The first answer wins. Answering with
ak secrets approveon the device that asked withdraws the remote request, and an answer given elsewhere clears the local inbox entry. A request already answered, withdrawn or expired exits3. approverefuses under an agent. Likeak secrets approve, it exits6when an agent is among its parent processes, so run it in a terminal you opened yourself.denyhas no such guard.- Not every device can answer. A machine device or a reader exits
6(approver_not_allowed) before anything is sent. - Where else. The vault dashboard can answer a request, but an AI tool connected over remote MCP can only deny it or hand you a link to answer; it cannot approve.
If sync is off, the vault uses the file backend, or the server does not serve
remote approvals, nothing is sent and the request waits in the local inbox for
ak secrets approve. --json prints the result as a JSON envelope.
Browser dashboard and AI tools (staging)
Two pre-release features build on sync. Both run on staging only and are not for production credentials:
- Use the vault from a browser: enrol a browser as a device and manage secrets in the vault dashboard, which never reveals a value.
- Connect an AI tool to the vault: let Claude
Code, Claude.ai, ChatGPT, Cursor or VS Code reach your secrets over remote
MCP, through a device of yours running
--watch --relay.
Remote MCP narrows one guarantee: the server still stores no plaintext and holds no key, but a remote MCP call is not end-to-end encrypted, because plaintext passes through the server's memory after TLS ends. The remote MCP page says exactly what passes through.
Limits
These are deliberate boundaries of this version:
- A grant trusts the agent's model with the plaintext. A prompt-injected
agent can send a granted value to any host that
--allow-hostdoes not exclude. An unrestricted grant relies on the runtime's permission prompt, andAGENTKIT_SECRETS_INJECT_AUTO_ALLOW=1removes that prompt. Codex cannot ask from a Hook, so on Codex a reference is denied until you set that variable in the environment that starts Codex. - No wall after injection. Once a value is in a child process, its environment, or a transcript, AgentKit cannot contain it. Redaction and rotation are the remedies.
- Self-approval refusal is a speed bump. An agent running as your user can detach from the process tree or edit the grants file directly.
- Keychain access control is the OS's. Any process running as your user that the keychain lets in can read an item.
- Memory attackers. Anyone who can read the memory of
ak, the Hook, or the tool process can read the value while it is in use. - Static windows. Grant and rotation windows are fixed durations.