Giving AI agents my secrets without leaving the password manager
An agent's shell doesn't see what I export in my terminal, so how should it get a token?
My coding agents, Claude Code and opencode, get secrets through rbw, a Bitwarden client that holds the unlocked vault the way ssh-agent holds keys. Nothing moves out of Bitwarden, and the vault locks itself after a timeout. Getting there meant unlearning how my shell used to load secrets.
Why the simple route fails
My shell used to load secrets into environment variables. An agent’s commands don’t run in my terminal, though. Every tool call starts a fresh, non-interactive shell that only sees the environment the agent started with. Export a variable afterwards and it lands in my shell, not the agent’s.
Two things made this confusing. An export made before I launched the agent does reach it, so the broken flow sometimes worked. And my zsh helper functions never load in an agent’s shell, because non-interactive shells skip .zshrc. Agents can’t call zsh functions. They need an executable.
What I compared
I looked at four options: rbw (an unofficial Bitwarden client), the official bw CLI with a saved session, gopass, and Bitwarden Secrets Manager. The official bw CLI works, but its sessions never time out, so an unlocked vault stays unlocked forever. The last two meant moving secrets out of my Bitwarden vault, and I wanted everything important to stay there.
rbw won. I unlock it once with a password prompt, and it locks itself again after a timeout.
The wrapper
Agents call a small script, bwget, inside the command that needs the secret:
SOME_API_TOKEN=$(bwget SOME_API_TOKEN) some-command
It looks the variable up in a file that maps names to Bitwarden items, checks rbw unlocked, and fetches the item. It’s a script rather than a shell function so agent shells can run it.
The unlock check matters. An agent can’t type my password, but if it asks a locked rbw for a secret, rbw opens a password window on my screen anyway. So bwget fails fast with “vault locked” and I unlock it myself.
The catch
While the vault is unlocked, any process running as you can read any item in it.
gpg-agent and ssh-agent work the same way. The lock timeout is the only real boundary.
The mapping file is a convenience, not a fence: an agent that can run rbw get can fetch anything.
rbw locks after an hour by default, and I would keep it short. For real isolation, rbw supports profiles (RBW_PROFILE), each with its own vault, so agents could get one that holds only their secrets.
Never print a secret, because command output ends up in transcripts. I learned that the hard way. ${VAR:+SET}${VAR:-UNSET} looks safe, but when the variable is set, :+ prints SET and :- prints the value right after it. That put a token in a transcript. Test without expanding the value:
[ -n "$SOME_API_TOKEN" ] && echo set
Terms of use
rbw is open source and unofficial: Bitwarden flags its logins as bots unless you run rbw register with your personal API key, and it doesn’t support passkey or Duo two-factor login. Anything an agent reads may go to its provider under that provider’s terms.
Where it ended up
Solved, at a price: my agents fetch secrets through bwget and everything important stays in Bitwarden, but while the vault is unlocked, they can read all of it.
