Agentic

AI Coding Agents and Secret Leaks: What Actually Breaks

developer typing code on laptop - a man is typing on a laptop keyboard

Photo by Amanz on Unsplash

The Common Belief: Secrets Leak When You Commit Them

A developer opens a repo in Cursor at 9:14 a.m., types "why is my Stripe webhook 401-ing," and the agent — helpfully, obediently — reads .env, docker-compose.yml, and the output of the failing curl command in the terminal pane. No commit happened. No git push fired. The pre-commit hook never got a chance to run. And yet a live secret key just crossed a network boundary into an inference provider's context window, got logged somewhere in a trace, and possibly landed in a shared team session.

The operative insight, as of September 26, 2026: the entire secrets-management industry was built around the commit as the moment of exposure, and AI coding agents moved the leak upstream of the commit entirely.

According to Google News, coverage surfaced this week around a GitGuardian analysis examining how Cursor, Claude Code, GitHub Copilot, and MCP-enabled tooling create credential exposure paths that traditional scanning was never designed to catch. GitGuardian is the obvious source for this — the company's business is finding secrets in source code, and its State of Secrets Sprawl report documented more than 10 million secrets leaked publicly on GitHub in 2023.

That 10 million figure is worth sitting with, because it describes the old failure mode. Ten million secrets leaked through the well-understood channel: someone committed a key, pushed it to a public repo, and a scanner (or an attacker) found it. Pre-commit hooks, .gitignore discipline, and repository scanning exist precisely because that channel is measurable. The uncomfortable part of the current story is that nobody has an equivalent count for the agent channel — because there is no git log for a context window.

The Pattern: This Is Tool-Use, and the Tool Is Your Filesystem

Strip the branding away and every one of these products implements the same agentic pattern: a model in a loop with read access to local state. The loop is roughly read-file → reason → propose-edit → read-terminal-output → repeat. That pattern is why the tools work. A coding assistant with no file access is an autocomplete widget; a coding assistant that can read your config, your test output, and your stack trace is the thing developers actually pay for.

The security consequence follows mechanically from the architecture, not from a bug. As the GitGuardian framing puts it, AI coding assistants need broad file access to produce useful suggestions, and that need creates a trade-off developers have to consciously manage. Environment variables, terminal buffers, and config files are exactly the highest-signal context for debugging — and exactly where API keys, OAuth tokens, and private keys live. The research on commonly leaked credential types in AI-assisted development names those three categories specifically. That is not coincidence. It is the same file.

Model Context Protocol, which Anthropic released in late 2024, widens the aperture again. MCP's whole purpose is to let an assistant reach external data sources and tools — a database, a ticketing system, an internal API. Each connector is another read surface, and each read surface is another place a token can be surfaced into context. The pattern is tool-use; the tools bite back.

Here is the second-order consequence the surface reporting tends to skip: the leak is no longer a single event you can point to. A committed key has a timestamp, a commit hash, and a blast radius you can compute. A key that entered a model's context has a provider log, possibly a proxy log, possibly a team-shared conversation, possibly a local session file — and the number of copies is not knowable from inside your own infrastructure. Rotation becomes the only honest remediation, because you cannot prove deletion.

The Arithmetic Nobody Puts on the Slide

Compare the two exposure channels side by side, because they behave differently in ways that matter for how you spend your security budget.

The commit channel is gated. There is a chokepoint — the commit, the push, the CI run — and you can install a scanner at that chokepoint. Detection is cheap, deterministic, and it produces an audit trail. The 10 million secrets GitGuardian counted in 2023 leaked despite that chokepoint existing, mostly because teams didn't install the gate or ignored its output.

The agent channel is ungated by design. There is no single moment to hook. A read happens because the model asked for it mid-reasoning, thousands of times per working day across a team. If a 50-developer engineering org runs agents that each read, conservatively, a few dozen files per session across several sessions a day, the number of file reads per week lands in the tens of thousands — versus a few hundred commits from the same team. That ratio is the whole argument: you are now defending a surface that is orders of magnitude more active than the one your tooling watches, and it generates no artifact you can grep afterward.

10M+ secrets counted (2023) No published count Commit channel Agent context channel (measurement gap, not a safety signal) Measured exposure volume

Chart: GitGuardian's State of Secrets Sprawl reported 10+ million secrets exposed publicly on GitHub in 2023 — a number that exists only because commits are auditable. The short bar on the right is not a claim that agent exposure is small; it reflects the absence of any comparable public measurement, which is the actual problem.

A careful skeptic should push back here, and the pushback is fair: isn't this just fear about a channel with no evidence of harm? Two responses. First, GitHub has been shipping mitigations — the platform added secrets filtering to Copilot across 2024–2025 specifically so the assistant would stop suggesting known-leaked credentials, which is a vendor conceding the channel is real. Second, and more important, absence of measurement is not absence of exposure; it is the reason the exposure would be hard to detect. Our read: the honest position is "unquantified," not "unproven," and security teams that treat those as synonyms are the ones who will be surprised.

Worth noting the divergence in how this gets framed. Security vendors like GitGuardian emphasize the context window as the new leak vector and argue traditional secrets management doesn't account for it at all. Platform vendors emphasize filtering and policy controls at the suggestion layer — GitHub's Copilot work is a good example. Those are not the same threat model. Filtering what an assistant outputs does nothing about what it ingested. Both framings are partially right, and the gap between them is where most real-world incidents will live.

Where This Breaks in Production

The failure modes are boring, which is what makes them likely.

Failure one: .gitignore is not an access control. Developers reasonably assume that an ignored .env is a private .env. It isn't. .gitignore tells Git what to skip; it says nothing to a file-reading agent walking your project directory. Cursor and Claude Code read project files by default to build context-aware suggestions, and "project files" plausibly includes config files carrying live secrets. A file can be simultaneously invisible to your repo scanner and fully visible to your model.

Failure two: rotation debt compounds silently. Once a key has plausibly entered a context window, the only defensible action is rotation — and most teams have no inventory of which keys sat in which project directory during which agent session. The cost isn't the rotation; it's discovering, six months later, that you can't reconstruct the exposure timeline.

Failure three: MCP connectors inherit whatever credentials you gave them, permanently. A connector wired to a production database with a broad-scope token is a standing read path. It doesn't expire when the conversation ends.

Failure four: policy without enforcement. Enterprises are now writing AI coding assistant policies that mandate secrets scanning and approval workflows before deployment. Policies are good. But a policy that gates deployment is still gating the commit channel — the agent read already happened at 9:14 a.m.

The practical fix is unglamorous and mostly predates AI: stop putting long-lived secrets on developer filesystems at all. Short-lived credentials from a secrets manager, injected at runtime and scoped per-service, make the agent's read harmless because there is nothing durable to read. Keep the pre-commit hooks and repository scanning that the research recommends — they still catch the 10-million-secrets failure mode — but treat them as the second line, not the first. And scope MCP connectors like you'd scope a service account for a contractor: least privilege, short expiry, auditable.

This pairs with a broader pattern our Cybersecurity desk has traced in AI-assisted attack surfaces: the tell that used to work — a bad grammar signal, a suspicious commit diff — stops working once AI is in the loop, and the control has to move earlier in the chain.

Bottom Line: Who Should Change Something This Week

Solo developers and small teams working on non-production credentials can probably keep their current setup and add one habit: never let a live production key sit in a local .env inside a directory an agent has read access to. Use a separate, secret-free workspace for agent-assisted debugging of production issues.

Teams running agents against production repos should treat this as a rotation-and-scoping project, not a detection project. On balance, our analysis is that the next 12–18 months of secrets-management tooling will be defined by pre-read controls — credential brokers, ephemeral tokens, filesystem-level redaction before the model sees the bytes — rather than by better post-hoc scanners. The vendor incentive points that way, and the architecture leaves little alternative: you cannot scan a context window you don't own.

The uncomfortable summary is that these tools are not misbehaving. They are doing precisely what broad file access implies, and the trade-off between capability and exposure is structural rather than fixable. Which means the question isn't whether to let agents read your code. It's what you're willing to leave lying around where they can read it.

Frequently Asked Questions

Can Cursor or Claude Code read my .env file even if it's in .gitignore?

Yes. .gitignore only instructs Git to exclude a file from version control — it does not restrict what a local coding agent can open. Both tools read project files by default to build context, which can include configuration files holding secrets. Vendor-specific ignore settings exist and should be configured explicitly rather than assumed.

How many secrets actually leak through GitHub versus AI coding tools?

GitGuardian's State of Secrets Sprawl report documented over 10 million secrets exposed publicly on GitHub in 2023. There is no comparable published figure for exposure through AI agent context windows, largely because context reads leave no auditable artifact equivalent to a commit history.

Is Model Context Protocol a security risk for enterprise AI agents?

MCP, released by Anthropic in late 2024, expands what an assistant can reach — external databases, APIs, internal tools. Each connector adds a read surface and a stored credential, which enlarges the potential leak area. The risk is manageable with least-privilege, short-lived tokens per connector rather than broad standing credentials.

What should a developer do if a secret was already exposed to an AI coding assistant?

Rotate the credential. Because copies may exist in provider logs, proxies, or shared sessions outside your infrastructure, deletion cannot be verified — rotation is the only remediation that changes the attacker's position. Then audit which other keys were present in the same directory during that period.

Disclaimer: This article is editorial commentary for informational and educational purposes only. It reflects analysis of publicly reported facts and does not constitute security, legal, or financial advice, nor does it represent independent product testing of any tool named. Research based on publicly available sources current as of September 26, 2026.