Skip to content

Latest commit

 

History

History
188 lines (133 loc) · 7.63 KB

claude-code-workflow.md

File metadata and controls

188 lines (133 loc) · 7.63 KB

Claude Code Workflow for .NET

Practical habits for working with Claude Code on a .NET solution. This is a guide for people, not a skill: the kit does not load it into context. Related skills: plan, verify, instinct-system.

1. Run parallel sessions with git worktrees

Each worktree gets its own checkout and its own Claude session, so sessions never overwrite each other's files.

git worktree add ../my-project-feature origin/main
git worktree add ../my-project-bugfix origin/main
cd ../my-project-feature && claude
Worktree Task
feature Build a new endpoint and handler
bugfix Fix a failing CI test
tests Add integration tests for an existing feature
analysis Read-only research with the Roslyn MCP, logs, architecture review

Tips:

  • Each worktree restores and builds on its own. Expect a first-build cost per worktree.
  • Two sessions must not edit the same files. Split work by project or feature folder.
  • Name terminal tabs by task and turn on terminal notifications so you notice when a session needs input.
  • Remove finished worktrees: git worktree remove ../my-project-bugfix.

2. Plan first, then execute

For any task touching 3 or more files, or involving an architecture decision:

  1. Enter plan mode (Shift+Tab twice, or the plan skill).
  2. Give full context: the goal, the constraints, the architecture in use.
  3. Challenge the plan: edge cases, migration impact, service lifetimes.
  4. Switch to normal mode and let Claude execute.

A second session makes a good reviewer. Paste the plan and ask: "Review this as a staff .NET engineer. What is missing? What could go wrong?"

If implementation drifts from the plan, stop. Go back to plan mode, understand what changed, re-plan, then continue. Pushing through a broken plan costs more than re-planning.

Skip plan mode for simple, obvious fixes. A one-line bug fix needs a test run, not a plan.

3. Give Claude a way to verify its work

The biggest quality lever. Tell Claude to run these before it says "done":

dotnet build
dotnet test
dotnet format --verify-no-changes

With the Roslyn MCP, get_diagnostics is a faster check after each edit than a full build. The verify skill runs the full pipeline (build, analyzers, antipatterns, tests, security, format, diff review) with PASS/FAIL per phase.

Useful prompts:

Prove this works. Run the tests and show me the output.
Then diff the API response between main and this branch.
Generate the migration, then show me the raw SQL it produces.
I want to review it before applying.
Would this pass a staff .NET engineer's review? Check for N+1 queries,
missing CancellationToken, exposed entities, missing validation, wrong lifetimes.

After a mediocre fix: "Knowing everything you know now, scrap this and implement the elegant solution."

4. Remove friction with hooks and permissions

Format on write

Catches formatting problems at write time, so CI never fails on style. .claude/settings.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "dotnet format --include \"$CLAUDE_FILE_PATH\" --no-restore 2>/dev/null || true"
          }
        ]
      }
    ]
  }
}

|| true keeps a failed format (for example on a non-C# file) from blocking Claude. The kit already ships format, bash-guard and restore hooks in hooks/; add your own only for project-specific needs.

Pre-allow safe dotnet commands

{
  "permissions": {
    "allow": [
      "Bash(dotnet build *)",
      "Bash(dotnet test *)",
      "Bash(dotnet run *)",
      "Bash(dotnet format *)",
      "Bash(dotnet restore *)"
    ]
  }
}

Check the file into git so the team shares it. Keep dotnet ef database update, dotnet nuget push and anything that touches a shared environment on the prompt list.

5. Use the specialist agents

The kit ships specialist agents (see agents/). Route to them before writing your own:

Run the code-reviewer agent on my changes before I open 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, add a project agent in .claude/agents/: a markdown file with a role, a numbered job list, and a required report format. Keep one concern per agent so its output stays reviewable.

6. Treat context as a budget

A typical .cs file costs 500 to 2000 tokens. Fifty file reads can use a large share of the window, and quality drops as it fills.

MCP first

A Roslyn MCP query costs roughly 30 to 150 tokens. A file read costs 500 or more. To understand OrderService, a chain of find_symbol, get_public_api, find_references and get_type_hierarchy costs a few hundred tokens in total. Reading the same four files costs several thousand. Read a file in full only when you are about to edit it.

What to read

Priority What How
1 Files you will modify Read fully, edits need exact content
2 Contracts you must satisfy Read the interface, skip implementations
3 Reference patterns get_public_api first, read only if it is not enough
4 General context Subagent summary, never in the main context

Never read whole directories (use get_project_graph), test files for context (use get_test_coverage_map), generated files or migrations.

When to use a subagent

Offload when the journey is verbose but the answer is short: exploring more than 3 unfamiliar files, researching docs, running tests with long output. Stay in the main context when you are editing a file you already read, doing 1 or 2 quick lookups, or building on the live conversation.

Ask for compressed answers: "Trace the auth flow from login to token validation. Return numbered steps with file:line references." You get a few hundred tokens instead of thousands of raw source.

Large solutions (50+ projects)

get_project_graph to see the shape, narrow to 2 or 3 projects, find_symbol for the key types, get_public_api for interfaces, then read only the files you will change.

Warning signs and recovery

Signs: 10+ files read, 50+ exchanges, Claude forgets earlier decisions or re-reads files it has already seen.

Recovery: write a 5 to 10 line summary of what is known, push remaining exploration to subagents, use MCP-only lookups, and start a fresh session if quality is still poor.

Load skills on demand

Do not preload skills "just in case". Load modern-csharp when you start writing C#. Pull ef-core, testing and the rest when the topic comes up.

To measure what the MCP server actually saves, see "Measuring token savings" in mcp/CWM.RoslynNavigator/README.md.

7. Compound your knowledge

After any correction, have Claude write a generalized rule into CLAUDE.md or MEMORY.md so the mistake does not return. The instinct-system skill describes capture, generalization and periodic audits.

Quick reference

Situation Do this
Task touches 3+ files Plan mode first
Simple bug fix Fix it, verify with dotnet test
Build, test and review at once Three worktrees
CI fails on formatting Add the format hook
Tired of permission prompts Pre-allow the safe dotnet commands
Claude made a mistake "Add a rule so you do not make that mistake again"
Code feels hacky Ask for the elegant solution, with the full context
Need a type's API or location get_public_api or find_symbol, not a file read
Context feels heavy Summarize, then subagents and MCP only
New topic mid-session Load that skill then, not earlier