Chuyên sâu
⏱ 25 phút
14
Custom Commands và Settings Nâng cao
Tạo slash commands riêng cho team, cấu hình permissions và tối ưu settings.json
🎯 Mục tiêu bài học
- ✓ Tạo custom slash commands tái sử dụng
- ✓ Cấu hình permissions allowlist giảm friction
- ✓ Thiết lập settings.json tối ưu cho team
- ✓ Dùng /schedule cho tác vụ tự động định kỳ
Custom Slash Commands
Tạo slash commands riêng bằng cách đặt file .md trong
.claude/commands/. Nội dung file là prompt sẽ được gửi khi dùng command.
project/
└── .claude/
└── commands/
├── deploy.md # /deploy
├── test-coverage.md # /test-coverage
└── daily-review.md # /daily-review
Ví dụ: /deploy
# .claude/commands/deploy.md
Chuan bi deploy cho du an nay:
1. Chay tat ca tests, dung neu co loi
2. Build production bundle
3. Kiem tra khong co console.log trong src/
4. Tao git tag version moi
5. Bao cao tom tat nhung gi can lam thu cong
Ví dụ: /test-coverage
# .claude/commands/test-coverage.md
Phan tich va cai thien test coverage:
1. Chay: pytest --cov=app --cov-report=term-missing
2. Tim 3 functions co coverage thap nhat
3. Viet tests bo sung cho 3 functions do
4. Chay lai va bao cao ket qua
Cấu hình Permissions Allowlist
Giảm số lần bị hỏi xác nhận bằng cách whitelist các lệnh an toàn:
# .claude/settings.json
{
"permissions": {
"allow": [
"Bash(npm run test*)",
"Bash(npm run lint*)",
"Bash(git status)",
"Bash(git diff*)",
"Bash(git log*)",
"Bash(pytest*)",
"Bash(python -m*)"
],
"deny": [
"Bash(git push --force*)",
"Bash(rm -rf*)"
]
}
}
Settings.json đầy đủ cho team
{
"model": "claude-sonnet-4-6",
"permissions": {
"allow": ["Bash(npm*)", "Bash(git status)", "Bash(pytest*)"]
},
"hooks": {
"PostToolUse": [{
"matcher": "Edit|Write",
"hooks": [{"type": "command", "command": "black . 2>/dev/null; true"}]
}]
},
"mcpServers": {
"github": {
"command": "npx",
"args": ["@anthropic-ai/mcp-github"],
"env": {"GITHUB_TOKEN": "${GITHUB_TOKEN}"}
}
}
}
/schedule — Tác vụ định kỳ
# Lich automated tasks
> /schedule
# Tao mot routine: moi sang 9h chay /daily-review
# Ket qua gui vao Slack channel #dev-team
💡 Commit settings.json vào Git
Commit .claude/settings.json và .claude/commands/ vào repo để toàn team dùng chung cùng một cấu hình và commands.