Secret management for coding agents: every key needs a reason
On a typical setup, any agent session can read every API key its skills use, and nothing records which one did. How I set keys up for agents, and bouncer, an open-source store that logs who asked and why.
Updated
Tags: ai · agents · tools · security · open-source
On this page
Coding agents use API keys all day. On a typical setup, the skills they run read those keys from the OS keychain or the environment, so any agent session can read any of them. If a token were used for something it shouldn't have been, nothing would say which of that day's sessions had fetched it, or what it was working on.
When I set up a Linux VM that only runs agents, I wanted that record. The requirement was easy to say: agents can pull the tokens they need, but they have to give a reason, and every fetch is logged with a timestamp so I can see which session pulled which token and why.
That became bouncer, a small secret store I've open-sourced under the MIT licence. The way I run it, nothing judges the reason: any agent that gives one gets the key, and the fetch goes in the log. On the Linux VM it runs as its own user, so agents can't read the vault without root. On a Mac it can only record the agents that ask. Either way it's only useful once the keys themselves are in order, so that's where I started.
Where agents find credentials
On a developer's machine, an agent can usually pick up credentials from four places:
- Environment variables exported by a shell profile, which every process the agent starts inherits, and
.envfiles it can simply read. - The OS keychain. On a Mac, a skill can read it with
security find-generic-password. - CLI logins. Tools like
gh,vercelandstripekeep a reusable login for your user, often in a file under your home directory. - The browser, through its signed-in sessions and whatever a password manager will fill in.
By default, none of these records which agent session read what.
There are two separate problems here. One is an agent that has been hijacked by something it read and sends a key somewhere else. The other is not knowing what your own agents do with the access you gave them. A credential proxy helps with the first for HTTP APIs, because the agent never holds the key. The second is the one I wanted to solve.
Sort out the keys first
Before copying anything to the new machine, I had an agent go through each service's dashboard and list the keys that already existed: names, permissions and last-used dates, never the values. Anything unused was deleted, and anything broader than it needed to be was replaced with a narrower key.
The new machine then got keys of its own:
- I created new keys for it and named them after the machine. Each can be revoked from the service's dashboard without touching my laptop, and the name says where it's used.
- Each key is scoped to what agents do. A deploy token can publish a site and still have no access to DNS or billing.
- Agents are kept away from anything I couldn't afford to lose. My object-storage key covers a working bucket and none of the backup buckets, because an agent's mistake there could delete the backups.
- API tokens replaced CLI logins. A login file can be read without asking anyone, while a token can be fetched at the moment a command runs. I also no longer have to keep signing CLIs back in.
- Where the service allows it, a token only works from a fixed IP address.
The agents' browser got the same treatment. Agents drive it, so a saved password would autofill for them, and an unlocked password manager would hand over every login in it. A managed Chrome policy turns off browser sign-in, Sync, the built-in password manager and autofill, and blocks every extension apart from an ad blocker. "Sign in with Google" still works in a tab. I've written separately about which browsers I give agents.
What already exists
I looked for something to install before building anything.
| Project | What it does | How it differs from what I wanted |
|---|---|---|
| Agent Vault, from Infisical | An HTTP proxy that attaches the credential to each outgoing request, so the agent never holds it, and logs the traffic | It works for HTTP APIs, so it doesn't cover a mailbox password or a database connection. The standalone open-source version now points new setups to Infisical's platform |
| credential-broker | Runs a command with secrets in its environment and redacts them from the output. Requests carry a reason, and the log records the process tree that asked | A person approves each grant with a YubiKey, Touch ID or a passphrase. I wanted tokens released with nobody at the desk |
| agent-secrets | A local daemon with age-encrypted secrets, leases that expire, an audit log and a killswitch | Requests don't carry a reason |
I wanted three things together: the agent session named on every request, a copy of the log kept off the machine, and nobody having to approve each fetch. I didn't find that combination, so I built it.
How bouncer works
bouncer is a single Rust binary of about 2.6 MB. A daemon keeps the vault decrypted in memory, and agents talk to it over a Unix socket:
bouncer get GITHUB_TOKEN --reason "list open PRs on the docs repo"
bouncer exec --reason "publish release 1.4.2 to npm" NPM_TOKEN -- npm publishget prints the value, and refuses without a reason of at least eight characters. exec is the one I tell agents to prefer. It runs the command with the secret in its environment and replaces the value with [REDACTED:1] wherever it appears in the command's output, so an exact copy of the key doesn't land in the agent's transcript.
For every request, the daemon asks the kernel which process is on the other end of the socket. It then walks up the process tree from that caller to pid 1 and records each executable and its arguments. Agent harnesses put a session ID in the environment, and bouncer looks for the ones Claude Code and Codex set, and for T3 Code's T3CODE_THREAD_ID. (T3 Code calls a session a thread, which is why the log's filter is --thread.) It takes the value from the oldest ancestor that has one and notes any different value set further down the tree.
Here's a get entry, shortened from the README. An exec entry has the same fields:
{"ts":"2026-11-17T10:42:07.318Z","seq":42,"op":"get","names":["GITHUB_TOKEN"],
"reason":"push the docs fix branch and open a PR","decision":"allow",
"attribution":{"cwd":"/home/me/src/docs",
"context":{"CLAUDE_CODE_SESSION_ID":{"value":"6d1f0c2e-...","pid":47990}},
"chain":[{"exe":"/usr/local/bin/bouncer","argv":"bouncer get GITHUB_TOKEN ..."},
{"exe":"/usr/bin/bash","argv":"/bin/bash -c bouncer get GITHUB_TOKEN ..."},
{"exe":"/home/me/.local/bin/claude","argv":"claude"}]},
"prev":"9c1e4b...","mac":"03f9fe..."}Each entry carries a MAC, computed with a key derived from the vault key, and the MAC of the entry before it. Editing or reordering entries, or removing one from the middle, breaks verification. Entries cut off the end are the exception. bouncer notices if the cut goes back past a change to the vault, but not if only the latest reads are missing, which is why the log is also copied off the machine.
bouncer log --thread <id> lists everything one session pulled.
Locally, a fetch through the CLI takes about 2 ms on an Apple M-series laptop, including the process walk and the audit write. Copies to other destinations are sent afterwards, so a request never waits for the network.
Keep the log out of the agents' reach
Runs as my login
Agent session
A skill or command needs a token
- asks, with a reason
Runs as its own user
bouncer
Checks the reason, identifies the caller and writes the log entry before it releases anything
- releases the value
Runs as my login
The command
Gets the token in its environment
On the VM
Audit log
Owned by the bouncer user, so reading or editing it takes root
- copies each entry
Off the machine
Bucket with Object Lock
One object per entry, kept for a year
Run under your own login, bouncer records what well-behaved agents did. Anything running as you can read the key file and the vault and skip the socket altogether. That's how it runs on a Mac, which has no stronger mode.
On the Linux VM it runs in dedicated-user mode. The daemon runs as a bouncer system user that owns the vault, the key and the log, and the vault key is a systemd credential that's stored encrypted on disk. My agents run as my login. Without root they can reach the socket and ask, but they can't read those files or inspect the daemon's memory.
That boundary doesn't hold against root. Anything with root can read the key directly, and with the key it could rewrite the log. To read the log myself, I run bouncer log as the bouncer user.
What root on the VM can't change is a copy that has already left it. Each entry is uploaded to an S3-compatible bucket with Object Lock and a year's retention. bouncer can send entries to InfluxDB, a webhook, a second file or syslog as well.
What the reviews changed
A coding agent wrote the first version, and I then had two other models, Fable 5.2 and GPT-6 Astra, review it as adversaries over two rounds. That isn't a security audit, and bouncer hasn't had an independent one. The fixes are behaviour I'd now look for in any store like this:
- Clients check who owns the socket before sending anything, so another user can't plant one.
- A change to the vault is logged before it takes effect.
- If an audit write fails, bouncer stops releasing secrets until the log is repaired, and it remembers that across a restart.
- A vault rolled back to an older copy is detected at start-up, and so is a log cut back past a change.
- Overlapping secret values are fully redacted from
execoutput.
What it doesn't protect against
bouncer is young software, and its licence disclaims any warranty. Root, a same-login setup and a log with its tail cut off are covered above. It has three more limits:
- An agent can give a misleading reason, and bouncer records whatever it wrote.
- Once a value is released, bouncer has no say over what the command does with it.
execredacts exact matches in the output, so it misses a value that has been encoded, written to a file or sent over the network. - A session ID can be faked. The process and user IDs come from the kernel, but session variables come from process environments, which are set by whatever starts a process.
If your worry is a hijacked agent sending a key to someone else, you want the proxy model, where the agent never holds the key.
An LLM on the door
The name comes from where I'd like this to go: a model that checks the reason at the door. bouncer has an optional admission check that sends a model the request and the caller's details, and gets back allow or deny with its reasoning, which goes into the log and back to the agent. I have it switched off, because a model can be talked round by a well-written reason and it adds its response time to every fetch.
Trying it
cargo install --git https://github.com/Smidge/bouncer
bouncer init
bouncer serve &
bouncer set GITHUB_TOKEN --desc "GitHub PAT, repo scope"set prompts for the value with echo off, so the token doesn't pass through your shell history or an exported variable. This runs bouncer under your own login, so it's a record of what agents asked for and nothing stronger. The README has the dedicated-user setup for Linux.
Then tell your agents about it. This is the README's snippet for CLAUDE.md or AGENTS.md:
## Secrets
Get credentials from `bouncer`, never from files, shell history or other projects.
- Prefer `bouncer exec --reason "<why>" NAME -- <command>`, which puts the secret in the
command's environment and redacts it from the output.
- If you need the value itself: `bouncer get NAME --reason "<why>"`.
- `bouncer ls` lists the available names.
- The reason is required and is logged with your session ID. Name the task, not the
secret: "deploy docs site to staging", not "need token".
- Do not print, echo or write secret values to files, commits or messages.Start with one token you can rotate easily and leave your agents to work for a day, then read bouncer log --tail 20. If the reasons say "need token", tighten the instruction until they name the task.
Share this post
Related reading
Hill climbing with AI judges: getting coding agents past their first build
I have AI judges blind-score my agents' work against a rubric, round after round. Here's the loop, a run that climbed from 7.5 to 8.0, and where judges mislead.
Parallel coding agents on one MacBook with T3 Code
Run T3 Code on one MacBook with two Claude accounts and four models, reach it from your phone over Tailscale, and cut each agent's background processes so more of them fit in memory.