---
title: "Claude Code 密钥自查：先看批准规则里有没有明文"
canonical: "https://new.nat6.net/news/custom-5a48f19da8ec282a/"
date: "2026-11-08"
updated: "2026-11-08"
source: "橙子新闻 · 官方文档整理"
source_url: "https://code.claude.com/docs/en/permissions"
language: "zh"
topics: []
license: "https://new.nat6.net/sources/"
attribution: "橙子新闻编辑部（自写稿） / Orange News Editorial (staff-written)"
---

# Claude Code 密钥自查：先看批准规则里有没有明文

- 发布日期 / Published: 2026-11-08
- 更新时间 / Updated: 2026-11-08
- 分类 / Category: 教程与技巧
- 来源 / Source: 橙子新闻 · 官方文档整理 — [原文 / Original](https://code.claude.com/docs/en/permissions)
- 页面 / Page: https://new.nat6.net/news/custom-5a48f19da8ec282a/
- 结构化数据 / JSON: https://new.nat6.net/api/v1/articles/custom-5a48f19da8ec282a.json

- 语言 / Languages: [zh](https://new.nat6.net/news/custom-5a48f19da8ec282a/) · [en](https://new.nat6.net/en/news/custom-5a48f19da8ec282a/) · [de](https://new.nat6.net/de/news/custom-5a48f19da8ec282a/) · [fr](https://new.nat6.net/fr/news/custom-5a48f19da8ec282a/) · [ru](https://new.nat6.net/ru/news/custom-5a48f19da8ec282a/) · [ja](https://new.nat6.net/ja/news/custom-5a48f19da8ec282a/) · [es](https://new.nat6.net/es/news/custom-5a48f19da8ec282a/) · [ko](https://new.nat6.net/ko/news/custom-5a48f19da8ec282a/) · [vi](https://new.nat6.net/vi/news/custom-5a48f19da8ec282a/) · [th](https://new.nat6.net/th/news/custom-5a48f19da8ec282a/) · [id](https://new.nat6.net/id/news/custom-5a48f19da8ec282a/) · [ms](https://new.nat6.net/ms/news/custom-5a48f19da8ec282a/) · [fil](https://new.nat6.net/fil/news/custom-5a48f19da8ec282a/) · [hi](https://new.nat6.net/hi/news/custom-5a48f19da8ec282a/)

## 正文 / Article

风险不在点过批准，而在永久规则里是否留下明文密钥。用过 Claude Code 的「Yes, and don't ask again」，可以检查本地批准规则；这不代表你已经泄密，更不代表每次批准都会永久保存。

本文依据官方文档整理，不是本站漏洞复现，也不引用尚未核实的泄露数量。文档核对日期为2026年11月8日。

## 1. 什么情况下会保存规则？

[官方权限文档](https://code.claude.com/docs/en/permissions)说明：对于会永久保存的批准，例如 Bash 命令或网页域名，选择「Yes, and don't ask again」会把规则写入 `.claude/settings.local.json`；文件修改批准则只持续到当前会话结束。不是所有批准都会写进这个文件。

要检查的是：保存的命令规则有没有包含密码、API Key 或令牌的实际值。批准一条不含秘密的测试命令，与把带密钥的完整命令留在规则里，是两回事。本地存在明文值得处理；是否已经外泄，还要看文件是否被提交、上传或分享。

## 2. 文件在哪里，怎么检查？

先在自己的本地编辑器里打开 `.claude/settings.local.json`，查看 `permissions.allow` 下的命令规则，尤其留意请求头、密码参数等位置。不要把文件原文或带密钥的截图发到群里，也不要上传给在线工具代查。

位置以[官方设置文档](https://code.claude.com/docs/en/settings)和实际版本为准：当前文档说明，Git 仓库内通常在仓库根目录；worktree 通常使用主检出目录。Windows、非 Git 目录等情况存在例外；早于 v2.1.211 的版本会把文件放在启动目录，旧文件也可能继续被读取。根目录没找到，不等于从未保存过规则。

文件不存在，不必为了自查新建；发现不认识的规则，先核清用途，不要直接把权限范围改大。

## 3. 发现明文后，为什么先轮换？

先到密钥所属服务撤销或轮换旧密钥，更新合法使用它的应用，再清理含秘密的批准规则。新密钥不要重新粘进要永久保存的命令。

如果文件曾被公开提交或分享，应按已暴露处理；只删当前文件，不能让别人已经拿到的旧密钥失效。随后检查该服务的使用记录，必要时联系账户管理员。仅在本机发现明文，不能直接断言已经有人盗用。

## 4. 已被 Git 跟踪，怎么停止跟踪？

在仓库根目录先运行只读检查：

`git ls-files -- .claude/settings.local.json`

若输出该路径，表示当前索引里有这个文件；完成密钥轮换后，可运行：

`git rm --cached .claude/settings.local.json`

[Git 官方文档](https://git-scm.com/docs/git-rm)说明，`--cached` 只从索引移除文件，保留本地工作区文件。这会产生待提交的移除变更，须检查并提交，才能让后续仓库版本不再跟踪它。命令不清除旧提交，也不会收回别人下载或复制的内容。

若没有输出，不要机械执行移除命令；这只说明当前未被跟踪，不证明历史从未含有它。已有公开泄露时，历史清理需另行与维护者协调，不能把上述命令当成清理历史的办法，也不要直接强推覆盖团队历史。

## 5. 如何避免下次又提交？

当前 Claude Code 设置文档说明：它首次在 Git 仓库写入该文件时，若尚未被忽略，会添加全局忽略规则；手动创建的文件则需要自己处理。因此，不能笼统说「默认一定会上传」，也不能只凭文件名带 local 就认定安全。

如需把忽略规则随项目共享，在仓库根目录 `.gitignore` 添加一行：

`/.claude/settings.local.json`

[Git 忽略规则文档](https://git-scm.com/docs/gitignore)明确：忽略规则不影响已经被跟踪的文件。它防的是以后误加，不替代停止跟踪、密钥轮换或历史清理。

最后确认三件事：旧密钥已失效，含秘密的规则已清理，今后的提交不再包含该本地文件。没有发现明文时，不必为了“排查”扩大批准权限。

## 推荐理由 / Why it matters

先查永久批准规则是否含明文密钥，再按轮换、停止跟踪与忽略规则的顺序处理；区分本地存放和已经公开泄露。

## 来源与版权 / Source & copyright

本文为橙子新闻自写稿；文中引用的第三方资料版权归原作者与媒体所有，本站不镜像全文。

This is a staff-written article by Orange News Editorial; copyright of third-party material cited remains with the original authors and publishers, and this site does not mirror full texts.

## 关于橙子中转站 / About Orange Relay

橙子中转站（pro.nat6.net）是一家优质的 AI API 中转站：价格优惠、质量稳定、模型齐全，支持 Claude、GPT、Gemini 等主流模型，欢迎体验。

[访问橙子中转站](https://pro.nat6.net/?utm_source=orange_news&utm_medium=article_footer&utm_campaign=brand&lang=zh)

## JSON-LD

```json
{
  "@context": "https://schema.org",
  "@type": "NewsArticle",
  "@id": "https://new.nat6.net/news/custom-5a48f19da8ec282a/#article",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://new.nat6.net/news/custom-5a48f19da8ec282a/"
  },
  "url": "https://new.nat6.net/news/custom-5a48f19da8ec282a/",
  "headline": "Claude Code 密钥自查：先看批准规则里有没有明文",
  "description": "风险不在点过批准，而在永久规则里是否留下明文密钥。用过 Claude Code 的「Yes, and don't ask again」，可以检查本地批准规则；这不代表你已经泄密，更不代表每次批准都会永久保存。 本文依据官方文档整理，不是本站漏洞复现，也不引用尚未核实的泄露数量。文档核对日期为2026年11月8日。 1…",
  "articleSection": "教程与技巧",
  "keywords": "AI, 橙子新闻 · 官方文档整理",
  "datePublished": "2026-11-08T05:26:53Z",
  "dateModified": "2026-11-08T05:26:53Z",
  "inLanguage": "zh-CN",
  "isAccessibleForFree": true,
  "author": {
    "@type": "Organization",
    "name": "橙子新闻编辑部",
    "url": "https://new.nat6.net/about/"
  },
  "publisher": {
    "@type": "NewsMediaOrganization",
    "@id": "https://new.nat6.net/#org",
    "name": "橙子新闻",
    "url": "https://new.nat6.net/",
    "logo": {
      "@type": "ImageObject",
      "url": "https://new.nat6.net/assets/img/logo-512.png",
      "width": 512,
      "height": 512
    }
  },
  "image": {
    "@type": "ImageObject",
    "url": "https://new.nat6.net/assets/img/og-default.png",
    "width": 1200,
    "height": 630
  },
  "isPartOf": {
    "@id": "https://new.nat6.net/#website"
  },
  "isBasedOn": "https://code.claude.com/docs/en/permissions",
  "citation": [
    "https://code.claude.com/docs/en/permissions"
  ],
  "license": "https://new.nat6.net/sources/",
  "about": [],
  "mentions": [
    {
      "@type": "Thing",
      "name": "橙子新闻 · 官方文档整理"
    }
  ],
  "speakable": {
    "@type": "SpeakableSpecification",
    "cssSelector": [
      "h1",
      ".article-summary"
    ]
  },
  "copyrightHolder": {
    "@type": "Organization",
    "@id": "https://new.nat6.net/#org",
    "name": "橙子新闻",
    "url": "https://new.nat6.net/"
  },
  "creditText": "橙子新闻（自写稿）；参考：橙子新闻 · 官方文档整理",
  "copyrightNotice": "© 2026 橙子新闻。本文为本站自写稿，文中引用的第三方资料版权归原作者与媒体所有；本站不镜像全文。",
  "copyrightYear": 2026,
  "abstract": "先查永久批准规则是否含明文密钥，再按轮换、停止跟踪与忽略规则的顺序处理；区分本地存放和已经公开泄露。",
  "subjectOf": [
    {
      "@type": "DigitalDocument",
      "name": "Claude Code 密钥自查：先看批准规则里有没有明文 (Markdown)",
      "url": "https://new.nat6.net/news/custom-5a48f19da8ec282a/index.md",
      "encodingFormat": "text/markdown"
    },
    {
      "@type": "DigitalDocument",
      "name": "Claude Code 密钥自查：先看批准规则里有没有明文 (JSON)",
      "url": "https://new.nat6.net/api/v1/articles/custom-5a48f19da8ec282a.json",
      "encodingFormat": "application/json"
    }
  ]
}
```

## 如何引用 / How to cite

- 引用格式 / Citation format (zh): 橙子新闻.《文章标题》. 发布日期. https://new.nat6.net/news/custom-5a48f19da8ec282a/
- Citation format (en): Orange News. "Article title". Published YYYY-MM-DD. https://new.nat6.net/news/custom-5a48f19da8ec282a/
- 回链要求 / Backlink: 引用请保留「橙子新闻」署名并回链 canonical URL；AI 摘要请注明数据来源 AIHOT；原文版权归原媒体与作者所有。
- Attribution & backlinks: Keep the "Orange News" attribution and link back to the canonical URL; cite AIHOT as the data source for AI summaries; original copyright remains with the original publishers and authors.

### 机器入口 / Machine entry points

- Markdown: https://new.nat6.net/news/custom-5a48f19da8ec282a/index.md
- JSON: https://new.nat6.net/api/v1/articles/custom-5a48f19da8ec282a.json
- API 清单 / API index: https://new.nat6.net/api/v1/site.json
- Markdown 内容协商 / negotiation: 对 https://new.nat6.net/news/custom-5a48f19da8ec282a/ 发送 `Accept: text/markdown`
