claude-code-workflow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseThe key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
文档中的关键词"MUST"、"MUST NOT"、"REQUIRED"、"SHALL"、"SHALL NOT"、"SHOULD"、"SHOULD NOT"、"RECOMMENDED"、"MAY"和"OPTIONAL"应按照RFC 2119中的描述进行解释。
Claude Code Workflow
Claude Code 工作流
Guidelines for effective AI-assisted development with Claude Code.
使用Claude Code进行高效AI辅助开发的指南。
Task Value Matrix
任务价值矩阵
| Value | Task Type | Example |
|---|---|---|
| High | Boilerplate generation | CRUD endpoints, test scaffolding |
| High | Refactoring | Extract function, rename across files |
| High | Documentation | Docstrings, README updates |
| Medium | Bug investigation | Error analysis, log interpretation |
| Medium | Code review | Pattern suggestions, security review |
| Low | Novel architecture | Requires deep domain knowledge |
| Low | Ambiguous requirements | Needs human clarification |
| 价值 | 任务类型 | 示例 |
|---|---|---|
| 高 | 样板代码生成 | CRUD接口、测试脚手架 |
| 高 | 代码重构 | 提取函数、跨文件重命名 |
| 高 | 文档编写 | 文档字符串、README更新 |
| 中 | 错误排查 | 错误分析、日志解读 |
| 中 | 代码评审 | 模式建议、安全评审 |
| 低 | 新型架构设计 | 需要深厚领域知识 |
| 低 | 模糊需求处理 | 需要人工澄清 |
Workflow Patterns
工作流模式
Explore-Plan-Code-Commit (EPCC)
Explore-Plan-Code-Commit (EPCC)
The RECOMMENDED workflow for most development tasks:
-
Explore: Use Glob, Grep, Read to understand existing code
- MUST understand context before making changes
- SHOULD identify related files and dependencies
- MAY use subagents for parallel exploration
-
Plan: Outline changes before implementation
- SHOULD create TodoWrite items for multi-step tasks
- MUST validate plan covers edge cases
-
Code: Implement changes incrementally
- MUST run tests after each significant change
- SHOULD use Edit over Write for existing files
- SHALL NOT introduce breaking changes without tests
-
Commit: Create logical, atomic commits
- MUST follow semantic commit conventions
- SHALL NOT commit secrets or credentials
适用于大多数开发任务的推荐工作流:
-
探索(Explore):使用Glob、Grep、Read工具理解现有代码
- 必须在修改前理解上下文
- 应该识别相关文件和依赖
- 可以使用子代理进行并行探索
-
规划(Plan):在实现前概述修改内容
- 应该为多步骤任务创建TodoWrite项
- 必须验证计划覆盖边缘情况
-
编码(Code):增量式实现修改
- 必须在每次重要修改后运行测试
- 应该对现有文件使用Edit而非Write工具
- 不得在未测试的情况下引入破坏性变更
-
提交(Commit):创建逻辑化、原子化的提交
- 必须遵循语义化提交规范
- 不得提交密钥或凭证
Test-Driven Development with AI
结合AI的测试驱动开发
1. Write failing test → 2. Implement minimum to pass → 3. Refactor → 4. Repeat- MUST run tests between each step
- SHOULD use targeted test execution during development
1. 编写失败的测试 → 2. 实现最小代码使测试通过 → 3. 重构 → 4. 重复- 必须在每个步骤之间运行测试
- 应该在开发过程中使用针对性的测试执行
Spike-Then-Implement
原型验证后实现(Spike-Then-Implement)
For uncertain implementations: Create throwaway spike, validate, delete, implement properly with tests.
对于不确定的实现:创建一次性原型,验证可行性后删除,再结合测试正式实现。
Context Management
上下文管理
Efficient Prompting
高效提示词编写
MUST: Provide specific file paths, include error messages verbatim, state expected vs actual behavior
SHOULD: Reference previous context, specify output format, include constraints upfront
SHOULD NOT: Repeat information in context, include unnecessary background, ask multiple unrelated questions
必须:提供具体文件路径、逐字包含错误信息、说明预期与实际行为差异
应该:引用之前的上下文、指定输出格式、提前说明约束条件
不应该:在上下文中重复信息、包含无关背景、询问多个不相关问题
Conversation Structure
对话结构
[Initial Context] → [Specific Task] → [Iterative Refinement]- SHOULD front-load critical information
- MUST NOT bury important constraints at end of message
[初始上下文] → [具体任务] → [迭代优化]- 应该将关键信息前置
- 不得将重要约束隐藏在消息末尾
Context Window Optimization
上下文窗口优化
- SHOULD use subagents for isolated subtasks
- MUST NOT paste entire files when snippets suffice
- 应该使用子代理处理孤立子任务
- 不得在代码片段足够时粘贴整个文件
Subagent vs Direct Tool Usage
子代理 vs 直接工具使用
Use Subagents (Task tool) When:
应使用子代理(Task工具)的场景:
- Parallel independent operations (multiple searches, test runs)
- Isolated subtasks not needing main conversation context
- Complex multi-step work (refactoring across many files)
- Risk isolation (exploratory changes that might fail)
- 并行独立操作(多文件搜索、多次测试运行)
- 不需要主对话上下文的孤立子任务
- 复杂多步骤工作(跨多文件重构)
- 风险隔离(可能失败的探索性修改)
Use Direct Tools When:
应直接使用工具的场景:
- Sequential dependencies (each step depends on previous)
- Context continuity needed (building on recent conversation)
- Simple operations (single file read/edit)
- Immediate feedback required (interactive debugging)
| Scenario | Recommendation |
|---|---|
| Search 5+ files for pattern | Subagent |
| Edit single file | Direct |
| Run tests + fix failures | Subagent |
| Explore unfamiliar codebase | Subagent |
| Implement planned changes | Direct |
- 有顺序依赖的任务(每一步依赖前一步结果)
- 需要上下文连续性的任务(基于近期对话内容开展工作)
- 简单操作(单文件读取/编辑)
- 需要即时反馈的任务(交互式调试)
| 场景 | 推荐方案 |
|---|---|
| 搜索5个以上文件的特定模式 | 子代理 |
| 编辑单个文件 | 直接工具 |
| 运行测试并修复失败用例 | 子代理 |
| 探索不熟悉的代码库 | 子代理 |
| 实现已规划的修改 | 直接工具 |
Model Selection
模型选择
Opus (Complex Reasoning)
Opus(复杂推理)
SHOULD use for: Architecture decisions, complex debugging, multi-file refactoring, novel problem solving, security-sensitive code review
应该用于:架构决策、复杂调试、多文件重构、新型问题解决、安全敏感代码评审
Sonnet (Standard Tasks)
Sonnet(标准任务)
RECOMMENDED for: Routine code changes, test writing, documentation, code review, bug fixes with clear scope
推荐用于:日常代码修改、测试编写、文档编写、代码评审、范围明确的bug修复
Haiku (Quick Operations)
Haiku(快速操作)
MAY use for: Simple queries, syntax checking, format conversions, quick lookups, commit message generation
IF deep reasoning OR high-stakes: USE Opus
ELSE IF routine development: USE Sonnet
ELSE IF simple/quick: USE Haiku可以用于:简单查询、语法检查、格式转换、快速查找、提交信息生成
IF 深度推理 OR 高风险场景: USE Opus
ELSE IF 常规开发任务: USE Sonnet
ELSE IF 简单/快速操作: USE HaikuQuality Assurance
质量保障
Automated Validation
自动化验证
MUST: Test execution after changes, linting/formatting, type checking, security scanning
SHOULD: Coverage thresholds, performance benchmarks, integration tests
必须:修改后执行测试、代码检查/格式化、类型检查、安全扫描
应该:覆盖率阈值、性能基准测试、集成测试
Human Review Checkpoints
人工评审检查点
REQUIRED: Security-sensitive changes, production deployments, architecture modifications, public API changes
RECOMMENDED: Complex business logic, performance-critical code, external integrations
必需:安全敏感修改、生产环境部署、架构调整、公开API变更
推荐:复杂业务逻辑、性能关键代码、外部集成
Prompt Engineering for Code Tasks
代码任务的提示词工程
Specificity Patterns
具体化模式
Effective: "Refactor UserService in src/services/user.py to use dependency injection for database connection"
Ineffective: "Clean up the user code"
有效示例:"重构src/services/user.py中的UserService,使其使用依赖注入管理数据库连接"
无效示例:"整理用户代码"
Constraint Specification
约束条件说明
MUST specify: Language/framework versions, performance requirements, backward compatibility, error handling
必须指定:语言/框架版本、性能要求、向后兼容性、错误处理规则
Prompt Templates
提示词模板
Bug Fix:
File: [path] | Error: [exact message]
Expected: [behavior] | Actual: [behavior]
Relevant code: [snippet]Feature:
Goal: [one sentence]
Criteria: [list] | Location: [file] | Constraints: [limits]Bug修复:
文件: [路径] | 错误: [准确信息]
预期行为: [描述] | 实际行为: [描述]
相关代码: [片段]功能开发:
目标: [一句话描述]
标准: [列表] | 位置: [文件] | 约束: [限制条件]Session Context Management
会话上下文管理
Integration with Context Files
与上下文文件的集成
CURRENT.md - Active task state (SHOULD update when switching tasks, MUST reflect current focus)
STATUS.md - Project progress (SHOULD update at session end, MUST include blockers/next steps)
CURRENT.md - 活跃任务状态(切换任务时应该更新,必须反映当前工作重点)
STATUS.md - 项目进度(会话结束时应该更新,必须包含障碍/下一步计划)
Session Lifecycle
会话生命周期
[Start] → [Load CURRENT.md] → [Work + TodoWrite] → [End] → [Update STATUS.md][开始] → [加载CURRENT.md] → [工作 + TodoWrite] → [结束] → [更新STATUS.md]Context Preservation
上下文保留
- MUST save context before long breaks
- SHOULD use /snapshot for complex multi-session work
- MAY use /pickup to resume efficiently
- 必须在长时间中断前保存上下文
- 应该对复杂多会话工作使用/snapshot命令
- 可以使用/pickup命令高效恢复会话
Skill Activation Optimization
技能激活优化
Triggering Skills Efficiently
高效触发技能
- MUST use specific keywords in descriptions
- SHOULD include file patterns for automatic activation
- MAY use manual invocation for specialized skills
- 必须在描述中使用特定关键词
- 应该包含文件模式以实现自动激活
- 可以手动调用特定技能
Skill Composition
技能组合
Skills SHOULD be: Single-purpose, composable, self-contained
Skills MUST NOT: Conflict with others, duplicate core rules, exceed context budget
| Pattern | Trigger |
|---|---|
| File-based | |
| Directory-based | |
| Content-based | Keywords in conversation |
| Command-based | |
技能应该:单一用途、可组合、独立封装
技能不得:与其他技能冲突、重复核心规则、超出上下文预算
| 模式 | 触发方式 |
|---|---|
| 基于文件 | |
| 基于目录 | |
| 基于内容 | 对话中的关键词 |
| 基于命令 | |
Anti-Patterns to Avoid
需避免的反模式
Conversation Anti-Patterns
对话反模式
| Anti-Pattern | Better Approach |
|---|---|
| Context dumping | Provide focused, relevant context |
| Vague requests | Specific, measurable goals |
| Premature optimization | MVP first, optimize with data |
| Ignoring errors | Address errors immediately |
| 反模式 | 更佳方案 |
|---|---|
| 上下文冗余 | 提供聚焦、相关的上下文 |
| 模糊请求 | 明确、可衡量的目标 |
| 过早优化 | 先实现MVP,基于数据优化 |
| 忽略错误 | 立即处理错误 |
Tool Usage Anti-Patterns
工具使用反模式
| Anti-Pattern | Better Approach |
|---|---|
| Bash for file ops | Use Read/Edit/Write tools |
| Write over Edit | Prefer Edit for existing files |
| Single-threaded search | Parallel subagent searches |
| Skipping Read | Always Read before Edit |
| 反模式 | 更佳方案 |
|---|---|
| 用Bash处理文件操作 | 使用Read/Edit/Write工具 |
| 用Write替代Edit | 对现有文件优先使用Edit |
| 单线程搜索 | 使用子代理并行搜索 |
| 跳过Read操作 | 编辑前务必先Read |
Workflow Anti-Patterns
工作流反模式
| Anti-Pattern | Better Approach |
|---|---|
| Coding without tests | TDD or test-after minimum |
| Giant commits | Atomic, logical commits |
| Ignoring TodoWrite | Update status in real-time |
| 反模式 | 更佳方案 |
|---|---|
| 无测试编码 | 采用TDD或先实现最小功能再补测试 |
| 巨型提交 | 原子化、逻辑化的提交 |
| 忽略TodoWrite | 实时更新状态 |
Prompting Anti-Patterns
提示词反模式
| Anti-Pattern | Better Approach |
|---|---|
| "Make it better" | Define specific improvements |
| Assuming knowledge | Provide relevant background |
| Ignoring constraints | State constraints upfront |
| 反模式 | 更佳方案 |
|---|---|
| “让它更好” | 定义具体的改进点 |
| 假设模型具备知识 | 提供相关背景信息 |
| 忽略约束条件 | 提前说明约束 |
Quick Reference
快速参考
Effective Session
高效会话流程
- Start with clear goal
- Load context (CURRENT.md)
- Use EPCC workflow
- Update TodoWrite in real-time
- Run tests frequently
- Save context before ending
- 以明确目标开始
- 加载上下文(CURRENT.md)
- 使用EPCC工作流
- 实时更新TodoWrite
- 频繁运行测试
- 结束前保存上下文
Model Selection
模型选择
- Opus: Architecture, security, complex bugs
- Sonnet: Daily development, tests, docs
- Haiku: Quick queries, formatting
- Opus:架构设计、安全、复杂bug
- Sonnet:日常开发、测试、文档
- Haiku:快速查询、格式化
Tool Selection
工具选择
- Read: View file content
- Edit: Modify existing files
- Write: Create new files (rare)
- Glob: Find files by pattern
- Grep: Search file contents
- Task: Parallel/isolated work
- Bash: System operations only
- Read:查看文件内容
- Edit:修改现有文件
- Write:创建新文件(少用)
- Glob:按模式查找文件
- Grep:搜索文件内容
- Task:并行/孤立任务
- Bash:仅用于系统操作