---
title: "Give an AI agent part of a repo"
url: https://docs.loot.build/guides/agent-keys
group: "Guides"
status: written
summary: "One command, one variable: a forge key scoped by path, held by the forge and by which keys it is given."
---

# Give an AI agent part of a repo

> One command, one variable: a forge key scoped by path, held by the forge and by which keys it is given.

An agent key gives an AI agent part of a forge repo: what it may read and where its changes may write, by path. The limit holds twice. The forge refuses what the agent may not do, and the agent never holds the keys to what it may not read.

## Add one

From a repo whose remote is a forge, as its owner. Scopes are files or directories, comma-separated, never globs; `.` is the whole tree. The write scope must lie inside the read scope, and an agent with no `--write` only reads.

```bash
loot agent add reviewer --read src,docs --write src
# registered agent reviewer (…) on https://forge.loot.build/k/…/site, reading .lootattributes, src, docs and writing src
#   its read scope gains .lootattributes: an agent seals what it writes by those rules
#   deposited 214 key(s) to agent reviewer — it reads them beside the ciphertext its scope covers
# LOOT_AGENT_KEY=loot-agent1.…
#   shown once and kept nowhere: put it in the agent's environment now
```

The line is the agent’s private key and the repo it works, in one variable. Nothing keeps a copy, so paste it into the agent’s environment or secret store at once. To keep the key off this machine entirely, mint it where the agent runs and register only its public half; then no secret is printed anywhere:

```bash
# where the agent runs, in any directory; <repo-url> is the repo's
# forge address, as loot remote list prints it
loot keygen --key-file agent.env <repo-url>
# it prints the public key; then in the repo, as its owner:
loot agent add reviewer --read src,docs --write src --pubkey <public-key>
```

`agent.env` holds `LOOT_AGENT_KEY=<line>`, readable by you alone. Load it into the agent’s environment, or pass `--key-file agent.env` to the agent’s verbs.

A script should not scrape the key out of that text, or leave it in a captured log. `--key-file <file>` writes `LOOT_AGENT_KEY=<line>` to a new file only you can read and prints no secret; it refuses a path that already exists. `--json` prints one object whose `key` field is the line, or `null` when a key file took it.

Before it registers anything, `agent add` says how many paths the read scope reaches and names any Restricted ones. A read scope that reaches a Restricted path is refused with `restricted_scope` and nothing is registered: narrow `--read` to leave those paths out, or pass `--allow-restricted` if you mean to give the agent their keys. `agent scope` asks the same on every rewrite.

## Give the key to the agent

`LOOT_AGENT_KEY` is read by the agent’s client. There are three, and each takes the one variable and nothing else, because the line names the forge and the repo:

- **The `loot` binary**, for an agent with a shell, outside any repo:

```bash
loot agent self
loot agent files     # each path: open, no_key_yet or out_of_scope
loot agent cat src/a.rs
loot agent propose -m "a returns one" src/a.rs
```

`propose` offers the named files, read from the current directory, as a new proposal. Each takes `--json`.

- **The SDK**, `@lootbuild/sdk`, for an agent written in TypeScript:

```bash
import { connectForge } from "@lootbuild/sdk";

const repo = await connectForge(process.env.LOOT_AGENT_KEY!);
```

- **The MCP server**, `@lootbuild/mcp`, for an agent that speaks MCP over stdio, such as Claude Code:

```bash
{
  "mcpServers": {
    "loot": {
      "command": "npx",
      "args": ["-y", "@lootbuild/mcp"],
      "env": { "LOOT_AGENT_KEY": "loot-agent1.…" }
    }
  }
}
```

Neither package is on npm yet, so today the binary is the client a plain install has.

## What the agent can do

- **Read** the repo’s heads and every change’s node, and the content of the files its read scope covers, once it holds their keys.
- **Propose** changes that write only inside its write scope. A deletion counts as a write. The forge refuses anything else, naming the path, and it never lets an agent move `main`.
- **Nothing more**: no push, no decline, no runner or pipeline act, and no setting of the owner’s.

Every agent change is a proposal that a person lands: `loot propose --list` shows them, and `loot propose --take <version>` takes one. In your repo it folds the proposal onto your line, and `loot push` lands it. In a lane it waits until `loot pull-grants` in the primary has taken the keys the agent handed you, then brings the lane onto it to review and land like any contribution.

## The two layers

**The forge refuses.** It admits the agent’s key on the row you signed, and only while the key that registered it is still a live key of your account. A write outside the write scope is refused at the upload, and no ciphertext outside the read scope is served.

**The keys are not there.** The forge holds ciphertext it cannot open, so an agent with permission and no keys reads nothing. Each push from your machines deposits to every live agent the keys its read scope covers, sealed to the agent’s key. A compromised forge, a leaked database or a hijacked agent runtime still has no key to anything outside the scope.

A push never fails over deposits. When an agent is still owed keys, say because a machine without them pushed, the push names it and `loot agent list` counts it; `loot agent deposit` pays it from a machine that holds them.

## Change or end it

```bash
loot agent list                       # scopes, last seen, keys still owed
loot agent scope reviewer --read . --write src   # widen: the new keys are deposited
loot agent retire reviewer            # for good: the forge admits the key nowhere
```

A narrowing stops the forge serving the ciphertext outside the new scope at once, but it cannot take back a key already deposited: a key is not a row. For a clean cut, retire the agent and add a new key.

## What is not scoped

Names. A change’s node rides whole, because its id covers its whole tree, so an agent, like the forge, sees every path, commit message and author in the repo, out of scope included. Scope narrows content, not names. If a path name is itself a secret, an agent key does not hide it.

loot’s cryptography has not yet been independently reviewed. [The trust matrix](https://loot.build/trust) says what each party can read.
