常用工作流程
一句话
掌握 Claude Code 日常开发工作流程,提高代码探索、调试和重构效率。
什么时候翻这页
- 需要快速理解新加入的代码库结构
- 遇到 bug 需要高效定位和修复
- 计划重构代码或添加测试
- 需要创建拉取请求或更新文档
- 想管理多个并行开发任务
核心概念
- 提示词模式(prompt recipes):针对日常任务的标准化提示词模板,包括代码探索、bug修复、重构等
- 会话恢复:保存对话历史,可跨多个会话继续任务,避免重复解释上下文
- 工作树(worktrees):创建独立的分支环境,支持并行开发而不产生编辑冲突
- 计划模式(plan mode):在修改文件前先展示计划,审查批准后再执行
- 子代理(subagents):将研究任务委托给代理,保持主上下文清洁
- 管道化:将 Claude 集成到脚本中,支持 CI 和批处理任务
怎么做
理解新代码库
- 导航到项目根目录:
cd /path/to/project - 启动 Claude Code:
claude - 请求高层概览:
give me an overview of this codebase - 深入探索特定组件:
explain the main architecture patterns used herewhat are the key data models?how is authentication handled?
修复 bug
- 分享错误信息:
I'm seeing an error when I run npm test - 请求修复建议:
suggest a few ways to fix the @ts-ignore in user.ts - 应用修复:
update user.ts to add the null check you suggested
重构代码
- 识别需要重构的代码:
find deprecated API usage in our codebase - 获取重构建议:
suggest how to refactor utils.js to use modern JavaScript features - 安全应用更改:
refactor utils.js to use ES2024 features while maintaining the same behavior - 验证重构:
run tests for the refactored code
创建拉取请求
- 总结更改:
summarize the changes I've made to the authentication module - 生成 PR:
create a pr - 审查和完善:
enhance the PR description with more context about the security improvements
命令 / 配置速查
| 命令 | 功能 |
|---|---|
claude --continue | 恢复最近的会话 |
claude --worktree <name> | 创建并行会话 |
claude --permission-mode plan | 进入计划模式 |
claude --resume | 选择要恢复的会话 |
claude -p "prompt" | 非交互式运行 Claude |
@<file> | 引用文件内容 |
@<directory> | 引用目录结构 |
初学者易错点
- 忘记使用
@符号引用文件,导致 Claude 需要重新读取文件,降低效率 - 在计划模式下忘记批准修改就直接退出,导致更改未保存
- 使用工作树时没有正确清理,导致分支混乱和冲突
- 在提示词中描述过于模糊,导致 Claude 无法准确理解需求
- 忽略了错误复现步骤,导致难以定位问题根源
相关词条
best-practicesClaude Code 最佳实践指南sessions会话管理与恢复worktrees工作树并行开发large-codebases大型代码库处理mcpMCP 资源使用方法permission-modes权限模式控制