Skip to content

Your agent logs keep your keys

Matt Waite

An agent's log keeps what the agent saw. If it opened a .env file or printed a token to check it, that token is now in a plain-text file in your home folder. Every other agent you run can read that file, and it stays there until the log is deleted.

In November, Apiiro reported 2,539 secrets in 1,994 public GitHub repositories, including files where Claude Code saves the commands you approved with "Yes, and don't ask again" (Privacy Guides). A secret in an approved command is saved in that file, and the file can end up committed. That's the public version. The private version is on most of our Macs.

Where keys end up

  1. Session logs. Claude Code's in ~/.claude/projects/, Codex's in ~/.codex/sessions/. What a command printed and what a file read returned are both in there.
  2. Saved approvals. When you choose "Yes, and don't ask again", Claude Code saves that command as a rule in the project's .claude/settings.local.json. A key in the command is saved with it.
  3. Your shell's startup files. A key exported in ~/.zshrc is in the environment of every agent you start from Terminal.
  4. Project .env files. Readable by any agent working in that folder.
  5. Scripts agents wrote. A key pasted into a quick script stays in the script.

Find them without printing them

Run these in your own Terminal. If you ask an agent to search for your keys, every key it finds goes into its conversation, and from there to its provider.

Logs. This counts the log files that hold a key in a common format, and prints no key:

grep -rlE 'sk-ant-[A-Za-z0-9_-]{20,}|sk-proj-[A-Za-z0-9_-]{20,}|sk-or-v1-[a-f0-9]{32,}|AKIA[0-9A-Z]{16}|ghp_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9_]{22,}|glpat-[A-Za-z0-9_-]{20,}|xox[abp]-[A-Za-z0-9-]{10,}|sk_live_[A-Za-z0-9]{24,}' ~/.claude/projects ~/.codex/sessions | wc -l

Drop the | wc -l to see which files. The pattern covers common formats from Anthropic, OpenAI, OpenRouter, AWS, GitHub, GitLab, Slack and Stripe. It won't catch a generic password.

Saved approvals. Point this at the folder where your projects live (here ~/Sites). It lists each settings.local.json that looks like it holds a key, a token or a password:

find ~/Sites -path '*/.claude/settings.local.json' -not -path '*/node_modules/*' \
  -exec grep -lE 'sk-ant-|sk-proj-|sk-or-v1-|AKIA[0-9A-Z]{16}|ghp_|github_pat_|glpat-|xox[abp]-|sk_live_|Bearer |password|token=' {} +

Then check git isn't carrying it. In that project, this prints the path only if git tracks the file:

git ls-files .claude/settings.local.json

Claude Code adds the file to your global git ignore list when it first writes it. A file you made by hand, or one a repo was already tracking, isn't covered.

Startup files. The names of the keys you export, never the values:

grep -hoE '^[[:space:]]*export [A-Z0-9_]*(KEY|TOKEN|SECRET)[A-Z0-9_]*' ~/.zshrc ~/.zshenv ~/.zprofile ~/.bash_profile 2>/dev/null

What to do, in this order

  1. Replace the key at the provider first. Taking a key out of a file doesn't make it safe. Anything that read the file may already have it, and the key keeps working until you cancel it there.
  2. Then clear the copies. Edit the line out of settings.local.json. Delete the old session logs you don't need. You can't resume a session whose log you deleted.
  3. Then make it harder next time. Keep keys out of the folders agents work in. Don't choose "don't ask again" on a command with a secret in it. And give Claude Code a rule it can't talk its way around.

Give Claude Code this

In ~/.claude/settings.json, this stops Claude Code's file tools reading any .env file in the folder you start it in or below, and turns on its macOS sandbox so those paths, plus your AWS credentials, are closed to shell commands too:

{
  "permissions": {
    "deny": ["Read(.env)", "Read(.env.*)"]
  },
  "sandbox": {
    "enabled": true,
    "allowUnsandboxedCommands": false,
    "filesystem": { "denyRead": ["~/.aws/credentials"] }
  }
}

Claude Code adds your Read(...) deny rules to the sandbox's list of paths commands can't read. The sandbox is off unless you turn it on, and on a Mac it uses the system's own sandbox, so a blocked path stays blocked however a command is worded. allowUnsandboxedCommands: false matters: by default Claude can retry a blocked command outside the sandbox. Some tasks may stop working, so try it in one project first. The settings reference has the rest.

What Excellent does here

Keys in your shell's startup files, your .env files and your tools' settings are open to every agent. Excellent for Mac finds them, says who can read each one and whether it has already reached a model, and opens the provider's page so you can replace it. It keeps a fingerprint of each key, never the key.

It also finds keys sitting in your agents' logs and can remove them. That can't be undone, and the app says so before you confirm. With Excellent Pro's check on, it blocks an API key typed into a command and asks before an agent reads a key file, a .env file or a token from your keychain. The keys doc has the details.

The app is almost here. The free scan counts the keys in your plain-text logs today, without showing them to your agent. For the rest of what your logs hold, see Check what your AI agent actually did.

Get new research by email. Each new study and analysis, with the data behind it, plus occasional product news. We confirm your address first; unsubscribe anytime.

We use your address only for the Excellent newsletter. The privacy policy has the rest.

Citation

Please cite this work as:

Matt Waite, “Your agent logs keep your keys”, Excellent Research, November 18, 2026. www.excellent.so/research/your-agent-logs-keep-your-keys

Or use the BibTeX citation:

@article{excellent2026youragentlogskeepyourkeys,
  author = {Matt Waite},
  title = {Your agent logs keep your keys},
  journal = {Excellent Research},
  year = {2026},
  url = {https://www.excellent.so/research/your-agent-logs-keep-your-keys}
}