Claude
5 分钟极速配置 Claude,一套模板搞定全套项目配置
一套包含 CLAUDE.md、settings.json 和常用 skills 的 Claude 快速配置模版,帮助你 5 分钟配置完新项目。
• 1 分钟阅读
以 Claude 为例,当你开启一个新项目时,需要耗费多少时间进行 Claude 配置?
每个新项目开始时都没有 CLAUDE.md,没有 settings.json,没有配套的 skills。Claude 不了解你的技术栈,每个命令都需要请求权限。
下面我会介绍一个包含 3 个配置文件和 3 个常用 skills 的完整套件,将它放到你的任何项目中,只需 5 分钟,即可完成你的项目配置。
快快收藏起来吧。
文件 1:Claude.md
这是 Claude 读取的第一个文件。包含命令、架构、规则,总共不到 60 行。
# CLAUDE.md
## Project
[一句话概括:该项目的作用]
## Stack
[框架、语言、数据库、部署目标]
## Commands
- Dev: `pnpm dev`
- Build: `pnpm build`
- Test single: `pnpm vitest run src/lib/__tests__/[file]`
- Test all: `pnpm test`
- Lint: `pnpm lint --fix`
- Type check: `npx tsc --noEmit`
## Architecture
- src/app/ → pages and API routes
- src/components/ → stateless UI components
- src/lib/services/ → business logic and data fetching
- src/lib/hooks/ → custom React hooks
- src/lib/utils/ → shared helpers
- src/lib/types/ → TypeScript types
## Rules
- NEVER commit .env files or secrets
- All database queries through src/lib/services/, never in components
- All async calls must use try/catch
- Prefix commits: feat:, fix:, docs:, refactor:, test:, chore:
- IMPORTANT: run type check after every code change
- No console.log in production code
## Workflow
- Ask before making architectural decisions
- Make minimal changes, don't refactor unrelated code
- Run tests after every change, fix failures before moving on
- Create separate commits per logical change
- When unsure between two approaches, explain both and let me choose
## Out of scope
- migrations/ → managed by ORM CLI, don't create manually
- public/assets/ → static files, don't modify
- .github/workflows/ → CI/CD, don't touch without asking
将[括号]部分替换为你的真实项目详情,可以删除不适用部分。
文件 2:setting.json
包含权限配置和 hooks。配置后,Claude 不会再重复请求安全命令的权限,并且会拦截危险的命令。
{
"permissions": {
"allow": [
"Read",
"Glob",
"Grep",
"LS",
"Edit",
"MultiEdit",
"Write(src/**)",
"Write(tests/**)",
"Write(docs/**)",
"Bash(npm run *)",
"Bash(pnpm *)",
"Bash(npm install *)",
"Bash(npm test *)",
"Bash(npx tsc *)",
"Bash(npx vitest *)",
"Bash(npx prettier *)",
"Bash(npx eslint *)",
"Bash(git status)",
"Bash(git diff *)",
"Bash(git log *)",
"Bash(git add *)",
"Bash(git commit *)",
"Bash(git checkout *)",
"Bash(git branch *)",
"Bash(cat *)",
"Bash(head *)",
"Bash(tail *)",
"Bash(wc *)",
"Bash(find *)",
"Bash(echo *)"
],
"deny": [
"Read(**/.env*)",
"Read(**/.dev.vars*)",
"Read(**/*.pem)",
"Read(**/*.key)",
"Read(**/secrets/**)",
"Read(**/credentials/**)",
"Read(**/.aws/**)",
"Read(**/.ssh/**)",
"Read(**/.npmrc)",
"Write(**/.env*)",
"Write(**/secrets/**)",
"Write(**/.ssh/**)",
"Write(.github/workflows/*)",
"Write(package-lock.json)",
"Bash(rm -rf *)",
"Bash(sudo *)",
"Bash(git push *)",
"Bash(git merge *)",
"Bash(git rebase *)",
"Bash(npm publish *)",
"Bash(docker *)",
"Bash(curl * | sh)",
"Bash(wget *)",
"Bash(chmod *)"
],
"defaultMode": "acceptEdits"
},
"hooks": {
"PostToolUse": [
{
"matcher": "Write(*.ts)",
"hooks": [
{
"type": "command",
"command": "npx prettier --write $file"
}
]
},
{
"matcher": "Write(*.tsx)",
"hooks": [
{
"type": "command",
"command": "npx prettier --write $file"
}
]
}
]
}
}
文件 3:.gitignore
# Dependencies
node_modules/
.pnp.*
# Build
dist/
build/
.next/
out/
# Environment
.env
.env.*
!.env.example
# AI tools
.claude/settings.local.json
.cursor/
.aider*
.continue/
.cody/
# Secrets & credentials
*.pem
*.key
*.p12
credentials.json
service-account*.json
.npmrc
.aws/
.ssh/
.docker/config.json
# IDE
.vscode/settings.json
.idea/
# OS
.DS_Store
Thumbs.db
# Logs & coverage
*.log
coverage/
.nyc_output/
# Terraform
.terraform/
*.tfstate
*.tfstate.backup
注意:.claude/settings.local.json 应该被 git 忽略,但 .claude/settings.json 和 .claude/skills/ 需要被提交,以便团队之间进行共享。
3 个 skills
每项技能都是一个 SKILL.md 文件,位于 .claude/skills/[name]/ 目录内。
/review
---
name: review
description: Review code for bugs, security issues, and style violations.
Use when reviewing PRs, checking code quality, or when user mentions
"review", "PR", "code quality".
allowed-tools: Read, Grep, Glob, Bash(git diff *)
---
Review the current diff or specified files for:
1. Bugs: logic errors, null handling, race conditions
2. Security: hardcoded secrets, SQL injection, XSS
3. Performance: N+1 queries, unnecessary re-renders
4. Style: naming, dead code, TODOs
Output as checklist grouped by severity: CRITICAL / WARNING / INFO
End with summary: "X critical, Y warnings, Z info"
/commit
---
name: commit
description: Create structured git commits from current changes.
Use when user says "commit", "save changes", or after finishing a feature.
allowed-tools: Read, Bash(git *)
---
1. Run `git status` and `git diff` to see all changes
2. Group related changes into logical units
3. For each unit, create a commit:
type(scope): description under 50 chars
- What changed
- Why (if not obvious)
4. Stage and commit each unit separately
5. Show summary: "Created N commits: [titles]"
Types: feat, fix, refactor, docs, test, chore
/deploy-check
---
name: deploy-check
description: Run pre-deployment checks. Use when user mentions
"deploy", "ship", "release", or "production".
allowed-tools: Read, Bash(npm *), Bash(npx tsc *), Bash(git *), Grep
---
Run in order, stop at first failure:
1. `npx tsc --noEmit` — types pass
2. `npm test` — tests pass
3. `npm run lint` — no lint errors
4. `npm run build` — build succeeds
5. grep for console.log in src/
6. Check for .env references in committed code
7. git status — no uncommitted changes
Output: ✅ or ❌ per check
Summary: "Ready to deploy" or "N issues to fix first"
自定义内容
记住,不要永久使用并保持这些文件的原样,它们只是一个起点。使用一段时间后,你应该:
CLAUDE.md:在每次 Claude 出错时添加对应规则。告诉 Claude “更新CLAUDE.md以防止这种情况再次发生”。settings.json:调整 Write 范围以适应你的项目结构,为你的特定工具添加 Bash 规则。- Skills:修改
/review以检查特定于你代码库的模式。 .gitignore:按需添加
这个套件应该随时间不断累积,到两三个月后,你的 CLAUDE.md 会记录 Claude 在你的项目中犯过的所有错误,并且能避免再次犯错。