Systematic debugging methods, log analysis, and performance diagnostics. Use when debugging issues, analyzing errors, or troubleshooting incidents.
View on GitHubxiaobei930/claude-code-best-practices
cc-best
January 25, 2026
Select agents to install to:
npx add-skill https://github.com/xiaobei930/claude-code-best-practices/blob/main/skills/debugging/SKILL.md -a claude-code --skill debuggingInstallation paths:
.claude/skills/debugging/# 调试技能
本技能提供系统化的调试方法和技巧。
## 触发条件
- 调试代码问题
- 分析错误日志
- 调查性能问题
- 排查生产事故
- 修复 Bug
## 调试原则
### 黄金法则
1. **复现问题** - 先能稳定复现,再开始调试
2. **最小化** - 找到最小可复现用例
3. **二分法** - 缩小问题范围
4. **假设验证** - 提出假设,验证假设
5. **记录过程** - 记录尝试过的方法
### 调试流程
```
问题描述 → 复现问题 → 缩小范围 → 定位原因 → 修复验证 → 记录总结
```
## 问题描述模板
```markdown
## 问题描述
[简要描述问题现象]
## 预期行为
[期望的正确行为]
## 实际行为
[实际观察到的行为]
## 复现步骤
1. [步骤1]
2. [步骤2]
3. [步骤3]
## 环境信息
- OS: [操作系统]
- Node/Python 版本: [版本]
- 相关依赖版本: [版本]
## 错误信息
[完整的错误堆栈或日志]
## 已尝试的方案
- [ ] 方案1 - 结果
- [ ] 方案2 - 结果
```
## 日志调试
### 有效的日志输出
```typescript
// ❌ 无用的日志
console.log("here");
console.log(data);
// ✅ 有信息量的日志
console.log("[UserService.createUser] 开始创建用户:", {
email: user.email,
timestamp: new Date().toISOString(),
});
console.log("[UserService.createUser] 数据库插入成功:", {
userId: result.id,
duration: Date.now() - startTime,
});
console.error("[UserService.createUser] 创建失败:", {
error: error.message,
stack: error.stack,
input: { email: user.email },
});
```
```python
# ❌ 无用的日志
print("here")
print(data)
# ✅ 有信息量的日志
import logging
logger = logging.getLogger(__name__)
logger.info(f"[create_user] 开始创建用户: email={email}")
logger.info(f"[create_user] 创建成功: user_id={user.id}, duration={duration}ms")
logger.error(f"[create_user] 创建失败: error={str(e)}", exc_info=True)
```
### 日志级别使用
| 级别 | 用途 | 示例 |
| ----- | -------------- | ------------------ |
| DEBUG | 详细调试信息 | 函数参数、中间状态 |
| INFO | 正常操作信息 | 用户登录、订单创建 |
| WARN | 警告但可继续 | 配置缺失使用默认值 |
| ERROR | 错误但可恢复 | API 调用失败重试 |
| FATAL | 致命错误需退出 | 数据库连接失败 |
## 断点调试
### VS Code 调试配置
```json
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Node.js",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/src/index.ts",
"preLaunchTask": "tsc: build",
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
},
{
"name": "Debug Python",
"type": "python",
"request": "l