20 20
21一个开发者的个人设置。它选择一个模型和工作量级别,调整终端,并预先批准一个只读命令和一个文件读取。未列出的所有内容都保持其默认值。这样的文件放在 `~/.claude/settings.json` 中,它适用于你打开的每个项目。21一个开发者的个人设置。它选择一个模型和工作量级别,调整终端,并预先批准一个只读命令和一个文件读取。未列出的所有内容都保持其默认值。这样的文件放在 `~/.claude/settings.json` 中,它适用于你打开的每个项目。
22 22
23**Copyable settings file**23> [tab] Copyable settings file
24 24>
25将其保存为 `~/.claude/settings.json`。这是有效的 JSON,没有注释,因此你可以按原样粘贴它并删除你不想要的键。25> 将其保存为 `~/.claude/settings.json`。这是有效的 JSON,没有注释,因此你可以按原样粘贴它并删除你不想要的键。
26 26>
27```json ~/.claude/settings.json theme={null}27> ```json ~/.claude/settings.json theme={null}
28{28> {
29 "model": "claude-sonnet-5",29> "model": "claude-sonnet-5",
30 "modelSettings": {30> "modelSettings": {
31 "claude-sonnet-5": { "effortLevel": "xhigh" }31> "claude-sonnet-5": { "effortLevel": "xhigh" }
32 },32> },
33 "editorMode": "vim",33> "editorMode": "vim",
34 "theme": "light-daltonized",34> "theme": "light-daltonized",
35 "statusLine": {35> "statusLine": {
36 "type": "command",36> "type": "command",
37 "command": "jq -r '\"[\\(.model.display_name)] \\(.context_window.used_percentage // 0)% context\"'",37> "command": "jq -r '\"[\\(.model.display_name)] \\(.context_window.used_percentage // 0)% context\"'",
38 "padding": 238> "padding": 2
39 },39> },
40 "spinnerTipsEnabled": false,40> "spinnerTipsEnabled": false,
41 "preferredNotifChannel": "terminal_bell",41> "preferredNotifChannel": "terminal_bell",
42 "permissions": {42> "permissions": {
43 "allow": [43> "allow": [
44 "Bash(git diff *)",44> "Bash(git diff *)",
45 "Read(~/.zshrc)"45> "Read(~/.zshrc)"
46 ]46> ]
47 },47> },
48 "autoUpdatesChannel": "stable",48> "autoUpdatesChannel": "stable",
49 "cleanupPeriodDays": 2049> "cleanupPeriodDays": 20
50}50> }
51```51> ```
52 52
53**What each key does**53> [tab] What each key does
54 54>
55同一个文件,每个键上方都有注释。在这里阅读;从另一个选项卡复制,因为 Claude Code 不接受设置文件中的注释。55> 同一个文件,每个键上方都有注释。在这里阅读;从另一个选项卡复制,因为 Claude Code 不接受设置文件中的注释。
56 56>
57```jsonc ~/.claude/settings.json theme={null}57> ```jsonc ~/.claude/settings.json theme={null}
58{58> {
59 // 在 Sonnet 5 上启动每个会话59> // 在 Sonnet 5 上启动每个会话
60 "model": "claude-sonnet-5",60> "model": "claude-sonnet-5",
61 // 在 Sonnet 5 上运行高于其默认高级别;/effort 为每个模型保存一个级别,--effort 为单个会话设置一个级别61> // 在 Sonnet 5 上运行高于其默认高级别;/effort 为每个模型保存一个级别,--effort 为单个会话设置一个级别
62 "modelSettings": {62> "modelSettings": {
63 "claude-sonnet-5": { "effortLevel": "xhigh" }63> "claude-sonnet-5": { "effortLevel": "xhigh" }
64 },64> },
65 // 提示中的 Vim 快捷键65> // 提示中的 Vim 快捷键
66 "editorMode": "vim",66> "editorMode": "vim",
67 // 色盲友好的浅色主题67> // 色盲友好的浅色主题
68 "theme": "light-daltonized",68> "theme": "light-daltonized",
69 // 提示下方的状态行:模型名称和使用的上下文69> // 提示下方的状态行:模型名称和使用的上下文
70 "statusLine": {70> "statusLine": {
71 "type": "command",71> "type": "command",
72 "command": "jq -r '\"[\\(.model.display_name)] \\(.context_window.used_percentage // 0)% context\"'",72> "command": "jq -r '\"[\\(.model.display_name)] \\(.context_window.used_percentage // 0)% context\"'",
73 "padding": 273> "padding": 2
74 },74> },
75 // 隐藏在加载器下旋转的提示75> // 隐藏在加载器下旋转的提示
76 "spinnerTipsEnabled": false,76> "spinnerTipsEnabled": false,
77 // 为通知(例如完成的任务或等待的权限提示)响铃终端铃声77> // 为通知(例如完成的任务或等待的权限提示)响铃终端铃声
78 "preferredNotifChannel": "terminal_bell",78> "preferredNotifChannel": "terminal_bell",
79 // 让 Claude Code 运行 git diff 并读取你的 .zshrc,无需询问79> // 让 Claude Code 运行 git diff 并读取你的 .zshrc,无需询问
80 "permissions": {80> "permissions": {
81 "allow": [81> "allow": [
82 "Bash(git diff *)",82> "Bash(git diff *)",
83 "Read(~/.zshrc)"83> "Read(~/.zshrc)"
84 ]84> ]
85 },85> },
86 // 从稳定频道获取更新86> // 从稳定频道获取更新
87 "autoUpdatesChannel": "stable",87> "autoUpdatesChannel": "stable",
88 // 删除超过 20 天的会话记录和其他本地会话数据88> // 删除超过 20 天的会话记录和其他本地会话数据
89 "cleanupPeriodDays": 2089> "cleanupPeriodDays": 20
90}90> }
91```91> ```
92 92
93## 团队的共享设置93## 团队的共享设置
94 94
100* **hook 是仓库中的脚本。** 此文件的 hook 运行 `.claude/hooks/block-rm.sh`;[How a hook resolves](https://code.claude.com/docs/zh-CN/hooks.md#how-a-hook-resolves) 介绍了如何编写它。100* **hook 是仓库中的脚本。** 此文件的 hook 运行 `.claude/hooks/block-rm.sh`;[How a hook resolves](https://code.claude.com/docs/zh-CN/hooks.md#how-a-hook-resolves) 介绍了如何编写它。
101* **规则匹配按写入的命令和路径。** `Bash(git push *)` 不匹配 [`git -C . push`](https://code.claude.com/docs/zh-CN/permissions#bash-rule-limits)。`Read(./.env)` 单独停止文件工具和命名文件的命令,例如 `cat .env`,但不停止 [`grep -r` 在目录上运行](https://code.claude.com/docs/zh-CN/permissions#read-and-edit);此文件中的 `sandbox` 块关闭了该间隙,因为 sandbox [添加你的 `Read` deny 路径](https://code.claude.com/docs/zh-CN/settings-reference#sandbox-filesystem-denyread) 到每个沙箱命令无法读取的内容。101* **规则匹配按写入的命令和路径。** `Bash(git push *)` 不匹配 [`git -C . push`](https://code.claude.com/docs/zh-CN/permissions#bash-rule-limits)。`Read(./.env)` 单独停止文件工具和命名文件的命令,例如 `cat .env`,但不停止 [`grep -r` 在目录上运行](https://code.claude.com/docs/zh-CN/permissions#read-and-edit);此文件中的 `sandbox` 块关闭了该间隙,因为 sandbox [添加你的 `Read` deny 路径](https://code.claude.com/docs/zh-CN/settings-reference#sandbox-filesystem-denyread) 到每个沙箱命令无法读取的内容。
102 102
103**Copyable settings file**103> [tab] Copyable settings file
104 104>
105将其保存为仓库顶部的 `.claude/settings.json` 并提交。这是有效的 JSON,没有注释,因此你可以按原样粘贴它并删除你不想要的键。105> 将其保存为仓库顶部的 `.claude/settings.json` 并提交。这是有效的 JSON,没有注释,因此你可以按原样粘贴它并删除你不想要的键。
106 106>
107```json .claude/settings.json theme={null}107> ```json .claude/settings.json theme={null}
108{108> {
109 "permissions": {109> "permissions": {
110 "allow": [110> "allow": [
111 "Bash(npm run *)"111> "Bash(npm run *)"
112 ],112> ],
113 "ask": [113> "ask": [
114 "Bash(git push *)"114> "Bash(git push *)"
115 ],115> ],
116 "deny": [116> "deny": [
117 "Read(./.env)",117> "Read(./.env)",
118 "Read(./.env.*)",118> "Read(./.env.*)",
119 "Read(./secrets/**)"119> "Read(./secrets/**)"
120 ]120> ]
121 },121> },
122 "hooks": {122> "hooks": {
123 "PreToolUse": [123> "PreToolUse": [
124 {124> {
125 "matcher": "Bash",125> "matcher": "Bash",
126 "hooks": [126> "hooks": [
127 {127> {
128 "type": "command",128> "type": "command",
129 "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/block-rm.sh"129> "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/block-rm.sh"
130 }130> }
131 ]131> ]
132 }132> }
133 ]133> ]
134 },134> },
135 "extraKnownMarketplaces": {135> "extraKnownMarketplaces": {
136 "acme-tools": {136> "acme-tools": {
137 "source": {137> "source": {
138 "source": "github",138> "source": "github",
139 "repo": "acme-corp/claude-plugins"139> "repo": "acme-corp/claude-plugins"
140 }140> }
141 }141> }
142 },142> },
143 "enabledPlugins": {143> "enabledPlugins": {
144 "code-formatter@acme-tools": true144> "code-formatter@acme-tools": true
145 },145> },
146 "sandbox": {146> "sandbox": {
147 "enabled": true,147> "enabled": true,
148 "filesystem": {148> "filesystem": {
149 "allowWrite": [149> "allowWrite": [
150 "/tmp/build"150> "/tmp/build"
151 ]151> ]
152 },152> },
153 "network": {153> "network": {
154 "allowedDomains": [154> "allowedDomains": [
155 "registry.npmjs.org",155> "registry.npmjs.org",
156 "*.example.com"156> "*.example.com"
157 ]157> ]
158 }158> }
159 },159> },
160 "plansDirectory": "./plans"160> "plansDirectory": "./plans"
161}161> }
162```162> ```
163 163
164**What each key does**164> [tab] What each key does
165 165>
166同一个文件,每个键上方都有注释。在这里阅读;从另一个选项卡复制,因为 Claude Code 不接受设置文件中的注释。166> 同一个文件,每个键上方都有注释。在这里阅读;从另一个选项卡复制,因为 Claude Code 不接受设置文件中的注释。
167 167>
168```jsonc .claude/settings.json theme={null}168> ```jsonc .claude/settings.json theme={null}
169{169> {
170 "permissions": {170> "permissions": {
171 // 无需询问即可运行 npm 脚本171> // 无需询问即可运行 npm 脚本
172 "allow": [172> "allow": [
173 "Bash(npm run *)"173> "Bash(npm run *)"
174 ],174> ],
175 // 在 git push 命令前确认175> // 在 git push 命令前确认
176 "ask": [176> "ask": [
177 "Bash(git push *)"177> "Bash(git push *)"
178 ],178> ],
179 // 拒绝文件工具和文件读取命令读取 env 文件和 secrets 文件夹179> // 拒绝文件工具和文件读取命令读取 env 文件和 secrets 文件夹
180 "deny": [180> "deny": [
181 "Read(./.env)",181> "Read(./.env)",
182 "Read(./.env.*)",182> "Read(./.env.*)",
183 "Read(./secrets/**)"183> "Read(./secrets/**)"
184 ]184> ]
185 },185> },
186 // 在每个 Bash 命令之前,运行仓库中可以阻止它的脚本186> // 在每个 Bash 命令之前,运行仓库中可以阻止它的脚本
187 "hooks": {187> "hooks": {
188 "PreToolUse": [188> "PreToolUse": [
189 {189> {
190 "matcher": "Bash",190> "matcher": "Bash",
191 "hooks": [191> "hooks": [
192 {192> {
193 "type": "command",193> "type": "command",
194 "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/block-rm.sh"194> "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/block-rm.sh"
195 }195> }
196 ]196> ]
197 }197> }
198 ]198> ]
199 },199> },
200 // 在每个克隆上注册团队的插件市场200> // 在每个克隆上注册团队的插件市场
201 "extraKnownMarketplaces": {201> "extraKnownMarketplaces": {
202 "acme-tools": {202> "acme-tools": {
203 "source": {203> "source": {
204 "source": "github",204> "source": "github",
205 "repo": "acme-corp/claude-plugins"205> "repo": "acme-corp/claude-plugins"
206 }206> }
207 }207> }
208 },208> },
209 // 启用该市场中的一个插件;来自外部源(例如 GitHub 仓库)的插件仍然需要每个人安装一次209> // 启用该市场中的一个插件;来自外部源(例如 GitHub 仓库)的插件仍然需要每个人安装一次
210 "enabledPlugins": {210> "enabledPlugins": {
211 "code-formatter@acme-tools": true211> "code-formatter@acme-tools": true
212 },212> },
213 // 沙箱命令:可写的构建目录;npm 和 example.com 预先允许213> // 沙箱命令:可写的构建目录;npm 和 example.com 预先允许
214 "sandbox": {214> "sandbox": {
215 "enabled": true,215> "enabled": true,
216 "filesystem": {216> "filesystem": {
217 "allowWrite": [217> "allowWrite": [
218 "/tmp/build"218> "/tmp/build"
219 ]219> ]
220 },220> },
221 "network": {221> "network": {
222 "allowedDomains": [222> "allowedDomains": [
223 "registry.npmjs.org",223> "registry.npmjs.org",
224 "*.example.com"224> "*.example.com"
225 ]225> ]
226 }226> }
227 },227> },
228 // 将计划文件保存在仓库内228> // 将计划文件保存在仓库内
229 "plansDirectory": "./plans"229> "plansDirectory": "./plans"
230}230> }
231```231> ```
232 232
233## 组织的托管设置233## 组织的托管设置
234 234
247 247
248管理员将这样的文件部署为 `managed-settings.json`,或通过 MDM 或 [server-managed settings](https://code.claude.com/docs/zh-CN/server-managed-settings.md) 部署相同的 JSON。一个部署的文件适用于它到达的每台机器或帐户。要为一个组提供不同的值,请将不同的文件或配置文件部署到该组,因为 [server-managed settings 还不支持按组策略](https://code.claude.com/docs/zh-CN/server-managed-settings.md#current-limitations)。248管理员将这样的文件部署为 `managed-settings.json`,或通过 MDM 或 [server-managed settings](https://code.claude.com/docs/zh-CN/server-managed-settings.md) 部署相同的 JSON。一个部署的文件适用于它到达的每台机器或帐户。要为一个组提供不同的值,请将不同的文件或配置文件部署到该组,因为 [server-managed settings 还不支持按组策略](https://code.claude.com/docs/zh-CN/server-managed-settings.md#current-limitations)。
249 249
250**Copyable settings file**250> [tab] Copyable settings file
251 251>
252将其部署为 `managed-settings.json`,或通过 MDM 或 claude.ai 控制台部署相同的 JSON。这是有效的 JSON,没有注释;将示例组织 UUID、服务器 URL 和市场替换为你自己的,并删除你不想要的键。252> 将其部署为 `managed-settings.json`,或通过 MDM 或 claude.ai 控制台部署相同的 JSON。这是有效的 JSON,没有注释;将示例组织 UUID、服务器 URL 和市场替换为你自己的,并删除你不想要的键。
253 253>
254```json managed-settings.json theme={null}254> ```json managed-settings.json theme={null}
255{255> {
256 "forceLoginMethod": "claudeai",256> "forceLoginMethod": "claudeai",
257 "forceLoginOrgUUID": [257> "forceLoginOrgUUID": [
258 "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"258> "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
259 ],259> ],
260 "availableModels": [260> "availableModels": [
261 "opus",261> "opus",
262 "sonnet"262> "sonnet"
263 ],263> ],
264 "enforceAvailableModels": true,264> "enforceAvailableModels": true,
265 "permissions": {265> "permissions": {
266 "deny": [266> "deny": [
267 "Bash(curl *)",267> "Bash(curl *)",
268 "Read(./.env)",268> "Read(./.env)",
269 "Read(./secrets/**)"269> "Read(./secrets/**)"
270 ],270> ],
271 "disableBypassPermissionsMode": "disable"271> "disableBypassPermissionsMode": "disable"
272 },272> },
273 "allowManagedPermissionRulesOnly": true,273> "allowManagedPermissionRulesOnly": true,
274 "allowedMcpServers": [274> "allowedMcpServers": [
275 {275> {
276 "serverUrl": "https://api.githubcopilot.com/*"276> "serverUrl": "https://api.githubcopilot.com/*"
277 }277> }
278 ],278> ],
279 "allowManagedMcpServersOnly": true,279> "allowManagedMcpServersOnly": true,
280 "strictKnownMarketplaces": [280> "strictKnownMarketplaces": [
281 {281> {
282 "source": "github",282> "source": "github",
283 "repo": "acme-corp/approved-plugins"283> "repo": "acme-corp/approved-plugins"
284 }284> }
285 ],285> ],
286 "sandbox": {286> "sandbox": {
287 "enabled": true,287> "enabled": true,
288 "failIfUnavailable": true,288> "failIfUnavailable": true,
289 "allowUnsandboxedCommands": false,289> "allowUnsandboxedCommands": false,
290 "network": {290> "network": {
291 "allowedDomains": [291> "allowedDomains": [
292 "registry.npmjs.org",292> "registry.npmjs.org",
293 "github.com"293> "github.com"
294 ],294> ],
295 "allowManagedDomainsOnly": true295> "allowManagedDomainsOnly": true
296 }296> }
297 },297> },
298 "requiredMinimumVersion": "2.1.150",298> "requiredMinimumVersion": "2.1.150",
299 "cleanupPeriodDays": 7,299> "cleanupPeriodDays": 7,
300 "companyAnnouncements": [300> "companyAnnouncements": [
301 "Welcome to Acme Corp! Review our code guidelines at docs.example.com"301> "Welcome to Acme Corp! Review our code guidelines at docs.example.com"
302 ]302> ]
303}303> }
304```304> ```
305 305
306**What each key does**306> [tab] What each key does
307 307>
308同一个文件,每个键上方都有注释。在这里阅读;从另一个选项卡复制,因为 Claude Code 不接受设置文件中的注释。308> 同一个文件,每个键上方都有注释。在这里阅读;从另一个选项卡复制,因为 Claude Code 不接受设置文件中的注释。
309 309>
310```jsonc managed-settings.json theme={null}310> ```jsonc managed-settings.json theme={null}
311{311> {
312 // 仅 claude.ai 登录,且仅在此组织中312> // 仅 claude.ai 登录,且仅在此组织中
313 "forceLoginMethod": "claudeai",313> "forceLoginMethod": "claudeai",
314 "forceLoginOrgUUID": [314> "forceLoginOrgUUID": [
315 "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"315> "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
316 ],316> ],
317 // 仅 Opus 和 Sonnet 模型;使用 enforceAvailableModels,默认选项也遵守列表317> // 仅 Opus 和 Sonnet 模型;使用 enforceAvailableModels,默认选项也遵守列表
318 "availableModels": [318> "availableModels": [
319 "opus",319> "opus",
320 "sonnet"320> "sonnet"
321 ],321> ],
322 "enforceAvailableModels": true,322> "enforceAvailableModels": true,
323 "permissions": {323> "permissions": {
324 // 在每台机器上拒绝 curl 命令和读取项目的 .env 文件和 secrets 文件夹324> // 在每台机器上拒绝 curl 命令和读取项目的 .env 文件和 secrets 文件夹
325 "deny": [325> "deny": [
326 "Bash(curl *)",326> "Bash(curl *)",
327 "Read(./.env)",327> "Read(./.env)",
328 "Read(./secrets/**)"328> "Read(./secrets/**)"
329 ],329> ],
330 // 从每个会话中删除绕过权限模式330> // 从每个会话中删除绕过权限模式
331 "disableBypassPermissionsMode": "disable"331> "disableBypassPermissionsMode": "disable"
332 },332> },
333 // 忽略来自用户、项目和本地设置的权限规则333> // 忽略来自用户、项目和本地设置的权限规则
334 "allowManagedPermissionRulesOnly": true,334> "allowManagedPermissionRulesOnly": true,
335 // 仅 GitHub MCP 服务器,通过 URL 而不是名称匹配,因为用户可以335> // 仅 GitHub MCP 服务器,通过 URL 而不是名称匹配,因为用户可以
336 // 将任何服务器命名为 "github"。不匹配的用户添加的服务器不会加载,包括336> // 将任何服务器命名为 "github"。不匹配的用户添加的服务器不会加载,包括
337 // 当列表仅有 URL 条目时的每个 stdio 服务器。下面的 allowManagedMcpServersOnly337> // 当列表仅有 URL 条目时的每个 stdio 服务器。下面的 allowManagedMcpServersOnly
338 // 键使此托管列表成为唯一适用的允许列表338> // 键使此托管列表成为唯一适用的允许列表
339 "allowedMcpServers": [339> "allowedMcpServers": [
340 {340> {
341 "serverUrl": "https://api.githubcopilot.com/*"341> "serverUrl": "https://api.githubcopilot.com/*"
342 }342> }
343 ],343> ],
344 "allowManagedMcpServersOnly": true,344> "allowManagedMcpServersOnly": true,
345 // 插件只能来自此市场345> // 插件只能来自此市场
346 "strictKnownMarketplaces": [346> "strictKnownMarketplaces": [
347 {347> {
348 "source": "github",348> "source": "github",
349 "repo": "acme-corp/approved-plugins"349> "repo": "acme-corp/approved-plugins"
350 }350> }
351 ],351> ],
352 // 对 Claude 运行的每个命令进行沙箱处理,如果无法设置沙箱则拒绝启动,352> // 对 Claude 运行的每个命令进行沙箱处理,如果无法设置沙箱则拒绝启动,
353 // 并且永远不要让被阻止的命令在沙箱外重试;网络353> // 并且永远不要让被阻止的命令在沙箱外重试;网络
354 // 限制为 npm 和 GitHub,用户无法添加域354> // 限制为 npm 和 GitHub,用户无法添加域
355 "sandbox": {355> "sandbox": {
356 "enabled": true,356> "enabled": true,
357 "failIfUnavailable": true,357> "failIfUnavailable": true,
358 "allowUnsandboxedCommands": false,358> "allowUnsandboxedCommands": false,
359 "network": {359> "network": {
360 "allowedDomains": [360> "allowedDomains": [
361 "registry.npmjs.org",361> "registry.npmjs.org",
362 "github.com"362> "github.com"
363 ],363> ],
364 "allowManagedDomainsOnly": true364> "allowManagedDomainsOnly": true
365 }365> }
366 },366> },
367 // 拒绝在 2.1.150 之前的版本上启动367> // 拒绝在 2.1.150 之前的版本上启动
368 "requiredMinimumVersion": "2.1.150",368> "requiredMinimumVersion": "2.1.150",
369 // 7 天后删除会话记录和其他本地会话数据369> // 7 天后删除会话记录和其他本地会话数据
370 "cleanupPeriodDays": 7,370> "cleanupPeriodDays": 7,
371 // 每个用户在启动时看到的消息371> // 每个用户在启动时看到的消息
372 "companyAnnouncements": [372> "companyAnnouncements": [
373 "Welcome to Acme Corp! Review our code guidelines at docs.example.com"373> "Welcome to Acme Corp! Review our code guidelines at docs.example.com"
374 ]374> ]
375}375> }
376```376> ```