Hướng dẫn Cấu hình
Các Tệp Cấu hình
Claude Code sử dụng nhiều tệp cấu hình để tùy chỉnh trải nghiệm phát triển của bạn:
- Cấu hình Toàn cục:
~/.claude/config.json - Cấu hình Dự án:
./claude.config.jsonhoặc./CLAUDE.md - Biến Môi trường: Cho API keys và thông tin nhạy cảm khác
Cấu hình Toàn cục
Thiết lập Cơ bản
{
"apiKey": "your-api-key",
"model": "claude-3-5-sonnet-20241022",
"outputStyle": "concise",
"planMode": "auto",
"maxTokens": 8192
}
Chi tiết Các Tùy chọn Cấu hình
| Tùy chọn | Kiểu | Mặc định | Mô tả |
|---|---|---|---|
apiKey | string | - | API key Anthropic |
model | string | claude-3-5-sonnet-20241022 | Model Claude sử dụng |
outputStyle | string | balanced | Kiểu output: concise, balanced, verbose |
planMode | string | manual | Chế độ plan: auto, manual, off |
maxTokens | number | 4096 | Số token tối đa |
temperature | number | 0.3 | Mức độ sáng tạo (0-1) |
Cấu hình Dự án
Tệp CLAUDE.md
Tạo tệp CLAUDE.md trong thư mục gốc dự án để cấu hình thiết lập cụ thể cho dự án:
# Project: My Web Application
## Mô tả Dự án
Đây là một ứng dụng web hiện đại sử dụng React + TypeScript.
## Chuẩn Coding
- Sử dụng ESLint + Prettier
- Tuân theo phong cách code Airbnb
- Sử dụng functional components + Hooks
- Ưu tiên TypeScript
## Cấu trúc Tệp
- `src/components/` - React components
- `src/hooks/` - Custom Hooks
- `src/utils/` - Utility functions
- `src/types/` - Định nghĩa type TypeScript
## Ghi chú Quan trọng
- Tất cả API calls cần xử lý lỗi
- Components phải bao gồm PropTypes hoặc TypeScript types
- Tính năng mới cần unit tests tương ứng
claude.config.json
Hoặc sử dụng định dạng JSON cho cấu hình dự án:
{
"project": {
"name": "My Web Application",
"type": "react-typescript",
"framework": "vite"
},
"codeStyle": {
"indentSize": 2,
"quotes": "single",
"semicolons": true,
"trailingComma": "es5"
},
"testing": {
"framework": "jest",
"coverageThreshold": 80
},
"hooks": {
"beforeCommit": ["npm test", "npm run lint"]
}
}
Biến Môi trường
Biến Môi trường Bắt buộc
# Anthropic API key
export ANTHROPIC_API_KEY=your_api_key_here
# Tùy chọn: chỉ định model
export CLAUDE_MODEL=claude-3-5-sonnet-20241022
# Tùy chọn: đường dẫn tệp config tùy chỉnh
export CLAUDE_CONFIG_PATH=/path/to/config.json
Hỗ trợ tệp .env
Tạo tệp .env trong thư mục gốc dự án:
ANTHROPIC_API_KEY=your_api_key_here
CLAUDE_OUTPUT_STYLE=concise
CLAUDE_PLAN_MODE=auto
CLAUDE_MAX_TOKENS=8192
Cấu hình Nâng cao
Agent Tùy chỉnh
{
"agents": {
"codeReviewer": {
"prompt": "Là chuyên gia review code, tập trung vào chất lượng code, hiệu suất và bảo mật",
"model": "claude-3-5-sonnet-20241022",
"temperature": 0.1
},
"documentationWriter": {
"prompt": "Chuyên viết tài liệu kỹ thuật rõ ràng, toàn diện",
"model": "claude-3-haiku-20240307",
"temperature": 0.5
}
}
}
Kiểu Output
{
"outputStyles": {
"development": {
"verbosity": "detailed",
"includeReasoning": true,
"showProgress": true
},
"production": {
"verbosity": "minimal",
"includeReasoning": false,
"showProgress": false
}
}
}
Cấu hình Hooks
{
"hooks": {
"beforeEdit": "npm run format",
"afterEdit": "npm run lint",
"beforeCommit": ["npm test", "npm run build"],
"onError": "echo 'Error occurred, please check logs'"
}
}
Cấu hình Enterprise
Tích hợp Bedrock
{
"provider": "bedrock",
"bedrock": {
"region": "us-east-1",
"modelId": "anthropic.claude-3-sonnet-20240229-v1:0",
"credentials": {
"accessKeyId": "your-access-key",
"secretAccessKey": "your-secret-key"
}
}
}
Tích hợp Vertex AI
{
"provider": "vertex",
"vertex": {
"projectId": "your-gcp-project",
"location": "us-central1",
"modelName": "claude-3-sonnet@20240229",
"credentials": "/path/to/service-account.json"
}
}
Khắc phục Sự cố
Xác thực Cấu hình
Xác thực cấu hình của bạn:
claude config validate
Xem Cấu hình Hiện tại
claude config show
Reset Cấu hình
claude config reset
Template Cấu hình
Template Phát triển Web
{
"project": { "type": "web", "framework": "react" },
"codeStyle": { "prettier": true, "eslint": true },
"testing": { "framework": "jest", "coverage": true },
"deployment": { "platform": "vercel" }
}
Template Phát triển Backend
{
"project": { "type": "backend", "framework": "express" },
"database": { "type": "postgresql", "orm": "prisma" },
"testing": { "framework": "mocha", "integration": true },
"deployment": { "platform": "heroku" }
}
Thực hành Tốt nhất
- Cấu hình Version Control: Bao gồm
claude.config.jsontrong version control - Tách biệt Môi trường: Sử dụng cấu hình khác nhau cho các môi trường khác nhau
- Chuẩn hóa Team: Các thành viên team nên sử dụng cùng cấu hình dự án
- Cập nhật Thường xuyên: Cập nhật cấu hình khi dự án phát triển
Tiếp tục với Cơ chế Cốt lõi để tìm hiểu sâu về cách hoạt động của Claude Code.