agent-secret

Keep secrets out of your agent's chat.

Encrypt an API key in this tab and hand your agent one link. It lands in the agent's .env, not in the transcript, and the server only ever holds ciphertext it cannot open.

Claimable for

Encrypted here before anything is sent. See exactly how

What happens to a key you paste into an agent chat

You paste sk-live-… into the chat, the agent writes it to .env, and the job looks done. The key, though, is now in a lot more places than .env.

Where it ends up

Most coding agents keep a transcript on disk. Claude Code, for example, writes every session to a JSONL file under ~/.claude/projects, and those files sit there for weeks unless someone cleans them up. The key is in that file verbatim: once in the message you sent, and often again in the tool call that wrote it to disk.

It also went to the model provider as part of the prompt, and it rides along in the context for every turn that follows. Providers keep request logs for a retention period that depends on the provider and your plan. When a long session is compacted, the summary can carry the key into the next one. And if the agent confirms its work with a cheerful "Set OPENAI_API_KEY=sk-live-…", that is one more copy.

Then there is everything around the chat: terminal scrollback, a screen share, a synced folder where someone saved the transcript, a bug report with the log attached. None of these is a breach on its own. Together they mean a key you meant to put in one file now lives in six, and you can't list them all.

What a one-time link changes

agent-secret moves the value out of the conversation. You paste the secret into this page, your browser encrypts it with a fresh 256-bit AES key, and the server stores only the ciphertext. What you hand the agent is a link whose last part, after the #, is that key. Browsers, curl and fetch never send the fragment, so the server could not decrypt what it holds even if it wanted to.

The transcript still gets the link. The difference is what the link is worth afterwards. The first GET returns the ciphertext and replaces the record with a tombstone, so by the time anyone reads that transcript the link answers 410 and there is nothing behind it. A link nobody claims expires on its own, after anything from five minutes to a day.

How your agent claims it

The copy block is two lines: a short instruction and the link. The instruction points the agent at /how, a static plain-text page with the protocol. It never touches a stored secret, so the agent can read it as often as it likes. The agent then splits the link at #, makes one GET for the ciphertext, decrypts locally and writes the value to its environment or a gitignored .env. It should report back by name only: "saved OPENAI_API_KEY". The exact steps, response codes and copyable scripts are under For AI agents.

The threat model, in plain words

Until it is claimed, the link is the secret. Anyone who sees it first can claim it, and your agent then gets a 410. That failure is loud on purpose: when the claim fails, rotate the key.

The server can't read your secret, but it does see when a link was created and claimed, from which IP, and roughly how long the secret is. You also trust that the page you loaded is the page in the repository. Its one script is pinned by hash in the Content-Security-Policy so you can check it, or you can run your own copy. And the agent sees the plaintext, because it has to in order to use the key. This keeps the secret out of the transcript, not out of the agent's machine.

How it works

Every link has two halves. Only the first one ever reaches the server.

Sent to the server

agent-secret.xndr.io/k7f2-9m3q

A random code. It finds the ciphertext, and the first read burns it.

Never sent

#Q2xvc2VkIGJ5IGRlZmF1bHQuIE9wZW4gYnkgY2hvaWNl

The 256-bit key. Browsers, curl and fetch drop everything after # before the request. This one was just made in your tab.

The whole trip

  1. Your browser makes a random 256-bit key and encrypts the secret with AES-256-GCM, using its built-in WebCrypto. Read those lines.
  2. It sends the server only the ciphertext, the nonce and the expiry. No key, no name. That request.
  3. The server stores them in Cloudflare KV under a random code and returns the code. Your tab puts the key after a # in the link.
  4. Your agent GETs the link. The server sees only the code, returns the ciphertext once and overwrites the record with a tombstone in the same request.
  5. The agent decrypts locally with the key from the fragment. A second GET gets 410. Unclaimed links expire after 5 minutes to 24 hours.

Who sees what

Your tabServerAgentLink previews
The secretyesnoyesno
The keyyesnoyesno
Ciphertextyesyesyesno
Variable nameyesnoyesno
IP and timingn/ayesn/an/a
The server also learns the ciphertext length: the secret's length plus 16 bytes. Link previews are the Slack, Telegram, Discord and similar bots that fetch a pasted URL. They are recognised by User-Agent and get a short note instead of the ciphertext, so a preview does not burn the link.

What it does not protect against

  • The link is the secret until it is claimed. Anyone who sees the whole link first can claim it. Your agent then gets 410, which is your cue to rotate the secret.
  • Single use is best effort. Workers KV has no compare-and-set, so two claims racing within KV's propagation window (up to about a minute between regions) can both succeed. A Durable Object would make it strict; this version does not use one.
  • Previews do not burn, and do not warn. A recognised preview bot never consumes the link, so it also cannot tell you someone pasted it somewhere. A bot that is not recognised will burn it, though it still cannot decrypt anything.
  • You trust the page you load. A compromised server could serve a script that sends the key elsewhere. Compare the script hash below with the source, or run your own copy.
  • Your agent sees the plaintext. That is the point. This keeps the secret out of the chat transcript, not out of the agent's machine. An agent that prints it puts it back in the transcript.

Check it yourself

  • Read the code. View this page's source: one inline script, no external files, no trackers. The server is app.ts, about 200 lines.
  • Watch the network tab. Create a test secret. The one POST carries ct, iv and ttl, nothing else.
  • Read the headers. The Content-Security-Policy lets exactly one script run, by hash: sha256-U1P2B8k8zVeqxY2wMm3K7hon6XB8mMLMa6+jsMXWKn4=. connect-src 'self' means the page cannot talk to any other origin.
  • Run your own. One Cloudflare Worker and one KV namespace, no server secrets. Deploy your own in three commands.

For AI agents

If you were given a link like agent-secret.xndr.io/k7f2-9m3q#…, this is the whole protocol. Plain-text copy: agent-secret.xndr.io/llms.txt.

  1. Split the link at #. The part before is the URL, the part after is the key. Never send the key anywhere.
  2. GET the URL once, with a User-Agent of your own, such as agent-secret-client/1.0. That read burns the secret.
  3. Decrypt with AES-256-GCM. Key: base64url-decode the fragment (32 bytes). Nonce: base64-decode iv (12 bytes). Input: base64-decode ct, ciphertext with the 16-byte tag appended. The UTF-8 plaintext is the value, nothing wrapped around it.
  4. Write it straight to an environment variable, a gitignored .env or a secret manager.
  5. Never print, log or repeat the value. Confirm by name only: "saved OPENAI_API_KEY to .env".

Responses

200
{"ct","iv"}, both base64. Claimed; the secret is now burned.
410
already_claimed or expired. Ask the human to rotate the secret and send a new link.
404
not_found: wrong code, or expired and purged.
403
Plain text error code: 1010: Cloudflare refused a library default User-Agent such as Python-urllib before the request reached the service. Nothing was claimed; retry with your own.
429
rate_limited. Wait a minute.

curl + node

LINK='PASTE-THE-LINK-HERE'   # https://<host>/<code>#<key>
NAME=OPENAI_API_KEY          # the variable the value should land in
curl -sS -A 'agent-secret-client/1.0' "${LINK%%#*}" |
KEY="${LINK#*#}" NAME="$NAME" node -e '
const r = JSON.parse(require("fs").readFileSync(0, "utf8"));
if (!r.ct) throw new Error("claim failed: " + (r.error || "no ciphertext"));
const c = Buffer.from(r.ct, "base64");
const d = require("crypto").createDecipheriv("aes-256-gcm",
  Buffer.from(process.env.KEY, "base64url"), Buffer.from(r.iv, "base64"));
d.setAuthTag(c.subarray(-16));
const v = Buffer.concat([d.update(c.subarray(0, -16)), d.final()]).toString("utf8");
require("fs").appendFileSync(".env", process.env.NAME + "=" + v + "\n");
console.log("saved " + process.env.NAME + " to .env");'

Python

# pip install cryptography
import base64, json, urllib.request
from cryptography.hazmat.primitives.ciphers.aead import AESGCM

LINK = "PASTE-THE-LINK-HERE"   # https://<host>/<code>#<key>
NAME = "OPENAI_API_KEY"        # the variable the value should land in

url, key = LINK.split("#", 1)
req = urllib.request.Request(url, headers={"User-Agent": "agent-secret-client/1.0"})
with urllib.request.urlopen(req) as res:   # raises HTTPError on 403/404/410/429
    body = json.load(res)
value = AESGCM(base64.urlsafe_b64decode(key + "=" * (-len(key) % 4))).decrypt(
    base64.b64decode(body["iv"]), base64.b64decode(body["ct"]), None
).decode("utf-8")
with open(".env", "a", encoding="utf-8") as f:
    f.write(f"{NAME}={value}\n")
print(f"saved {NAME} to .env")

Both append to .env in the current directory and print only the name. Check that .env is gitignored. After the claim, the link left in the transcript is dead: the server no longer holds the ciphertext.

Where it fits next to the tools you already use

agent-secret does one job: it gets a value from you to an agent once, without the value passing through the chat. It is not a place to keep secrets, and it doesn't try to be.

Password managers

1Password, Bitwarden and the like are where the key should live. Some can feed an agent directly; the 1Password CLI, for instance, injects secrets into a process with op run. If the agent's machine is already signed in, use that. The one-time link covers the gap: the agent runs on a server, in a container or on a colleague's laptop, and setting up a vault there for one key is more work than the key is worth.

.env files

A gitignored .env is usually where the value ends up, and that is fine. The file was never the problem. The problem was how the value travelled to it. A one-time link replaces the copy and paste, not the file.

Secret managers and vaults

HashiCorp Vault, Doppler, Infisical and the cloud providers' secret managers handle rotation, access policies and audit logs for a team. That is the right home for production credentials. They assume the consumer can already authenticate to them, which an agent you started five minutes ago usually can't. Hand over the first token, or a short-lived one, with a link, and let the secret manager take it from there.

Questions

Can agent-secret read my secret?

No. Your browser encrypts the value before anything is sent, and the key stays in the part of the link after the #, which browsers and HTTP clients never transmit. The server stores ciphertext and a nonce. A full copy of its database would not decrypt anything.

What if someone opens the link before my agent does?

They get the secret, and your agent gets a 410 when it tries. Treat that as a leak: rotate the key and send a new link. Pick the shortest expiry that works, so the window stays small.

Will a link preview in Slack or Telegram burn the link?

No. Known preview bots, including Slack, Telegram, Discord, WhatsApp and LinkedIn, get a short note instead of the ciphertext and leave the secret in place. A crawler that is not on that list would burn it, though it still could not decrypt it.

Which agents can use it?

Any agent that can make an HTTP request and run AES-256-GCM. In practice that is anything with a shell and curl plus Node or Python, which covers Claude Code, Codex, Cursor and most self-hosted agents. The protocol is plain text at /how.

How long does a link last?

Between 5 minutes and 24 hours, chosen when you create it, and only until the first claim. After a claim the server keeps a small tombstone until the original expiry, so a second attempt gets a clear 410 rather than a confusing 404.

Is it free, and can I run my own?

It is free, needs no account and is MIT licensed. Your own copy is one Cloudflare Worker and one KV namespace, with no server secrets to configure. The README has the three commands.