workflow-mastery
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWorkflow Mastery for .NET
.NET工作流精通指南
Core Principles
核心原则
- Parallel over sequential — Run 3-5 Claude sessions simultaneously using git worktrees. Build a feature in one, fix a bug in another, run tests in a third. The single biggest productivity unlock.
- Plan then execute — For any non-trivial task, start in plan mode, iterate until the plan is bulletproof, then switch to auto-accept. A good plan means Claude 1-shots the implementation.
- Verification closes the loop — Give Claude a way to prove its work: ,
dotnet build,dotnet testvia MCP. This single practice 2-3x the quality of the output.get_diagnostics - Context is a budget, not a dumping ground — The context window fills fast: a typical .cs file is 500-2000 tokens, and 50 file reads can burn a large share of the budget. Spend tokens like sprint capacity — deliberately.
- Automate the repetitive — If you do it more than once a day, make it a hook, a slash command, or a subagent. Pre-allow safe permissions. Eliminate friction.
- Compound your knowledge — Every correction becomes a rule in (see
MEMORY.mdskill). Every PR review adds a learning. Over time, Claude's mistake rate drops because your project's knowledge base grows.instinct-system
- 优先并行而非串行 — 使用git worktrees同时运行3-5个Claude会话。在一个会话中开发功能,另一个中修复bug,第三个中运行测试。这是提升生产力最显著的方法。
- 先规划再执行 — 对于任何非琐碎任务,先进入计划模式,迭代至计划无懈可击,再切换到自动接受模式。完善的计划意味着Claude能一次性完成实现。
- 验证闭环 — 给Claude提供验证工作成果的方式:、
dotnet build、通过MCP调用dotnet test。这一实践能将输出质量提升2-3倍。get_diagnostics - 上下文是预算,而非垃圾场 — 上下文窗口会快速填满:一个典型的.cs文件占500-2000令牌,读取50个文件会消耗大量预算。像管理迭代容量一样谨慎使用令牌。
- 自动化重复任务 — 如果某项任务每天执行超过一次,将其设为钩子、斜杠命令或子代理。预先设置安全权限,消除操作摩擦。
- 积累知识复利 — 每次修正都要写入(参考
MEMORY.md技能)。每次PR评审都要添加学习内容。随着时间推移,Claude的错误率会下降,因为项目的知识库不断增长。instinct-system
Patterns
模式
Parallel Sessions with Git Worktrees
基于Git Worktrees的并行会话
The biggest productivity multiplier. Each worktree gets its own Claude session, its own files, zero conflicts.
bash
undefined这是提升生产力的最大乘数。每个工作树都有独立的Claude会话和文件,零冲突。
bash
undefinedCreate worktrees for parallel work
创建用于并行工作的工作树
git worktree add ../my-project-feature origin/main
git worktree add ../my-project-bugfix origin/main
git worktree add ../my-project-tests origin/main
git worktree add ../my-project-feature origin/main
git worktree add ../my-project-bugfix origin/main
git worktree add ../my-project-tests origin/main
Start Claude in each (separate terminal tabs)
在每个工作树中启动Claude(在独立终端标签页中)
cd ../my-project-feature && claude
cd ../my-project-bugfix && claude
cd ../my-project-tests && claude
**Practical .NET workflow:**
| Worktree | Task | Claude Session |
|----------|------|---------------|
| `feature` | Build new endpoint + handler | Main development |
| `bugfix` | Fix the failing CI test | Autonomous bug fix |
| `tests` | Write integration tests for existing feature | Test generation |
| `analysis` | Query the Roslyn MCP, read logs, review architecture | Read-only research |
**Tips:**
- Name your terminal tabs by task so you never lose track
- Use shell aliases (`alias zf='cd ../my-project-feature'`) for one-keystroke switching
- Enable terminal notifications so you know when a session needs inputcd ../my-project-feature && claude
cd ../my-project-bugfix && claude
cd ../my-project-tests && claude
**实用.NET工作流:**
| 工作树 | 任务 | Claude会话 |
|----------|------|---------------|
| `feature` | 构建新端点及处理器 | 主开发会话 |
| `bugfix` | 修复失败的CI测试 | 自主bug修复会话 |
| `tests` | 为现有功能编写集成测试 | 测试生成会话 |
| `analysis` | 查询Roslyn MCP、读取日志、评审架构 | 只读研究会话 |
**技巧:**
- 按任务命名终端标签页,避免混淆
- 使用Shell别名(如`alias zf='cd ../my-project-feature'`)一键切换
- 启用终端通知,及时知晓会话需要输入Auto-Format Hook for .NET
.NET自动格式化钩子
Catch formatting issues on every file write — eliminates the "CI failed on formatting" loop.
json
// .claude/settings.json
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "dotnet format --include \"$CLAUDE_FILE_PATH\" --no-restore 2>/dev/null || true"
}
]
}
]
}
}Why : The hook should never block Claude's workflow. If formatting fails (e.g., on a non-C# file), silently continue.
|| true在每次文件写入时捕获格式问题——消除“CI因格式失败”的循环。
json
// .claude/settings.json
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "dotnet format --include \"$CLAUDE_FILE_PATH\" --no-restore 2>/dev/null || true"
}
]
}
]
}
}为什么加:钩子不应阻止Claude的工作流。如果格式化失败(如针对非C#文件),应静默继续。
|| truePre-Allow Safe .NET Permissions
预先设置安全.NET权限
Stop clicking "allow" for every command. Add these to :
dotnet.claude/settings.jsonjson
{
"permissions": {
"allow": [
"Bash(dotnet build *)",
"Bash(dotnet test *)",
"Bash(dotnet run *)",
"Bash(dotnet ef *)",
"Bash(dotnet format *)",
"Bash(dotnet restore *)",
"Bash(dotnet pack *)",
"Bash(dotnet tool *)"
]
}
}Check this into git so the whole team gets frictionless workflows.
无需为每个命令点击“允许”。将以下内容添加到:
dotnet.claude/settings.jsonjson
{
"permissions": {
"allow": [
"Bash(dotnet build *)",
"Bash(dotnet test *)",
"Bash(dotnet run *)",
"Bash(dotnet ef *)",
"Bash(dotnet format *)",
"Bash(dotnet restore *)",
"Bash(dotnet pack *)",
"Bash(dotnet tool *)"
]
}
}将其提交到git,让整个团队都能享受无摩擦的工作流。
Plan Mode Strategy
计划模式策略
For any task touching 3+ files or involving architecture decisions:
Step 1: Enter plan mode (Shift+Tab twice)
Step 2: Describe the task with full context
Step 3: Iterate on the plan — challenge assumptions, ask "what about edge cases?"
Step 4: Once the plan is solid, switch to normal mode
Step 5: Claude executes with auto-accept — often 1-shots the implementationAdvanced pattern: Have one Claude write the plan, then spin up a second Claude session to review it as a staff engineer:
"Review this plan as a staff .NET engineer. Challenge every assumption.
What could go wrong? What's missing? What would you do differently?"When things go sideways: The moment implementation deviates from the plan, STOP. Don't push through. Switch back to plan mode, understand what changed, re-plan, then resume.
对于涉及3个以上文件或架构决策的任务:
步骤1:进入计划模式(按两次Shift+Tab)
步骤2:描述任务及完整上下文
步骤3:迭代完善计划——挑战假设,询问“边缘情况怎么办?”
步骤4:计划确定后,切换到普通模式
步骤5:Claude以自动接受模式执行——通常能一次性完成实现进阶模式: 让一个Claude编写计划,再启动第二个Claude会话,以资深工程师身份评审:
“以资深.NET工程师身份评审此计划。挑战所有假设。
可能出现什么问题?遗漏了什么?你会怎么做?”出现问题时: 一旦实现偏离计划,立即停止。不要强行推进。切换回计划模式,理解变化原因,重新规划后再继续。
Verification Loop for .NET
.NET验证循环
For the full 7-phase verification pipeline (build, diagnostics, anti-patterns, tests, security, format, diff review) with structured PASS/FAIL reporting, see the verify skill.
Boris's #1 tip: "Give Claude a way to verify its work." The short version: always tell Claude to run , , , and before declaring done. The verify skill has the complete pipeline with short-circuit rules and report templates.
dotnet builddotnet testget_diagnosticsdotnet format --verify-no-changes完整的7阶段验证流水线(构建、诊断、反模式、测试、安全、格式、差异评审)及结构化PASS/FAIL报告,请参考verify技能。
Boris的头号技巧:“给Claude提供验证工作成果的方式。”简化版:始终要求Claude在完成前运行、、和。verify技能包含完整的流水线、短路规则和报告模板。
dotnet builddotnet testget_diagnosticsdotnet format --verify-no-changesCompounding Knowledge via Corrections
通过修正积累知识复利
For the full correction capture system — detection, generalization, categorized storage, and periodic audits — see the skill. The short version: after every correction, capture a generalized rule in so the same mistake never recurs.
instinct-systemMEMORY.md完整的修正捕获系统——检测、归纳、分类存储和定期审计,请参考****技能。简化版:每次修正后,在中记录通用规则,避免重复犯错。
instinct-systemMEMORY.mdPrompting Techniques for .NET
.NET提示技巧
Challenge Claude's work:
"Grill me on these changes. Would this pass a staff .NET engineer's code review?
Check for: N+1 queries, missing CancellationToken, exposed domain entities,
missing validation, incorrect service lifetimes."Demand proof:
"Prove this works. Run the tests, show me the output.
Then diff the API response between main and this branch."After a mediocre fix:
"Knowing everything you know now, scrap this and implement the elegant solution.
No hacks, no workarounds."For EF Core migrations:
"Generate the migration, then show me the raw SQL it produces.
I want to verify the migration before applying it."挑战Claude的工作:
“严格评审这些变更。这能通过资深.NET工程师的代码评审吗?
检查:N+1查询、缺失CancellationToken、暴露领域实体、
缺失验证、不正确的服务生命周期。”要求提供证明:
“证明此实现有效。运行测试并展示输出。
然后比较main分支和当前分支的API响应差异。”修复效果不佳时:
“基于当前掌握的所有信息,废弃此实现并提供优雅的解决方案。
禁止使用 hacks 和临时变通方案。”针对EF Core迁移:
“生成迁移脚本,然后展示其生成的原始SQL。
我要在应用前验证迁移内容。”Subagent Patterns for .NET
.NET子代理模式
The kit ships 10 specialist agents — route to them before writing your own:
, , , ,
, , ,
, , . Each carries
pre-loaded skills and domain context a generalist session lacks.
dotnet-architectcode-reviewerrefactor-cleanertest-engineersecurity-auditorbuild-error-resolveref-core-specialistapi-designerperformance-analystdevops-engineerUse them:
"Run the code-reviewer agent on my changes before I create the PR."
"Have refactor-cleaner simplify the files I just modified."
"Send the failing CI log to build-error-resolver."For workflows the kit does not cover, create project-specific subagents in
— a markdown file with a role, a numbered job list, and a
required report format (PASS with summary / FAIL with specifics). Keep one
concern per agent so its output stays reviewable.
.claude/agents/When to offload vs. stay in main context: see Context Discipline below — subagents are also your context isolation chambers, not just task runners.
工具包包含10个专业代理——先使用它们,再考虑自定义:
、、、、
、、、
、、。每个代理都预装了通用会话不具备的技能和领域上下文。
dotnet-architectcode-reviewerrefactor-cleanertest-engineersecurity-auditorbuild-error-resolveref-core-specialistapi-designerperformance-analystdevops-engineer使用方式:
“在我创建PR前,让code-reviewer代理评审我的变更。”
“让refactor-cleaner简化我刚修改的文件。”
“将失败的CI日志发送给build-error-resolver。”对于工具包未覆盖的工作流,在中创建项目特定子代理——一个包含角色、编号任务列表和必填报告格式(PASS带摘要/FAIL带详情)的Markdown文件。每个代理只负责一个关注点,确保输出易于评审。
.claude/agents/何时卸载到子代理 vs. 保留在主上下文: 请参考下文的上下文规范——子代理不仅是任务运行器,也是上下文隔离室。
Context Discipline
上下文规范
The rules in already mandate MCP-first navigation ( before file reads, over builds). This section is the strategy layer on top: how to budget, when to offload, and how to recover.
.claude/rules/agents.mdfind_symbolget_diagnostics.claude/rules/agents.mdfind_symbolget_diagnosticsToken Economics
令牌经济学
A Roslyn MCP query costs 30-150 tokens; a file read costs 500-2000+. To understand , four MCP calls ( → → → ) cost ~310 tokens; reading the four related files costs ~2900. Then read only the method you'll modify. Reserve full file reads for files you are about to edit.
OrderServicefind_symbolget_public_apifind_referencesget_type_hierarchy一次Roslyn MCP查询消耗30-150令牌;读取一个文件消耗500-2000+令牌。要了解,四次MCP调用( → → → )约消耗310令牌;读取四个相关文件约消耗2900令牌。仅读取你要修改的方法。仅在准备编辑文件时才完整读取。
OrderServicefind_symbolget_public_apifind_referencesget_type_hierarchySubagent Offloading Decision Matrix
子代理卸载决策矩阵
OFFLOAD TO A SUBAGENT WHEN:
- Exploring unfamiliar code (> 3 files to read)
- Research requiring docs or multiple files
- Verbose output (test runs, diagnostics, comparisons)
- Any task where the journey is verbose but the answer is concise
STAY IN MAIN CONTEXT WHEN:
- Modifying a file you've already read
- Quick lookups (1-2 MCP queries)
- Work that builds on the ongoing conversation with the userAsk subagents for compressed answers: "Trace the auth flow from login to token validation. Return numbered steps with file:line references." You get ~300 tokens of findings instead of 15k tokens of raw files.
卸载到子代理的场景:
- 探索不熟悉的代码(需读取3个以上文件)
- 需要文档或多个文件的研究任务
- 输出冗长的任务(测试运行、诊断、比较)
- 过程冗长但答案简洁的任务
保留在主上下文的场景:
- 修改已读取的文件
- 快速查询(1-2次MCP调用)
- 基于与用户持续对话的工作要求子代理提供压缩后的答案:“追踪从登录到令牌验证的认证流程。返回带文件:行号引用的编号步骤。”你会得到约300令牌的结果,而非15000令牌的原始文件内容。
File Reading Prioritization
文件读取优先级
PRIORITY 1 — Files you will modify: read fully (exact content needed for edits)
PRIORITY 2 — Contracts you must satisfy: read the interface, skip implementations
PRIORITY 3 — Reference patterns: get_public_api first, read only if insufficient
PRIORITY 4 — General context: subagent summarizes; never read in main context
NEVER READ: entire directories (get_project_graph), test files for context
(get_test_coverage_map), generated files/migrations, configs unless needed优先级1 — 要修改的文件:完整读取(编辑需要精确内容)
优先级2 — 必须满足的契约:读取接口,跳过实现
优先级3 — 参考模式:先调用get_public_api,不足时再读取
优先级4 — 通用上下文:由子代理总结;绝不在主上下文中读取
禁止读取:整个目录(用get_project_graph)、用于上下文的测试文件(用get_test_coverage_map)、生成文件/迁移、无需修改的配置Budget Planning and Recovery
预算规划与恢复
Before a complex task, sketch the spend: understand ~5k (MCP + subagent), plan ~2k, implement ~15k (read targets + write + iterate), verify ~3k — leaving the bulk of the window for conversation.
WARNING SIGNS: 10+ files read, 50+ exchanges, forgetting earlier details,
re-reading files you already saw
RECOVERY: summarize what you know in 5-10 lines → subagents for remaining
exploration → MCP-only lookups → suggest a fresh session if still degraded
LARGE CODEBASES (50+ projects): get_project_graph → narrow to 2-3 relevant
projects → find_symbol for key types → get_public_api for interfaces →
read ONLY files you'll modify → subagents for cross-cutting concerns复杂任务前,估算令牌消耗:约5k(MCP+子代理)用于探索,约2k用于规划,约15k(读取目标文件+写入+迭代)用于实现,约3k用于验证——为对话预留大部分窗口。
警告信号:读取10个以上文件、50次以上交互、遗忘之前的细节、重新读取已看过的文件
恢复方法:用5-10行总结已知内容 → 用子代理完成剩余探索 → 仅使用MCP查询 → 若仍无改善,建议启动新会话
大型代码库(50+项目):调用get_project_graph → 缩小到2-3个相关项目 → 用find_symbol定位关键类型 → 用get_public_api获取接口 → 仅读取要修改的文件 → 用子代理处理跨领域问题Lazy Skill Loading
延迟技能加载
Don't front-load skills "just in case" — 15 skills at ~300 tokens each is ~4500 tokens spent before any work starts. Load at session start if relevant; pull , , etc. the moment the topic actually arises.
modern-csharpef-coretesting不要提前加载所有技能“以防万一”——15个技能每个约300令牌,总计约4500令牌,还未开始工作就已消耗。若相关,在会话开始时加载;当实际涉及、等主题时再加载对应技能。
modern-csharpef-coretestingAnti-patterns
反模式
Don't Skip Plan Mode for Complex Tasks
复杂任务不要跳过计划模式
// BAD — dive straight into a multi-file refactor
"Refactor the Orders module to use DDD with aggregates and value objects"
*Claude modifies 15 files, misses half the invariants, tangles the migration*
// GOOD — plan first, execute after
"Enter plan mode. I want to refactor the Orders module to use DDD.
Let's plan which files change, what the aggregate boundary is,
how value objects map to EF Core, and what the migration strategy is."// 错误做法——直接开始多文件重构
“将Orders模块重构为使用DDD聚合和值对象”
*Claude修改15个文件,遗漏半数约束,搞乱迁移*
// 正确做法——先规划,再执行
“进入计划模式。我要将Orders模块重构为使用DDD。
我们来规划哪些文件需要修改、聚合边界是什么、
值对象如何映射到EF Core,以及迁移策略。”Don't Work in a Single Session When You Could Parallelize
能并行时不要单会话串行工作
// BAD — sequential work in one session
1. Build feature (20 min)
2. Write tests (15 min)
3. Fix formatting (5 min)
4. Update docs (10 min)
Total: 50 minutes
// GOOD — parallel worktrees
Worktree 1: Build feature (20 min)
Worktree 2: Write tests (15 min, started simultaneously)
Worktree 3: Update docs (10 min, started simultaneously)
Total: ~20 minutes (wall clock)// 错误做法——单会话串行工作
1. 开发功能 (20分钟)
2. 编写测试 (15分钟)
3. 修复格式问题 (5分钟)
4. 更新文档 (10分钟)
总计:50分钟
// 正确做法——并行工作树
工作树1:开发功能 (20分钟)
工作树2:编写测试 (15分钟,同时启动)
工作树3:更新文档 (10分钟,同时启动)
总计:约20分钟(时钟时间)Don't Accept the First Solution
不要接受第一个解决方案
// BAD — accept mediocre code
Claude: "Here's the implementation" *generic, works but not great*
You: "Looks good, ship it"
// GOOD — push for quality
Claude: "Here's the implementation"
You: "Would a staff .NET engineer approve this?
What about the service lifetime? Is this N+1 safe?
Is there a more elegant way using C# 14 features?"// 错误做法——接受平庸代码
Claude:“这是实现方案” *通用、可用但不够好*
你:“看起来不错,发布吧”
// 正确做法——追求高质量
Claude:“这是实现方案”
你:“资深.NET工程师会批准这个吗?
服务生命周期有问题吗?这能避免N+1查询吗?
有没有使用C# 14特性的更优雅方式?”Don't Load Everything Because the Window Is Large
不要因窗口大就加载所有内容
// BAD — "the context window is huge, let's load everything"
Read all 30 files in the Orders module, all 15 test files,
docker-compose.yml, every migration
*80k tokens consumed before writing a single line of code*
// GOOD — minimum viable context
MCP: get_project_graph (solution shape) + find_symbol (locate targets)
Read: the 2-3 files you'll actually modify
Subagent: summarize anything else
*~3k tokens consumed, the rest free for actual work*// 错误做法——“上下文窗口很大,加载所有内容”
读取Orders模块的30个文件、15个测试文件、
docker-compose.yml、所有迁移文件
*编写第一行代码前已消耗80k令牌*
// 正确做法——最小必要上下文
MCP:调用get_project_graph(解决方案结构)+ find_symbol(定位目标)
读取:实际要修改的2-3个文件
子代理:总结其他内容
*约消耗3k令牌,剩余空间用于实际工作*Decision Guide
决策指南
| Scenario | Recommendation |
|---|---|
| Task touches 3+ files | Plan mode first |
| Task is a simple bug fix | Just fix it, verify with |
| Need to build + test + review | 3 parallel worktrees |
| CI keeps failing on format | Add PostToolUse format hook |
| Tired of permission prompts | Pre-allow |
| Claude made a mistake | "Update CLAUDE.md so you don't make that mistake again" |
| Code feels hacky | "Knowing everything you know now, implement the elegant solution" |
| Want to verify architecture | Spin up a second session as staff reviewer |
| Repetitive PR workflow | Route to kit agents (code-reviewer, refactor-cleaner) or create a project subagent |
| Learning a new codebase | Use "Explanatory" output style via |
| Need a type's API or location | |
| Need to modify a file | Read it fully — exact content required |
| Exploring unfamiliar code | Spawn a subagent — keep main context clean |
| 10+ files read in a session | Pause — switch to MCP + subagents |
| Context feels heavy or sluggish | Summarize what you know, subagents going forward |
| Large codebase (50+ projects) | MCP-first, subagent-heavy, read only files you modify |
| New topic mid-session | Load the relevant skill on demand, not in advance |
| 场景 | 建议 |
|---|---|
| 任务涉及3个以上文件 | 先进入计划模式 |
| 任务是简单bug修复 | 直接修复,用 |
| 需要构建+测试+评审 | 使用3个并行工作树 |
| CI因格式问题持续失败 | 添加PostToolUse格式钩子 |
| 厌倦权限提示 | 预先允许 |
| Claude犯错 | “更新CLAUDE.md,避免再犯同样的错误” |
| 代码感觉粗糙 | “基于当前掌握的所有信息,实现优雅的解决方案” |
| 要验证架构 | 启动第二个会话作为资深评审 |
| PR工作流重复 | 路由到工具包代理(code-reviewer、refactor-cleaner)或创建项目子代理 |
| 学习新代码库 | 通过 |
| 需要类型的API或位置 | 使用 |
| 需要修改文件 | 完整读取——需要精确内容 |
| 探索不熟悉的代码 | 生成子代理——保持主上下文整洁 |
| 会话中读取10个以上文件 | 暂停——切换到MCP+子代理 |
| 上下文感觉沉重或缓慢 | 总结已知内容,后续使用子代理 |
| 大型代码库(50+项目) | MCP优先、依赖子代理、仅读取要修改的文件 |
| 会话中途出现新主题 | 按需加载相关技能,不要提前加载 |