返回博客
Industry

Claude Code 的“不再询问”把 1,379 个密钥留在了 GitHub:在下次 Push 前修好你的 Agent 配置

安全机构 Apiiro 扫描了逾 10 万个公开仓库,发现 1,122 个 .claude/settings.local.json 文件泄露了真实凭证。当你点击“是,且不再询问”时,包含密码的完整 Shell 命令会被明文保存,并经常被 Agent 自己提交到仓库中。

OPC Community

OPC Community

Nov 13, 2026 3 min read
Claude Code 的“不再询问”把 1,379 个密钥留在了 GitHub:在下次 Push 前修好你的 Agent 配置

点击“是,且不再询问”不仅仅是在授权一个工具——它会把整条命令字符串(连同里面的内联密码)原封不动地写进项目目录下的明文 JSON 文件里。

如果你是一个用终端 Agent 独立开发的构建者,肌肉记忆往往是你最大的安全漏洞。11月1日至3日期间,安全机构 Apiiro 扫描了 GitHub 上的公开仓库,发现了 104,185 份 .claude/settings.local.json 文件。其中约 1.1%(1,122 个文件)包含真实有效的密钥凭证;如果算上 Git 历史记录和保存的 Agent 聊天日志,泄露的独立密钥总数高达 2,539 个。

没有人黑进 Anthropic 窃取这些密钥。是开发者自己敲下回车交出了密码,而在近一半的案例中,正是 Agent 自己执行了把密钥推向公开仓库的 Commit。

一次权限批准是如何变成明文泄露的?

默认情况下,Claude Code 在执行大多数 Shell 命令前会暂停询问。当它提出一条命令,而你选择了 “Yes, and don't ask again”(是,且不再询问) 时,它会在项目目录的 .claude/settings.local.json 中写入一条永久允许规则。

问题出在规则的记录格式上:这条允许规则保存的是完整的命令字符串本身。如果你让 Agent 测试数据库迁移、调用内部 Webhook 或部署服务,而生成的命令里恰好带上了数据库 URI 或 API Token,这个密钥就会被直接明文写入磁盘。

更糟糕的是,Apiiro 追踪了 1,105 个泄露仓库后发现,其中 539 个仓库里修改并提交该文件的 Commit 共同作者(Co-author)正是 Claude 自己。当你随口让 Agent 执行 git add . && git commit 时,它会尽职尽责地把自己的配置文件夹一并打包上传。

一人公司锁死终端 Agent 的三条铁律

1. 立即配置全局 Gitignore: 不要依赖单个项目的 .gitignore。在本机执行一次全局排除配置,彻底杜绝任何仓库暂存本地 Agent 配置文件: ``bash git config --global core.excludesFile ~/.gitignore_global echo ".claude/settings.local.json" >> ~/.gitignore_global echo ".claude/logs/" >> ~/.gitignore_global ` 2. 绝不在 Shell 命令中传递内联密钥: 让 Agent 在运行时读取环境变量(例如 psql "$DATABASE_URL"),这样写入 settings.local.json` 的就只是变量名而非真实密码。 3. 升级至 Claude Code v2.1.325+ 并清理历史记录: 记住,单纯删除文件无法清除 Git 历史和已被 Fork 的分支。凡是进过该文件的密钥,必须第一时间轮换(Rotate)。

附赠技巧:用 Message Threads 将长会话首字延迟降低 35%

在加固安全配置的同时,别忘了用上 Anthropic 在 11 月 2 日上线的公测特性:Message Threads(消息线程)。在 50 万到 100 万 Token 的超长代码重构会话中,它能避免每轮对话重复上传和分词整个历史上下文,将中位首字延迟(TTFT)降低约 35%。不过独立开发者需要注意账单细节:虽然请求体积变小了,但模型每轮依然会读取完整上下文,因此 Token 计费并不会减少——它省下的是你的等待时间,而不是 API 预算。

常见问题

Why did Claude Code leak passwords into public GitHub repositories?

When a user selects "Yes, and don't ask again" on a command prompt, Claude Code writes the exact command string as an allow rule in .claude/settings.local.json. If the command contained an inline password or API key, it was saved in plain text and frequently committed to GitHub when the agent ran broad git add commands.

How can I check if my repositories are affected by the .claude/settings.local.json leak?

Search both your current working trees and your full git commit history across all repositories for .claude/settings.local.json and .claude/settings.json. If any credential ever appeared in those files, rotate the key immediately—simply deleting the file does not remove it from git history or public forks.

Does Anthropic's new Message Threads feature reduce API token costs for Claude Code?

No. While Message Threads reduce median time-to-first-token by about 35% on 500k–1M token requests by avoiding re-uploading and re-tokenizing the entire history on every turn, the model still processes the full conversation context, so token billing remains the same.

Share this article

加入 OPC 同行社

与全球一人公司创始人连接,获取每日洞察、精选机会与同行支持。

免费加入