The assumption that .env files are the primary leak vector for API keys is officially dead. A recent deep scan of a developer's home directory across 803,628 files uncovered 179 real API keys, but the true culprit wasn't configuration files. Instead, 115 of those keys were sitting in plain text within Claude Code's session transcripts under ~/.claude/projects. This discovery highlights a massive blind spot in how AI coding agents handle sensitive data during debugging and execution.
The Agent Folder Problem
While .env files accounted for only 32 of the exposed keys, coding agent foldersβsuch as ~/.claude, ~/.codex, and ~/.cursorβheld 119 keys. The breakdown shows that Claude Code alone is responsible for the vast majority, with 115 keys found in its session transcripts. These logs persist for 30 days by default, creating a rolling window of vulnerability where every read operation, environment variable dump, or failed curl command leaves a permanent trace of the secret.
How Secrets Slip Through
The leak mechanism is straightforward but overlooked: agents record everything they read and print. When a developer asks the agent to debug an environment, commands like env or printenv dump the entire context into the transcript. Similarly, pasting a key directly into a chat or having the agent manage an MCP server's environment block writes the value to disk. It is not a bug in the agent's logic but a feature of its transparency that developers fail to secure.
Mitigation and Best Practices
The author recommends immediate rotation of any key found in these folders, treating them as leaked regardless of file deletion. Technical fixes include setting cleanupPeriodDays in ~/.claude/settings.json to shorten retention and using permission deny rules for .env files. However, the author notes a critical limitation: deny rules only cover specific tools like cat or head, failing to block indirect reads via scripts or grep. The most robust solution involves using short-lived, scoped keys or tools like 1Password CLI to inject secrets at runtime rather than storing them in files.
Key Takeaways
- Claude Code session transcripts are a primary leak vector, holding more keys than .env files.
- Default 30-day retention for transcripts creates a persistent attack surface for exposed secrets.
- Permission deny rules in Claude Code do not cover all file access methods, leaving gaps.
- Developers must rotate keys found in agent folders and consider runtime secret injection over static files.
The Bottom Line
Coding agents are creating a new, invisible class of secret leakage that standard git hygiene misses; developers must treat session transcripts as sensitive data stores and enforce strict retention policies or runtime injection to stay secure.