secrets
ak secrets grant
Let a fingerprinted agent binary read a secret
Use ak secrets grant for the operation described below. The command help records its arguments, effects, and options.
Grant across git worktrees
From AgentKit CLI v3.2.0-beta.12, add --repo to grant access for the same
project path in every worktree of a repository. The grant prints its repo: slot.
An unsupported checkout or a project outside git exits 2. See the
vault guide
for repository scope and restrictions.
Command contract
Let a fingerprinted agent binary read a secret
Synopsis
Record that one agent binary may read one secret. A grant is keyed by four fields — secret, project, binary fingerprint, and purpose — and all four must match for it to apply; an empty --purpose is a literal value, not a wildcard. Only the fingerprint carries authority: it is the hash of the caller's executable file, not the adapter's name and not whether it was pinned.
--agent takes that fingerprint as sha256:<64 hex>, or the name of an adapter pinned with ak secrets trust (--agent claude), which is resolved once, now, to the pin's fingerprint and stored as that hash; the name is kept only as the default --agent-label. The pin is the fingerprint ak secrets resolve and ak secrets run verify the calling agent against, so the grant matches that agent until it is re-pinned (ak secrets run also needs --exec and --env). An adapter with no pin is refused. Often no grant is needed at all: the agent's ak secrets run or ak secrets resolve files a request, and ak secrets approve answers it.
--project defaults to the AK project containing the current directory; an explicit path resolves to the root of the AK project that contains it, and "default" names the shared slot. Two git worktrees of one repository are two projects, so grants do not carry between them unless you opt in with --repo, and any directory outside an AK project falls into the shared "default" slot — there the scope is effectively secret, binary, and purpose alone for every such directory on the machine.
An allow expires after 24h unless --ttl or --persist says otherwise. --block records a refusal that outranks every allow on the same scope and never expires unless --ttl asks it to; clearing it takes an explicit ak secrets revoke. --once records an allow good for a single release, kept beside any standing allow on the same scope; it is the only allow a synced vault policy that needs a fresh approval accepts, and only within 10 minutes of being recorded.
A grant trusts the agent's model with the plaintext: the model can run the same binary that resolves ${secret:NAME}, so it can read any value it is granted. Grant only what that agent should hold, and rotate a secret it no longer needs.
--repo records the grant on the repository-wide slot instead ("repo:<git dir>", plus "#<path>" for an AK project below the worktree's top level): the same AK project in every git worktree of the repository matches it, so one approval covers them all. That is wider on purpose — it also covers code on branches nobody has reviewed yet, checked out in any worktree — so it is opt-in, the output says so, and every release it answers is still audited under the caller's own worktree. A block on either slot outranks an allow on the other, and an --allow-host list on either binds both. An --exec program is pinned by its absolute path, so a program inside one worktree does not carry to the others. --repo is refused outside a git repository, and for a linked worktree whose git directory does not point back at it.
--allow-host restricts an allow to specific destinations: a WebFetch.url that resolves a secret reference must target one of the given hosts (or host:port), matched exactly and case-insensitively after normalization — a default :443 or :80 port and one trailing dot are stripped, and an internationalized name is converted to its ASCII form — with no wildcards. Only the port is normalized this way, not the scheme: an http:// URL to a host matches a :443 (or port-less) list entry exactly as an https:// URL does. It is repeatable and comma-separated. The check runs inside ak secrets resolve itself: it governs what the inject hook substitutes and what resolve releases when it is told the destination, but it does not follow the caller — nothing stops a model from invoking ak secrets resolve itself with a self-asserted --dest-host. The hook sends no --dest-host for a Bash.command reference (a shell command line names no single destination to check), a WebFetch.url it could not parse a host out of, or one where a reference sits inside the host, port, or userinfo itself; an unrestricted grant still resolves and substitutes every one of these exactly as it did before this flag existed, while a restricted grant refuses all of them outright, never raised for approval, even under AGENTKIT_SECRETS_INJECT_AUTO_ALLOW. A grant recorded with no --allow-host places no destination restriction, matching today's behavior. Granting a scope that already carries an --allow-host list — including approving a pending request for it, allow-once included — never drops hosts from it on its own; only an --allow-host on the new grant replaces the list. Revoke the scope first (ak secrets revoke) to lift a restriction entirely. --allow-host is rejected on --block: a block already refuses every destination.
--exec with --env records an exec scope: the secret is released only by ak secrets run, only in that environment variable, and only to the program --exec names, pinned by its resolved path and content hash. Upgrading the program changes the hash and the grant stops matching. An exec grant and an ordinary grant never answer for each other, and an ordinary --block also refuses every exec scope on the secret for that agent. Shells and launchers, by file name or by a script's #! line, are refused, as is any variable that steers a loader, a runtime or a network endpoint. Arguments are not part of the scope: whatever the program is told to run gets the value too, and a grant to an interpreter covers every script it is asked to run; the output says so. --allow-host is rejected with --exec.
Effects: Writes one allow or block row into the grants file under AGENTKIT_HOME, replacing any earlier row with the same four-field scope and state. An allow and a block on one scope are kept side by side, and the block wins. Recording an allow also compacts grants whose expiry has passed. Stored secret values are not read or changed.
Exit status: 0 success 2 invalid flags, fingerprint or unpinned adapter, ttl, allow-host, exec program, env name, or grant, or --repo outside a git repository 5 the grant or trust file could not be read or written 6 an agent adapter is above this process, or the check for one failed; an agent may not grant itself access
ak secrets grant <ref> [flags]Examples
ak secrets grant ${REF} --agent claude # 24h allow for the pinned claude binary (resolve)
ak secrets grant ${REF} --agent sha256:${HASH} --repo # every worktree of this repository
ak secrets grant ${REF} --agent sha256:${HASH} --block # refuse, outranks allows, no expiry
ak secrets grant ${REF} --agent claude --exec ${PROGRAM} --env ${VAR} # only into one programOptions
--agent string Agent to match: a pinned adapter name such as claude, or its full sha256:<64 hex> fingerprint (required)
--agent-label string Display name for the fingerprint (defaults to the adapter --agent names); cosmetic, never matched against
--allow-host strings Destination host (or host:port) this allow may reach; repeatable or comma-separated, no wildcards, rejected on --block
--block Record a block instead of an allow
--env string Environment variable the program receives the secret in (needs --exec)
--exec string Program the secret is granted for, by name on PATH or by path; makes this an exec scope (needs --env)
-h, --help help for grant
--json Emit machine-readable JSON (implies --no-interactive)
--no-interactive Disable interactive prompts (CI-safe)
--once Record an allow good for one release
--persist Record a grant with no expiry
--project string Project slot; defaults to the AK project containing the current directory
--purpose string Free-text purpose label; matched literally
-q, --quiet Suppress non-error output on stderr
--repo Record on the repository-wide slot so every git worktree of this repository matches (opt-in, wider scope)
--ttl string How long the grant lives, e.g. 12h, 30d, 2w (allows default to 24h; blocks never expire)
-V, --verbose Extra diagnostic output on stderr (loses to --quiet)
-y, --yes Assume yes for all promptsSEE ALSO
- ak secrets - Manage named secret values (API keys, tokens)