AI News·24 Nov 2026·via Dev Community

    I scanned my laptop for API keys. 115 of them were in Claude Code's transcripts

    A developer performing a local security scan discovered that 115 of their API keys were stored in plaintext within the session transcripts of Claude Code, an AI coding agent. The findings, published on 2026-11-24, revealed that coding agents store session data, including sensitive credentials, as part of their design.

    A developer's comprehensive scan of their home folder, encompassing over 800,000 files, uncovered 179 active API keys, with 1,338 plaintext copies distributed across various locations. A notable 119 of these keys were identified within coding agent folders, with 115 specifically found in Claude Code's session transcripts under the `~/.claude/projects` directory.

    The presence of these keys in agent transcripts is described as an intended function, not a software flaw. Claude Code's documentation states it stores session transcripts locally in plaintext for 30 days by default. These transcripts record both the input the agent reads and the output its commands generate. Consequently, an API key becomes part of this record if the agent reads a file containing it, a command it executes prints the key, or if the agent is launched from a shell where keys are exported as environment variables.

    Beyond Claude Code, the scan also located two keys in `~/.codex` files and another two in `.gemini` files. Other key storage locations included notes, configuration files, logs, .env files, source code, and shell history. The report also noted that 16 of the identified keys were tracked by Git, indicating potential exposure through version control systems.

    To mitigate such risks, the developer's findings suggest several measures. These include rotating any API keys that have been exposed in transcripts or git-tracked files. Users can also shorten the default 30-day retention period for Claude Code's transcripts by adjusting the `cleanupPeriodDays` setting in `~/.claude/settings.json`, particularly if they do not frequently resume old sessions. Implementing deny rules can prevent agents from accessing sensitive files, though the source notes these rules may not cover commands that read without explicitly naming a file.

    Further recommendations include avoiding starting coding agents from shells where API keys are exported, as the agent's commands will inherit these sensitive environment variables and record them in transcripts. The report also advises using methods that keep actual key values out of local files, such as referencing them from secure vaults or encrypting them. Additionally, employing short-lived, scope-limited API keys with spend restrictions, where providers allow, can minimize the impact of any potential leaks.

    Share this article

    Original reporting by Dev CommunityWe don't republish, read the full story →

    Related reading

    6 stories