主题
0.7 全局配置 — 让 Claude Code 按你的习惯工作
学习目标
- 知道 Claude Code 的配置文件在哪
- 复制一份推荐配置直接用
- 理解每个配置项的作用
配置文件在哪?
~/.claude/settings.json- macOS / Linux:
/Users/你的用户名/.claude/settings.json - Windows:
C:\Users\你的用户名\.claude\settings.json
如果不存在,手动创建:
bash
mkdir -p ~/.claude
nano ~/.claude/settings.json推荐配置(直接复制)
下面是一份经过实战验证的配置,直接复制进去就能用:
json
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"language": "chinese",
"outputStyle": "Concise",
"effortLevel": "high",
"alwaysThinkingEnabled": true,
"respectGitignore": false,
"includeGitInstructions": false,
"feedbackSurveyRate": 0,
"spinnerTipsEnabled": true,
"voiceEnabled": true,
"autoDreamEnabled": true,
"autoUpdatesChannel": "stable",
"cleanupPeriodDays": 14,
"permissions": {
"allow": [
"Read",
"Edit",
"Write",
"Glob",
"Grep",
"WebFetch",
"WebSearch",
"Agent",
"Bash(npm *)",
"Bash(npx *)",
"Bash(node *)",
"Bash(bun *)",
"Bash(pnpm *)",
"Bash(git *)",
"Bash(python3 *)",
"Bash(curl *)",
"Bash(ls *)",
"Bash(mkdir *)",
"Bash(rm *)",
"Bash(cp *)",
"Bash(mv *)",
"Bash(cat *)",
"Bash(head *)",
"Bash(tail *)"
],
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)",
"Read(./**/credentials*)"
]
},
"env": {
"CLAUDE_CODE_MAX_OUTPUT_TOKENS": "16000",
"MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES": "3",
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
},
"attribution": {
"commit": "",
"pr": ""
}
}每个配置项的作用
基础设置
| 配置项 | 值 | 作用 |
|---|---|---|
language | "chinese" | 界面和回复用中文 |
outputStyle | "Concise" | 回复简洁不废话(也可以选 "Verbose" 详细模式) |
effortLevel | "high" | 推理深度设为高,回答质量更好 |
alwaysThinkingEnabled | true | 默认开启扩展思考,复杂问题想得更深 |
respectGitignore | false | 不受 .gitignore 限制,所有文件都能看到 |
includeGitInstructions | false | 不自动加 git 上下文(减少 token 消耗) |
feedbackSurveyRate | 0 | 关闭反馈调查弹窗 |
voiceEnabled | true | 开启语音输入功能 |
autoDreamEnabled | true | 开启后台自动任务 |
cleanupPeriodDays | 14 | 临时文件保留 14 天 |
permissions — 权限控制
allow 列表里的操作会自动执行,不需要每次弹窗确认:
| 权限 | 含义 |
|---|---|
Read / Edit / Write | 读/改/创建文件 |
Glob / Grep | 搜索文件名/文件内容 |
WebFetch / WebSearch | 访问网页/搜索 |
Agent | 派出子智能体 |
Bash(git *) | 执行 git 命令 |
Bash(npm *) / Bash(pnpm *) | 执行包管理器命令 |
Bash(node *) / Bash(python3 *) | 运行脚本 |
Bash(curl *) | 下载/请求 |
Bash(ls/mkdir/rm/cp/mv/cat/head/tail *) | 常用文件操作命令 |
deny 列表里的操作会被禁止,即使你手动确认也不行:
json
"deny": [
"Read(./.env)", // 禁止读取环境变量文件(里面有密钥)
"Read(./.env.*)", // 禁止读取所有 .env 变体
"Read(./secrets/**)", // 禁止读取 secrets 目录
"Read(./**/credentials*)" // 禁止读取任何 credentials 文件
]这样即使 Claude Code 想看你的密钥,也看不了。安全第一。
env — 环境变量
| 变量 | 作用 |
|---|---|
CLAUDE_CODE_MAX_OUTPUT_TOKENS | 单次回复最大长度,设大一点避免回复被截断 |
MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES | 自动压缩最大失败次数 |
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS | 设为 "1" 开启团队模式,可以让多个 Claude Code 并行协作(进阶篇会详细讲) |
attribution — Git 署名
json
"attribution": {
"commit": "",
"pr": ""
}设为空字符串 = Claude Code 帮你提交代码时不加任何"AI 生成"的署名。如果你想加署名,可以写:
json
"commit": "Co-Authored-By: Claude <claude@anthropic.com>"配置文件层级
Claude Code 有多层配置,优先级从高到低:
| 层级 | 路径 | 说明 |
|---|---|---|
| 项目本地 | 项目/.claude/settings.local.json | 只影响你自己,不提交 git |
| 项目团队 | 项目/.claude/settings.json | 团队共享,提交到 git |
| 全局用户 | ~/.claude/settings.json | 你的所有项目通用 |
一般只用全局配置就够了。
小结
- 配置文件在
~/.claude/settings.json - 上面的推荐配置直接复制就能用
- 核心是 permissions(权限)— 控制哪些操作自动执行、哪些禁止
- deny 里一定要加
.env和credentials,保护你的密钥 - 配置改完退出 Claude Code 重新进入生效
下一节 → 和 Claude Code 对话的正确姿势