Skip to content

AI agents leak keys, rewrite main and skip your checks

Matt Waite

Coding agents leak keys into logs and commits. They force-push over main. They skip your git hooks to get a commit through. They delete folders you needed. And they break the rule you wrote, because you wrote it for the other agent.

None of this needs a rogue agent, or a careless person running it. Agents run hundreds of steps faster than anyone can watch, and nothing stops the bad ones by default. Each one has a fix you can turn on today, and most of the fixes live outside the agent.

1. Keys leak

An agent that opens a .env file or prints a token puts that key in its log, in plain text, in your home folder. An agent that types a key into a command you approve with "Yes, and don't ask again" saves it in the project's .claude/settings.local.json. In November, Apiiro reported 2,539 secrets in 1,994 public GitHub repositories, including files where Claude Code saves those approvals (Privacy Guides).

And a key the agent can read, it can use. In April, a coding agent working on PocketOS found an API token in an unrelated file and used it to delete the company's production database and its backups; Railway later restored the data (The Register, Apr 27, 2026).

What stops it: close the key files to the agent where the operating system enforces it. In Claude Code, a Read deny rule plus its macOS sandbox does that. Your agent logs keep your keys has the settings to paste, and how to find the keys already sitting in your logs without printing them.

2. Main gets rewritten

"Make origin's main match my local main" is a reasonable thing to ask. The agent's answer is git push --force, and a teammate's commit is gone.

What stops it: the git server, not the agent. Turn on branch protection for main on GitHub or GitLab and block force pushes. A rule in CLAUDE.md asks the agent not to; branch protection makes the server refuse.

3. Checks get skipped

When a pre-commit hook complains, git commit --no-verify makes the complaint go away. Nothing on your Mac can stop that for good: git always lets you skip local hooks.

What stops it: run the same checks on the server. Make them required on main (GitHub calls them required status checks; GitLab, "Pipelines must succeed"), so work that skipped them locally can't merge until they pass on the server.

4. Folders get deleted

"My disk is full, clean up old backups" is how a folder holding the only copies disappears. Anything your user account can delete, an agent running on it can delete.

What stops it: the sandbox. In Claude Code, sandbox.filesystem.denyWrite closes a folder to every shell command the agent runs, and the Mac enforces it however the command is worded:

{
  "sandbox": {
    "enabled": true,
    "allowUnsandboxedCommands": false,
    "filesystem": { "denyWrite": ["~/backups", "~/models"] }
  }
}

Put your own folders in the list. allowUnsandboxedCommands: false stops Claude retrying a blocked command outside the sandbox, which it can do by default. Try it in one project first; some tasks will stop working, which is the point. Codex has its own sandbox modes in ~/.codex/config.toml.

5. The rule never reached the agent

Claude Code reads CLAUDE.md. Codex reads AGENTS.md. Your global rules in ~/.claude/CLAUDE.md never reach Codex at all. An agent can't follow a rule it was never given.

What stops it: one set of rules both agents read. Claude Code and Codex don't read the same rules has a one-minute check and the one-line import that fixes it.

Helpers do work you don't watch

Agents now split big jobs into helpers ("subagents"). You watch the main agent and read its summary. The helpers' commands never scroll past you. Claude Code writes each helper's log to its own file, in a subagents folder next to the main session's log, so the record is there if you look.

The record doesn't stay, though. Claude Code deletes session logs after 30 days by default (the cleanupPeriodDays setting). Check what your AI agent actually did has five searches that find leaked keys, secrets files read, force pushes, skipped checks and deletes.

Apple is moving too. On Oct 2 it said it will add controls around Full Disk Access on the Mac, "as AI agents become increasingly capable and autonomous," so that only "very explicit user action" grants it (MacRumors). Apple gave no date. Once it ships, it will limit what agents can open. It won't tell you what they already did.

Five checks to run today

Run these in your own Terminal, not by asking an agent. Whatever an agent reads goes into its conversation, and from there to its provider.

  1. Keys in your logs. The count in Your agent logs keep your keys. It prints no key.

  2. Keys every agent gets. The names of the keys exported in your startup files, never the values:

    grep -hoE '^[[:space:]]*export [A-Z0-9_]*(KEY|TOKEN|SECRET)[A-Z0-9_]*' ~/.zshrc ~/.zshenv ~/.zprofile ~/.bash_profile 2>/dev/null
  3. Force pushes and deletes. The searches in the log guide.

  4. Rules that reach only one agent. The comm check in the rules article.

  5. Branch protection. Open each repo you let agents push to and check that main blocks force pushes.

What Excellent does

Excellent for Mac, for Macs with Apple silicon and macOS 14 or later, reads the logs that Claude Code, Codex, Grok Build, GitHub Copilot CLI, Gemini CLI and Qwen Code already keep, on your Mac, and shows you what went wrong: keys sitting in logs, secrets files read, history overwritten on main, checks skipped, never-delete folders touched and your written rules broken, plus your email sent to websites or typed into forms. Each finding says which agent, where and when. Seeing them is free.

Excellent Pro checks risky actions before they run, in 9 agents: it blocks your email on its way to a website and an API key typed into a command, and asks before a force push, skipping your git hooks or a look at your keys. It can turn your file and folder rules into Claude Code's and Codex's macOS sandbox. Excellent can also turn on branch protection on GitHub or GitLab. How Excellent for Mac works, and what it sends has what's free, what's Pro, and the limits. That's Excellent for Mac today; a version for Linux servers comes next, then Windows.

The Mac app is almost here. If you'd rather not wait, the free scan is a prompt you paste into Claude Code or Codex. Your agent saves a small read-only script, checks its fingerprint and runs it on your logs. It writes one report on your Mac.

Citation

Please cite this work as:

Matt Waite, “AI agents leak keys, rewrite main and skip your checks”, Excellent Research, November 18, 2026. www.excellent.so/research/ai-agents-leak-keys-rewrite-main-skip-checks

Or use the BibTeX citation:

@article{excellent2026aiagentsleakkeysrewritemainskipchecks,
  author = {Matt Waite},
  title = {AI agents leak keys, rewrite main and skip your checks},
  journal = {Excellent Research},
  year = {2026},
  url = {https://www.excellent.so/research/ai-agents-leak-keys-rewrite-main-skip-checks}
}