来源:howborisusesclaudecode.com · ykdojo/claude-code-tips · r/ClaudeCode | 整理时间:2026-04-04
概述
本篇整理了来自 Claude Code 创建者 Boris Cherny、GitHub 社区和 Reddit 社区的实战技巧。这些技巧经过大量开发者验证,可以显著提升 Claude Code 的使用效率。
来自创建者 Boris Cherny 的技巧
Boris Cherny 是 Claude Code 的创建者,他在 howborisusesclaudecode.com 分享了 72 个使用技巧。
核心建议
1. "Surprisingly vanilla"
大多数人以为创建者会有极其复杂的配置,实际上 Claude Code 开箱即用就很好。不需要过度定制。
2. 每个人用法不同
团队中每个人使用 Claude Code 的方式都不同,没有唯一的"正确用法"。找到适合自己的方式。
3. 善用 /loop 做自动化
# 每 5 分钟自动审查代码
/loop 5m /babysit
# 每 30 分钟自动处理 Slack 反馈
/loop 30m /slack-feedback
# 每小时清理过期的 PR
/loop 1h /pr-pruner
会话管理
4. 用 worktree 做并行开发
# 在独立的 worktree 中工作,互不干扰
claude --worktree feature-auth # 终端 1
claude --worktree bugfix-login # 终端 2
claude --worktree docs-update # 终端 3
5. 命名会话,跨时间恢复
claude -n auth-refactor # 给会话命名
claude --resume auth-refactor # 之后恢复
6. Plan Mode 用于只读分析
# Shift+Tab 切换到 Plan Mode
# Claude 只分析不修改,适合代码审查
来自社区的 Top 技巧
来源:ykdojo/claude-code-tips(45 个技巧)和 Reddit 社区
提示工程
7. "先面试我"技巧
I want to build [brief description].
Interview me in detail using AskUserQuestion.
Ask about technical implementation, UI/UX, edge cases, concerns.
Keep interviewing until we've covered everything, then write SPEC.md.
让 Claude 先充分理解需求,再动手实现,避免返工。
8. SPEC.md 工作流
Write a complete technical spec to SPEC.md first.
Then implement it step by step, checking off each item.
先写规格说明,再逐步实现,保持方向一致。
9. 给具体的验证方式
# 不好
Fix the login bug
# 好
Fix the login bug. After fixing:
1. Run npm test -- --grep "login"
2. Start dev server
3. Test login at localhost:3000/login
10. 用 Gemini CLI 做辅助
社区发现可以通过 tmux 让 Gemini CLI 和 Claude Code 协作:Claude 负责主要开发,Gemini 做辅助审查。
上下文管理
11. 每个任务一个会话
/clear # 在不相关任务之间清除上下文
上下文是有限资源。混合多个不相关任务会降低性能。
12. 用子 Agent 做探索
Use subagents to investigate how the payment system works
# 探索在子 Agent 中完成,不污染主上下文
13. /compact 带指令压缩
/compact Focus on the database schema changes
# 保留关键信息,丢弃无关对话
14. /init 后手动精简
/init # 自动生成 CLAUDE.md
# 然后手动删掉 Claude 能自己推断的内容
# 目标:200 行以内
开发工作流
15. 容器化开发
# 在 Docker 容器中运行 Claude Code
# 环境隔离,安全可控
docker run -it -v $(pwd):/workspace claude-code
16. 声音输入
使用语音转文字工具(如 Whisper)输入复杂需求,比打字快得多。
17. 可视化 Git 客户端
配合 Git Graph、Lazygit 等工具,直观查看 Claude 的修改历史。
18. 沙盒测试
# 在独立环境中测试 Claude 的修改
claude --worktree experiment
# 测试通过后再合并到主分支
生产环境经验
来源:diet103/claude-code-infrastructure-showcase · Reddit 生产案例
案例 1:TypeScript 微服务
6 个月的 TypeScript 微服务开发中,团队总结:
- 用 Hook 激活技能——解决了"技能不自动激活"的问题
- 分层 CLAUDE.md——全局 + 项目 + 模块三层配置
- CI/CD 集成——PR 自动审查,质量门禁
案例 2:7 小时 = 1-2 周工作量
StarMorph 团队使用三阶段系统:
- Phase 1:Opus 做深度研究和规划
- Phase 2:制定详细实施计划
- Phase 3:Sonnet 做快速实现
非技术创始人用 Claude Code 构建原型,赢得了政府合同。
案例 3:"Genome" 文件方法
Reddit 用户(437 upvotes)分享的五阶段生命周期:
- Objective — 明确目标
- Planning — 制定计划
- Implementation — 实现
- Validation — 验证
- Completion — 完成
维护一个"Genome"文件记录架构原则,跨会话保持一致性。
核心教训:跳过规划阶段是致命的。
常见错误与修复
| 错误 | 症状 | 修复 |
|---|---|---|
| 堆砌会话 | 上下文杂乱,回答质量下降 | /clear 分隔任务 |
| 反复纠错 | 改了 3 次还不对 | 清空上下文,重写 prompt |
| CLAUDE.md 太长 | Claude 忽略部分指令 | 精简到 200 行以内 |
| 无限探索 | Claude 读了几百个文件 | 明确范围,用子 Agent 隔离 |
| 跳过验证 | 代码看起来对但边界情况没处理 | 始终要求 Claude 运行测试 |
| 过度定制 | 配了一堆 Hook 和 Skill,变慢了 | 只配置真正常用的 |
中文用户特别建议
1. 语言切换
从现在起用中文回复我
或在 CLAUDE.md 中加入:
## 偏好
- 使用中文回复
- 代码注释用英文
- commit message 用中文
2. 文档翻译工作流
把这份英文文档翻译成中文,保持技术术语的英文原文(用括号标注)
3. 中文技术社区资源
| 资源 | 链接 |
|---|---|
| Claude Code 中文指南 | https://github.com/claude-code-chinese/claude-code-guide |
| Reddit ClaudeCode | https://www.reddit.com/r/ClaudeCode/ |
| Claude Code 创建者技巧 | https://howborisusesclaudecode.com |
技巧速查表
| 类别 | 技巧 | 命令/方法 |
|---|---|---|
| 会话 | 清除上下文 | /clear |
| 会话 | 压缩上下文 | /compact [focus] |
| 会话 | 命名会话 | claude -n <name> |
| 会话 | 恢复会话 | claude --resume <name> |
| 会话 | 回退操作 | Esc+Esc 或 /rewind |
| 模式 | Plan Mode | Shift+Tab |
| 模式 | 自动模式 | --permission-mode auto |
| 并行 | Worktree | claude --worktree <name> |
| 并行 | 子 Agent | "Use subagents to..." |
| 自动化 | 循环任务 | /loop <interval> <task> |
| 自动化 | 非交互 | claude -p "task" |
| 配置 | 生成 CLAUDE.md | /init |
| 配置 | 查看 Hooks | /hooks |
| 成本 | 查看 Token 用量 | /cost |
相关链接
- 最佳实践
- CLAUDE.md 指南
- 技能与钩子
- 无头模式与 CI/CD
- Boris Cherny 的 72 个技巧:https://howborisusesclaudecode.com
- 45 个社区技巧:https://github.com/ykdojo/claude-code-tips
- 终极指南(含案例研究):https://github.com/FlorianBruniaux/claude-code-ultimate-guide
- Reddit 社区:https://www.reddit.com/r/ClaudeCode/
- 中文指南:https://github.com/claude-code-chinese/claude-code-guide