最新资讯
dev.to 如何将 PostgreSQL 接入 AI agent 并对写入操作设置审批 unite.ai AWS 在 SageMaker 推理端点加入 NVIDIA GPU 分区支持 unite.ai BMO 在信用卡客服引入 agentic AI 案件准备 theverge.com Meta 的 Muse AI 可创建自定义 spaces,按需生成应用式体验 thenewstack.io Meta 用最强 AI 模型训练多数用户实际使用的模型 bloomberg.com Anthropic IPO 买家估值预期低至 1.1 万亿美元 dev.to 用 Switch 构建 AI 投资委员会:多空研究员 Agent 协作 bloomberg.com 微软正结束向甲骨文租用 AI 云算力的协议 the-decoder.com Perplexity 推出常驻 AI Agent“Teammates” dev.to osFoundry的Loop和Graph是什么,何时该用哪个? dev.to 限制上下文而非限制评审:面向开源补丁的字节预算证据包 dev.to 约束自主智能体:用 GKE Agent Sandbox 实现亚秒级零信任执行
多元动态
登录 注册
AI编码 dev.to · @quintetkit

把配置写进项目 settings.json 却毫无效果:Claude Code 设置的作用域陷阱

原文 我的收藏

作者发现将 autoMode 写入 .claude/settings.json 后完全无效:JSON 合法、启动无警告、--debug 也无输出,原因是该键不从该文件作用域生效。作者统计 Claude Code 设置参考中 223 个键有 71 个受作用域限制,例如 autoMode、autoMode.classifyAllShell、skipAutoPermissionPrompt、spellcheck、sandbox.network.strictAllowlist 等仅支持 user 或 managed 作用域,diffTool、autoConnectIde 仅支持 ~/.claude.json;另有 useAutoModeDuringPlan、syncClaudeAiSkills、skipDangerousModePermissionPrompt 三个键仅从 settings.local.json 生效,从共享的 settings.json 移入后会静默失效。嵌套键按完整点号名限定作用域,如 sandbox.network.strictAllowlist 受限而 sandbox 本身不受限。

AI推荐理由 作者基于 Claude Code 设置参考文档逐项统计 223 个配置键,指出其中 71 个键受作用域限制,把 autoMode 等键写入项目级 .claude/settings.json 不会报错、不告警也不生效,并列出 settings.local.json 与 settings.json 作用域不同的三个键及嵌套键按完整点号名限定的问题。这是对具体工具配置行为的可复现观察,对使用 Claude Code 的开发者有直接排错价值;局限在于结论依赖作者对官方文档的解读,未附官方确认或版本号。

72

正文

I put autoMode in .claude/settings.json, committed it, and it had no effect. The JSON was valid. Startup printed no warning. --debug said nothing. I spent a while assuming I had the semantics wrong before I found the actual reason: that key does not apply from that file. Settings have a scope, and the scope is not in the file Claude Code's settings reference has a column I had never read carefully. Every key names the scopes it applies from. Counting it: Any file 152 keys Managed 39 keys only from managed settings User or managed 23 keys ~/.claude/settings.json, or managed User, local, or managed 3 keys settings.local.json but not settings.json Global config 6 keys ~/.claude.json only ------------------------------------ 223 keys, of which 71 are scoped Enter fullscreen mode Exit fullscreen mode 71 of 223. Put one of those in a project's .claude/settings.json and it is not an error, produces no warning, and does nothing. The ones I would expect people to hit: autoMode user or managed autoMode.classifyAllShell user or managed skipAutoPermissionPrompt user or managed useAutoModeDuringPlan user, local, or managed spellcheck user or managed sandbox.network.strictAllowlist user or managed sandbox.filesystem.disabled user or managed diffTool ~/.claude.json only autoConnectIde ~/.claude.json only Enter fullscreen mode Exit fullscreen mode If you run several agents at once you get more approval prompts, so loosening autoMode is the obvious move — and the obvious place to put it is the project config you already have open. That is the one place it does not work. The row that will cost you a debugging session User, local, or managed 3 keys Enter fullscreen mode Exit fullscreen mode settings.local.json is a different scope from settings.json. Three keys apply from the local one and not from the shared one: useAutoModeDuringPlan syncClaudeAiSkills skipDangerousModePermissionPrompt So: you put one in settings.local.json, it works. Later you move it into the shared file so the team gets it, and it silently stops. Nothing changed except which file it lives in. This is a manufactured "works on my machine" — with the unusual property that the person who wrote it is the one for whom it works. Nested keys are scoped by their full dotted name The documentation names them the way you would write a path, not the way you would write JSON: sandbox.network.strictAllowlist ← this is what is scoped sandbox ← this is not Enter fullscreen mode Exit fullscreen mode Which matters if you go looking. I wrote a checker for this and inspected only the top level of the settings object, so this: { "sandbox": { "network": { "strictAllowlist": true } } } Enter fullscreen mode Exit fullscreen mode produced nothing at all. 20 dotted keys were invisible to it, 12 of them sandbox.*. How I found out how wrong I was I had been maintaining this list by hand, copied out of the documentation, with a comment I wrote myself: /** そのファイルからは効かないスコープのキー(一部。確実なものだけ) */ Enter fullscreen mode Exit fullscreen mode "Some. Only the certain ones." I knew it was partial. I did not know how partial. actual I had Managed 39 14 User or managed 23 0 ← the whole row Global config 6 6 Enter fullscreen mode Exit fullscreen mode The user or managed row was missing entirely — 23 keys, including autoMode, the one that started this. I had read the table by grouping it: Managed is for organisations deploying policy, which is not my situation, so I skipped past it — and past the row sitting next to it, which turned out to mean "applies from your own ~/.claude/settings.json" and was the row I most needed. Reading it row by row would have worked. Reading it by category is what failed. So it is generated now, straight from the scope column, and the count comes out of the same place the checker reads. Checking yours npx @quintetkit/ccheck Enter fullscreen mode Exit fullscreen mode warn .claude/settings.json:63 `autoMode` applies from user or managed settings only. It has no effect from this file. why: https://code.claude.com/docs/en/settings-reference Enter fullscreen mode Exit fullscreen mode One thing that took a second pass to get right: ~/.claude/settings.json is the user scope. Deciding "this key doesn't apply here" from the path alone would report a correctly placed autoMode on the machine of anyone who runs it against their home directory — including mine, which has autoMode in it. So the scope is decided by whether the directory being scanned is your home, not by what the path looks like. The full list of 71, and the same list as JSON if you would rather check the claim than trust it: https://quintetkit.github.io/en/reference/claude-code-settings-scope.html I publish the configuration for splitting Claude Code into separate personas — Architect, Coder, Reviewer, Conflict Resolver — under MIT. Copy it, run ./setup.sh, and it works. It does not depend on your tech stack. https://github.com/quintetkit/quartet I built one real tool using nothing but this workflow. Every Issue, PR, review and merge is still there. The parts that went wrong were not deleted. https://github.com/quintetkit/mdlinkcheck The version that adds a UI Designer persona, review criteria, a per-Issue parallel execution script and a 11-chapter guide is on the product page. The full kit — five personas, the scripts and the complete guide — is available here. https://quintetkit.gumroad.com/l/quintet

来源报道 · 1 篇 · 以下链接均前往原始媒体

← 返回精选动态 原文

更多内容