功能深潜

Claude Code 权限详解:哪些工具会先征求同意,怎么把它们加进白名单

Claude Code 的所有动作都走一套固定的内置工具,其中一部分执行前会停下来问你。本页把一次真实会话里的每个权限弹窗都截了图——包括那个会替你写出项目白名单的选项。

Claude Code Bash command approval for git add src/app/globals.css offering Yes, Yes and do not ask again for git add commands in the project directory, and No with feedback
Claude Code 针对 git add 弹出的批准窗口——选第二个选项,项目的白名单就生成了。

共 13 个图解步骤,阅读约需 5 分钟。每一步都深链回来源视频中的对应时刻。

TL;DR

Claude Code 靠内置工具干活——读文件用 Read、改文件用 Edit、跑命令用 Bash——你在提示词里根本不用点名。Anthropic 文档给每个工具标了 Permission Required:Read、Grep、LS、TodoWrite 静默执行,Bash、Edit、MultiEdit、Write 和联网类工具会停下来征求同意。编辑弹窗只有三个答案:Yes、Yes and don't ask again this session(alt+m)、No 并说明要改哪里。用「不再询问」批准一条 Bash 命令,会把 Bash(git add:*) 这样的规则写进 .claude/settings.local.json 的 permissions.allow——这个文件属于你个人,不要提交。想整场会话都不再被打断,就按 alt+m 切到 accept edits 模式。

来源视频

本页跟随 Net Ninja Claude Code 系列的第 4 课,在一场真实会话里过一遍内置工具和权限弹窗。每张截图都深链到它出现的精确时刻。

截图为视频画面,已署名致谢;正文为原创。步骤已于 2026 年 9 月对照视频核验。

Claude Code 自带哪些工具

固定的内置工具集,以及文档里那列「是否需要批准」。

  1. 1

    Anthropic 的工具清单标明了谁需要批准

    在你敲第一个字之前,Claude Code 已经带着一整套内置工具:Read 打开文件、Edit 修改单个文件、Bash 执行命令、TodoWrite 负责它干活时列的那份清单。Claude Code 设置文档用 Permission Required 一列把每个工具标好了——Bash、Edit、MultiEdit、NotebookEdit、Write、WebFetch、WebSearch 是 Yes;Read、Glob、Grep、LS、NotebookRead、Task、TodoWrite 是 No。同一页还写着:权限规则可以用 /allowed-tools 或在 permission settings 里配置。

    Anthropic Claude Code settings documentation listing every built-in tool with a Permission Required column that marks Bash, Edit, MultiEdit and Write as Yes while Read, Grep, LS and TodoWrite are No
    Bash 和 Edit 需要批准,Read 不需要。在 1:19 处观看
  2. 2

    读取一路放行,编辑当场停下

    一屏就能看出差别。Claude Code 读了 layout.tsx 的 43 行,什么都没问;紧接着对同一个文件调用 Update,立刻弹出「Do you want to make this edit to layout.tsx?」。左边编辑器里 diff 已经摊开,所以你要批准的是一个看得见、看得完的具体改动。

    Claude Code terminal inside VS Code where a Read of layout.tsx completed silently and the Update call right below it paused on a Do you want to make this edit to layout.tsx prompt
    Read 静默完成,Update 在等回答。在 0:46 处观看

逐条批准文件编辑

给一个 CSS 文件加一个变量,触发了三次独立弹窗。

  1. 3

    提一个必然要改文件的需求

    演示里只加一个主题变量:「@src/app/globals.css Add another theme variable to the CSS file called highlight, and make it a pastel yellow」。@ 提及把文件直接拉进上下文,Claude Code 先读完 66 行——全程没有弹窗——然后开始思考。

    Claude Code prompt that @-mentions src/app/globals.css to add a highlight theme variable in pastel yellow, answered by a Read of 66 lines and a Pontificating status line
    @ 提及提供文件,读取不花任何批准。在 2:02 处观看
  2. 4

    编辑弹窗只有三个答案

    「Do you want to make this edit to globals.css?」给出三个选项:1. Yes;2. Yes, and don't ask again this session (alt+m);3. No, and tell Claude what to do differently (esc)。建议新增的 --highlight: #fef3c7 已经在编辑器里显示,弹窗顶部还写着改动已在 Visual Studio Code 中打开、并提示「Save file to continue...」。作者这里故意选最普通的 Yes,好让后面的流程看得清楚。

    Claude Code edit permission dialog for globals.css offering Yes, Yes and do not ask again this session with the alt+m shortcut, and No with an explanation, beside a diff adding --highlight: #fef3c7
    同意、本场同意、或者拒绝并给出改法。在 2:23 处观看
  3. 5

    同一个文件,第二次批准

    第一处改动落地了——「Updated src/app/globals.css with 1 addition」——然后 Claude Code 转到同一个文件的另一处,于是又问了一次。这是最让人意外的一点:批准是按「每次编辑」给的,不是按「文件」给的。亮色模式的变量已经写进去,暗色模式的那个正卡在弹窗后面。

    Second Claude Code approval request for the same globals.css file, showing the light-mode highlight already applied and the dark-mode variable still waiting for permission
    同一个文件的新代码块,等于一次新弹窗。在 2:38 处观看
  4. 6

    一个小改动,三次批准

    第三次批准后,映射 --color-highlight: var(--highlight) 也写进去了,Claude Code 随即总结这次任务:亮色模式 #fef3c7、暗色模式 #fbbf24 的柔和黄,加上主题区块里对应的映射。一个 CSS 变量点了三次 yes——白名单要解决的正是这种摩擦。

    Claude Code terminal after three separate approvals on one file, listing the added --color-highlight token mapping and summarising the pastel yellow values for light and dark mode
    三次 yes,换来一个 CSS 变量。在 2:56 处观看

为项目放行一条 Bash 命令

Bash 弹窗的第二个选项,会替你写好 settings.local.json。

  1. 7

    Bash 先看仓库,而且不问

    下一个请求很简单:「can you make a commit」。Claude Code 连着调用三次 Bash——git status、git diff、git log --oneline -5——没有一个停下来征求批准;每条结果都折叠在「ctrl+r to expand」后面。它在动手之前先把改了什么摸清楚,而这一整轮只读命令在这次会话里一个弹窗都没花。

    Claude Code Bash tool running git status, git diff and git log one after another with no approval prompt after a request to make a commit, each result collapsed behind ctrl+r to expand
    status、diff、log 一路直接跑完。在 3:13 处观看
  2. 8

    就是这个弹窗在写你的白名单

    接着它要执行 git add src/app/globals.css,这次问了。弹窗里先显示命令本身,再显示 Claude 给它写的一行说明(「Stage the globals.css file with highlight theme variable」),然后三个选项:1. Yes;2. Yes, and don't ask again for git add commands in D:\tutorials\sandbox\@claude\shinobi;3. No, and tell Claude what to do differently (esc)。留意第二个选项有多具体——命令名和项目目录都被写进了选项文字里。

    Claude Code Bash command approval for git add src/app/globals.css whose second option reads Yes, and do not ask again for git add commands in the project directory
    「不再询问 git add 命令(限本项目目录)」在 3:26 处观看
  3. 9

    规则当场生效

    选了第二个选项,命令立刻执行,放行的效力在同一次会话里就生效了:git add 跑完,只留下一条 Git 自己的 CRLF 警告。队列里的下一条 git commit 仍然单独弹出「Do you want to proceed?」——新规则只覆盖 git add,别的不管。

    Claude Code terminal where the just-allowed git add command has already run and only the following git commit still needs a Do you want to proceed answer
    git add 已放行,git commit 照旧要问。在 3:34 处观看
  4. 10

    那份权限写到了哪里

    选了「不再询问」之后,项目根目录就会出现 .claude/settings.local.json——资源管理器里就能看到它,紧挨着标记为已修改的 globals.css。不用事先建模板、也不用先配置:授予长期权限的那一刻文件就生成了,编辑器随即打开它。

    VS Code explorer showing the .claude folder Claude Code created at the project root containing settings.local.json, next to a globals.css marked as modified
    .claude/settings.local.json 由 Claude Code 自动创建。在 3:40 处观看
  5. 11

    逐键看懂 allow 数组

    文件很小:一个 permissions 对象,里面三个数组——allow、deny、ask。Claude Code 写入的规则是字符串 'Bash(git add:*)':工具名、命令前缀,然后一个冒号加星号,表示「后面跟什么都有可能」。空着的 deny 和 ask 是同一套机制的反方向用法。你也可以手写这些条目——弹窗只是更快的输入方式,作者强调的重点是:这份列表归你改。

    settings.local.json in Claude Code with a permissions object whose allow array holds the rule Bash(git add:*), shown alongside empty deny and ask arrays
    permissions.allow 里存着 Bash(git add:*)。在 4:10 处观看

accept edits 模式

整场会话不再被询问,用完再关掉。

  1. 12

    整场会话不再为编辑弹窗

    第三种免问方式是一个模式,而不是一条规则。按下 alt+m(Windows;作者提示 Mac 上可能是 ctrl+m),输入框下方的指示就会亮起:「accept edits on (alt+m to cycle)」。此后这场对话里 Claude Code 改文件不再征求同意。它只在当前会话有效——新开会话又会开始问;而它写「to cycle」,是因为 alt+m 是在几个模式之间循环,不是拨一个开关。

    Claude Code input area displaying the highlighted accept edits on indicator with alt+m to cycle, meaning further file edits in this session run without permission prompts
    输入框下方亮起「accept edits on (alt+m to cycle)」。在 4:22 处观看
  2. 13

    再循环一次,回到逐条询问

    再按一次 alt+m,输入区的指示就消失了,这代表编辑重新回到逐条批准。白名单不受任何影响——settings.local.json 里那条 Bash(git add:*) 还在,下次打开项目照样有效。

    Claude Code prompt box with the accept edits indicator gone after cycling the mode again, so file edits return to per-change approval
    指示消失,弹窗回来。在 4:42 处观看

常见问题