An agent that runs scripts needs keys: an OpenAI key, a Stripe test key, a token for a deploy. The quick way is to paste the key into the chat, or to leave it in a .env file next to the code. Both put the value in places it doesn’t need to be.
A pasted key becomes part of the conversation. It’s in the transcript, in whatever your agent’s host keeps, and in front of the model on every turn after. A .env file is plain text that every tool the agent runs can read, and it’s one git add . away from a repository.
Most of the time the agent doesn’t need to see the key at all. A program needs to have it.
Keep the key out of the conversation
aFile keeps a secret encrypted for the agent and gives it to one command at a time, in that command’s environment. Install the CLI and connect once:
npm i -g @afile/cli
afile connectafile connect registers the agent with no account and makes its key on this machine. Then save the key as a secret. The value comes only from standard input, so it never sits on a command line or in your shell history:
printf %s "$OPENAI_API_KEY" | afile secret OPENAI_API_KEYOutput
Saved secret OPENAI_API_KEY.
Use it without showing it: afile run --secret OPENAI_API_KEY -- <command>Typed in a terminal with nothing piped in, afile secret OPENAI_API_KEY asks for the value and doesn’t echo it.
Run the program with the key
afile run --secret OPENAI_API_KEY -- python agent.pyThe CLI decrypts the secret on this machine and sets OPENAI_API_KEY in the environment of python agent.py, and of nothing else. It prints nothing about the value, and it exits with the command’s exit code. Give --secret once for each key a program needs.
Lists show names, never values:
afile secretsOutput
OPENAI_API_KEY version 1 · changed 29 Nov 19:19
Secrets print only with get. Prefer afile run so the value never enters the conversation.Tell your agent how
The aFile skill tells an agent to read a secret only from standard input, to keep values off the command line and out of chat, and to use afile run. Add it to the agents on your computer:
afile addOr to one of them, with afile add -a claude-code or afile add -a codex. After that you can ask in plain words:
Save the OpenAI key in key.txt as a secret, then delete the file.
An agent that uses aFile over MCP can’t read a secret at all. The get_item tool refuses and points to afile run.
What this protects, and what it doesn’t
- The value is encrypted on your machine, with a key that stays there, before it’s uploaded. aFile stores only ciphertext, and it can’t read the secret’s name either.
- Saving the same name again keeps a new version. The one before stays for 30 days, so a wrong paste can be undone.
- It isn’t a sandbox. An agent that can run
afilecan also runafile get OPENAI_API_KEY, which writes the value to a pipe or a file, or prints it in a terminal after you confirm. The skill tells the agent not to unless you ask. What changes is the default: the key isn’t in the chat, the transcript or a file in the project unless someone takes it out on purpose. - The program you run does get the key, as it would from
.env. Run programs you trust with it. - Keep a copy of the agent’s own key with
afile key --export --out afile-key.json. Without it, nobody can open the secrets again, aFile included.
Questions people ask
Where does the CLI keep its own token?
In ~/.config/afile/credentials.json, readable only by you. Set AFILE_CONFIG_DIR to keep a second agent, with its own secrets, on the same machine.
Can I use the same secrets on another machine?
Yes. Export the agent’s key with afile key --export --out afile-key.json, copy the file over, and run afile connect --restore afile-key.json there. The file holds the agent’s token too, so keep it as you would a password.
Does this replace a team’s secrets manager?
No. It’s for the keys one agent uses: kept encrypted, out of the conversation, and handed to the programs it runs.