Claude Code is accidentally exposing secrets all over GitHub
Claude Code is leaking sensitive information on public GitHub instances thanks to a partial oversight in the way its settings files are handled. That’s the finding of AI security researchers at Apiiro, who discovered thousands of secrets, including database passwords, API tokens, and root logins, amid Claude Code settings files embedded in GitHub repositories.
由于在处理设置文件的方式上存在疏忽,Claude Code 正在公共 GitHub 实例上泄露敏感信息。这是 Apiiro 的人工智能安全研究人员得出的结论,他们在嵌入 GitHub 存储库的 Claude Code 设置文件中发现了数千个机密信息,包括数据库密码、API 令牌和根登录凭据。
The leak stems from the way Claude Code handles user approval for automated shell commands. When a user chooses the “Yes, and don’t ask again” option to approve running a command, that choice gets stored as part of a rule in the local “.claude/settings.local.json” file on the user’s computer. That rule is sometimes coded as a pattern, but the command itself is often written to that settings file as is, including any sensitive information that may be embedded within it.
此次泄露源于 Claude Code 处理自动化 shell 命令用户授权的方式。当用户选择“是,且不再询问”选项来批准运行命令时,该选择会作为规则的一部分存储在用户计算机本地的“.claude/settings.local.json”文件中。该规则有时被编码为一种模式,但命令本身通常会按原样写入该设置文件,其中可能包含任何嵌入的敏感信息。
This isn’t really a significant security issue if the settings file stays on the user’s local machine (assuming that machine doesn’t become compromised itself, of course). And Anthropic notes in its Claude Code documentation that this particular settings file gets added to the developer’s global .gitignore list, which usually prevents it from being shared publicly.
如果设置文件保留在用户的本地机器上(当然,前提是该机器本身没有被入侵),这并不是一个重大的安全问题。Anthropic 在其 Claude Code 文档中指出,这个特定的设置文件会被添加到开发者的全局 .gitignore 列表中,这通常可以防止其被公开共享。
But that .gitignore setting isn’t reflected at the repo level, meaning the sensitive file can be uploaded accidentally if a repo is cloned to another machine or a folder becomes a repo later, for instance. In many cases, Claude Code itself will commit changes to the settings file without the user’s input, Apiiro writes.
但该 .gitignore 设置并未在存储库级别生效,这意味着如果存储库被克隆到另一台机器,或者文件夹稍后变成了存储库,敏感文件可能会被意外上传。Apiiro 写道,在许多情况下,Claude Code 本身会在没有用户输入的情况下提交对设置文件的更改。
Apiiro’s researchers found over 100,000 cases where Claude Code’s local settings file had been uploaded to a public GitHub repository. Of these, only about 1,100 from 63 different organizations contained secrets such as public API tokens, database passwords, or private keys. Even after these files are discovered and removed from a repository, the secrets can persist in forks of the original project if a GitHub user isn’t careful.
Apiiro 的研究人员发现了超过 10 万起 Claude Code 本地设置文件被上传到公共 GitHub 存储库的案例。其中,来自 63 个不同组织的约 1,100 个文件包含公共 API 令牌、数据库密码或私钥等机密信息。即使这些文件被发现并从存储库中删除,如果 GitHub 用户不小心,这些机密信息仍可能保留在原始项目的分支(fork)中。
What’s to be done? Although this security issue is getting more attention now, it was flagged in a Claude Code bug report as far back as August 2025. Other bug reports also noted that the sensitive settings file was sometimes not added to the user’s .gitignore list or that Claude Code could add the sensitive commands to another file that was not protected from git sharing. These bug reports were all closed without action after 60 days of inactivity.
该怎么办?尽管这个问题现在受到了更多关注,但早在 2025 年 8 月,Claude Code 的一份错误报告中就已指出该安全问题。其他错误报告也指出,敏感设置文件有时未被添加到用户的 .gitignore 列表中,或者 Claude Code 可能会将敏感命令添加到另一个未受 git 共享保护的文件中。这些错误报告在 60 天无活动后均被关闭,且未采取任何行动。
In a comment thread on Hacker News over the weekend, Claude Code’s Boris Cherny said the team is “looking into what we can do to prevent this.” That said, he noted that these settings files should pretty much never be checked in to a user’s git source control and that cases like these seemed to come up only when “the files were manually created and checked in.”
在上周末 Hacker News 的评论区中,Claude Code 的 Boris Cherny 表示团队正在“研究我们可以采取什么措施来防止这种情况”。不过,他指出这些设置文件几乎不应该被提交到用户的 git 源代码管理中,并且此类案例似乎只在“文件被手动创建并提交”时才会出现。
In the meantime, Cherny recommended using Claude Code’s auto mode, which uses classifiers to automatically route “routine permission prompts” without requiring what Cherny calls “manually maintaining finicky allow/deny lists.” But when another user noted that sensitive commands can still be saved to settings files in auto mode, Cherny said that was a “good catch” and added that the team is “thinking through what we can do to improve this.”
与此同时,Cherny 建议使用 Claude Code 的自动模式,该模式使用分类器自动处理“常规权限提示”,而无需他所说的“手动维护繁琐的允许/拒绝列表”。但当另一位用户指出在自动模式下敏感命令仍可能被保存到设置文件中时,Cherny 表示这是一个“很好的发现”,并补充说团队正在“思考我们可以做些什么来改进这一点”。
Cherny also recommends Claude Code users make use of secret scanners—which can trawl files for sensitive information and scrub it out—and said that the team was considering building this kind of secret scanning into Claude Code itself in the future. That said, the Apiiro researchers found that 215 of the roughly 1,100 public secrets it found in Claude Code settings files were not flagged by two popular secret scanners, gitleaks and TruffleHog.
Cherny 还建议 Claude Code 用户使用机密扫描工具(可以扫描文件中的敏感信息并将其清除),并表示团队正在考虑在未来将此类机密扫描功能直接内置到 Claude Code 中。不过,Apiiro 的研究人员发现,在他们在 Claude Code 设置文件中发现的约 1,100 个公共机密中,有 215 个未被两种流行的机密扫描工具 gitleaks 和 TruffleHog 标记出来。
This is far from the only case of an AI agent unintentionally leaking sensitive information. Last month, Meta suspended the sharing feature on its Muse agent after security researchers found the URLs for those links could be easily guessed.
这绝不是人工智能代理无意中泄露敏感信息的唯一案例。上个月,在安全研究人员发现 Meta 的 Muse 代理生成的链接 URL 可以轻易被猜出后,Meta 暂停了该代理的共享功能。