Inside agentwhy, part 3: hiding a key before your AI reads it
Part 2 ended with the routes the shell check leaves open, and one that no check of a command can close: a key in a file nobody named. Blocking needs a name. .env has one. A Stripe key pasted into config/payments.yml mont
Part 2 ended with the routes the shell check leaves open, and one that no check of a command can close: a key in a file nobody named. Blocking needs a name. .env has one. A Stripe key pasted into config/payments.yml months ago, a token in a test fixture, a key in a log your AI tails: none of them is on your list, and none of them will be.
This part is the layer for that file. It doesn't block the read. It changes what the read hands back.
A stand-in where the key was
With hiding keys on, agentwhy looks at what each tool returned, after the tool ran and before your AI reads it. A key it recognises is swapped for a stand-in:
# config/payments.yml, on your disk
stripe:
secret_key: sk_live_…
# what your AI reads
stripe:
secret_key: [redacted by agentwhy]
Your file stays as it is. Only the copy your AI gets is changed.
In Claude Code it is a PostToolUse hook, agentwhy hide-keys, and it covers every tool's result: a file read, a command's output, an MCP tool's answer, a helper's report back to your AI. That last one matters for the incident this series started from: a helper's answer is how part of a secret came back into my chat in September.
The risk a stand-in brings
Your AI reads [redacted by agentwhy] where a key was. Then you ask it to change something in that file. If it writes the file back from what it read, the stand-in goes into your config and the real key is gone.
So the AI is told, next to the result, that the real value is still in the file and that it should not write the stand-in into it. It changes the file around the key instead. Your key stays where it was, and your AI never saw it.
Turning it on
npx @agentwhy/cli init --hide-keys
Or one switch in Settings. A project you set up on agentwhy's welcome page has it on already, and the same switch turns it off.
It runs on every step your AI takes, so it has a cost. Through npx that is about half a second a step. Installed and run directly, about 35 ms.
In Codex
The same switch also adds a hook to your own ~/.codex and approves it. Codex then hides a key in what a shell command printed, in the projects where the switch is on, after a command that failed too.
It works differently there. Codex can't change only part of a result, so the whole result comes back as an error that holds the output with the key swapped. Codex's AI reads it as an error. The key itself stays in Codex's own record of the command, and Codex's terminal shows you the last lines of a command that failed, key included.
What it misses
It knows the keys of common services by their shape. So these still get through:
- A key of a format it doesn't recognise, and a password of no known format.
- Part of a key, or a key that is encoded or split.
- In Claude Code, the output of a command that failed.
- A file you attach to a message yourself.
- Anything in Copilot.
It lowers the risk. It doesn't remove it. A key your AI never had to read, because it lives in a secret manager and not in a file, is still the stronger fix. This is for the files you haven't got to yet.
Try it
Turn it on in a project you work in, and keep working as you do. Don't go looking for a real key to test it on: if the key is of a format it doesn't know, your AI reads it whole. The next time your AI opens a file with a key it recognises, it reads the stand-in, and npx @agentwhy/cli shows the conversation in the report.
Next week, part 4: when you paste the key yourself.
Which file in your projects holds a key that no rule of yours names?
Disclosure: I build agentwhy, the open-source tool this post describes.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.