claude-code-usage
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClaude Code Best Practices
Claude编码最佳实践
Language Rule
语言规则
- Always respond in the same language the user is using. If the user asks in Chinese, respond in Chinese. If in English, respond in English.
- 始终使用与用户相同的语言回应。如果用户用中文提问,就用中文回应;如果用英文提问,就用英文回应。
Context Management Rules
上下文管理规则
| Rule | Why |
|---|---|
| One window = one task | Mixing tasks pollutes context and degrades output quality |
Use | Clean start is more reliable than compressed context |
| Prevents old context from interfering with new work |
| Copy key info to new windows | Don't rely on context persistence — paste critical details |
| 规则 | 原因 |
|---|---|
| 一个窗口对应一项任务 | 混合任务会污染上下文,降低输出质量 |
优先使用 | 全新开始比压缩上下文更可靠 |
复杂任务完成后使用 | 避免旧上下文干扰新工作 |
| 将关键信息复制到新窗口 | 不要依赖上下文持久性——粘贴关键细节 |
Task Execution Strategy
任务执行策略
| Task Type | Recommended Approach |
|---|---|
| Small bug fix (few lines) | Describe directly, let Claude modify in-place |
| Large feature / refactor | |
| Multi-file changes | Must use |
| Code analysis / learning | Ask Claude to analyze directly — no plan needed |
| Debugging | Provide error message + file path + relevant code — ask for root cause |
| 任务类型 | 推荐方案 |
|---|---|
| 小型bug修复(仅几行代码) | 直接描述问题,让Claude就地修改 |
| 大型功能开发 / 代码重构 | |
| 多文件变更 | 必须使用 |
| 代码分析 / 学习 | 直接让Claude分析——无需制定计划 |
| 调试 | 提供错误信息 + 文件路径 + 相关代码——询问根本原因 |
Prompt Techniques
提示词技巧
Do This
建议做法
- Give specific paths: "Modify the function in
_transfer"src/MyToken.sol - Give examples: "Input: 100 tokens, Expected: 95 tokens after 5% fee"
- Set boundaries: "Only modify this function, don't touch other code"
- Reference tests: "The fix should make pass"
test_transfer_feeDeduction
- 提供具体路径:"修改中的
src/MyToken.sol函数"_transfer - 给出示例:"输入:100代币,预期:扣除5%手续费后剩余95代币"
- 设置边界:"仅修改此函数,不要改动其他代码"
- 参考测试用例:"修复需使测试通过"
test_transfer_feeDeduction
Avoid This
避免做法
- Vague references: "Modify that transfer function" — which one? Where?
- Open-ended requests without constraints: "Make it better"
- Multiple unrelated tasks in one message
- 模糊指代:"修改那个转账函数"——哪一个?在哪里?
- 无约束的开放式请求:"让它变得更好"
- 一条消息中包含多个不相关任务
Git Operation Rules
Git操作规则
- Always run before committing to review changes
git diff - Only commit — do not push unless explicitly requested
- Never push directly to main/master branch
- Stage specific files — never use in Solidity projects (risk of committing
git add .).env
- 提交前务必运行来检查变更内容
git diff - 仅执行提交操作——除非明确要求,否则不要推送
- 绝不直接推送到main/master分支
- 暂存指定文件——在Solidity项目中绝不使用(存在提交
git add .文件的风险).env
Foundry-Specific Workflow
Foundry专属工作流
| Action | Command |
|---|---|
| Before committing | |
| After modifying contracts | |
| Before PR | |
| Debugging failed test | |
| 操作 | 命令 |
|---|---|
| 提交前 | |
| 修改合约后 | |
| 发起PR前 | |
| 调试失败的测试用例 | |
Quick Command Reference
快速命令参考
| Command | Purpose |
|---|---|
| Clear context, start fresh |
| Enter planning mode — analyze before modifying |
| View all available commands |
| Compress context (prefer |
| 命令 | 用途 |
|---|---|
| 清空上下文,重新开始 |
| 进入规划模式——修改前先分析 |
| 查看所有可用命令 |
| 压缩上下文(优先使用 |
Project-level Configuration
项目级配置
Create in the project root with project-specific rules. Claude automatically reads it at the start of every conversation — no manual loading needed.
.claude/instructions.md在项目根目录创建文件,写入项目专属规则。Claude会在每次对话开始时自动读取该文件,无需手动加载。
.claude/instructions.md