A comprehensive guide covering setup, workflows, optimization, and troubleshooting for dotnet-agent-kit.
- .NET 10 SDK
- Claude Code CLI (
npm install -g @anthropic-ai/claude-codeor equivalent) - Docker (for Testcontainers in integration tests)
- Node.js (for MCP servers that use
npx)
- Install the Roslyn MCP server:
dotnet tool install -g CWM.RoslynNavigator- Add dotnet-agent-kit as a Claude Code plugin (inside a Claude Code session):
/plugin marketplace add codewithmukesh/dotnet-agent-kit
/plugin install dotnet-agent-kit
For local development/testing, load directly from disk instead: claude --plugin-dir /path/to/dotnet-agent-kit
- Configure MCP servers:
Copy or merge
mcp-configs/mcp-servers.jsoninto your project's.mcp.json:
cp /path/to/dotnet-agent-kit/mcp-configs/mcp-servers.json .mcp.jsonUpdate ${workspaceFolder} to your project root path.
- Drop in a template CLAUDE.md (optional):
Choose a template from
templates/that matches your architecture and copy itsCLAUDE.mdinto your project root.
Start Claude Code in your project directory. The plugin loads automatically. Try these commands to explore:
/verify health # Assess project health
"show instincts" # See what patterns have been learned
/spec add user export # Agree the requirements and plan before building
The system will detect your architecture, load appropriate skills, and route queries to the right skill or agent.
Context window budget is finite. These strategies maximize what fits.
Always use Roslyn MCP tools before reading source files:
| Instead Of | Use |
|---|---|
| Reading a 500-line file to find one method | find_symbol (returns file + line number) |
| Grepping for all usages of a type | find_references (structured results) |
| Reading multiple files to trace inheritance | get_type_hierarchy (complete chain) |
Running dotnet build and parsing output |
get_diagnostics (structured errors/warnings) |
| Manually inspecting all files for dead code | find_dead_code (zero-reference analysis) |
This approach typically reduces token consumption by 60-80% compared to file-reading approaches.
Skills are loaded on-demand, not all at once. Each agent has a defined skill map (see AGENTS.md), and the routing table sends everything else to a skill:
- Small queries (single fix or pattern): 1-2 skills loaded
- Medium queries (feature implementation): 3-4 skills loaded
- Large queries (architecture review): All relevant skills for the domain
docs/claude-code-workflow.md ("Treat context as a budget") provides advanced strategies for managing token budget during long sessions.
Use subagents to keep the main context window clean:
- Research tasks: Spawn a subagent to explore a codebase area while you work on another
- Parallel analysis: Multiple subagents can investigate different aspects simultaneously
- One task per subagent: Focused subagents produce better results than multi-task ones
- Model selection matters: Use Sonnet for routine subagent work, Opus for complex analysis
dotnet-agent-kit supports several autonomous feedback loops that run without user intervention.
- Runs
dotnet build - Parses compiler errors and categorizes them (missing reference, type mismatch, syntax, etc.)
- Applies known fix patterns for each error category
- Rebuilds and checks if errors decreased
- Repeats until the build is green or the iteration limit (default: 10) is reached
- Reports what was fixed and what remains
The build-error-resolver agent handles this with contextual skill loading -- it pulls in ef-core for DbContext errors, dependency-injection for DI container errors, and so on.
Follows strict red-green-refactor:
- Red: Write a failing test that defines the desired behavior
- Green: Write the minimum code to make the test pass
- Refactor: Clean up while keeping tests green
- Uses
WebApplicationFactory+ Testcontainers for integration tests - Verifies each step before proceeding
- Runs
dotnet formatfor style consistency - Uses
find_dead_codeto identify unused symbols - Runs
detect_antipatternsfor code smell detection - Applies
get_diagnosticsfor analyzer warnings - Makes structural improvements (extract method, simplify logic)
- Verifies build + tests after each change
The /verify command runs a comprehensive 7-phase pipeline. Each phase produces PASS or FAIL with actionable output. The pipeline short-circuits on critical failures.
Runs dotnet build across all projects. Must pass before proceeding.
Checks get_diagnostics for compiler warnings and analyzer violations. Reports severity counts and specific issues.
Uses detect_antipatterns to scan for .NET-specific code smells: async void, sync-over-async, new HttpClient(), DateTime.Now, broad catch, logging string interpolation, missing CancellationToken, EF queries without AsNoTracking.
Runs dotnet test with detailed output. Reports pass/fail counts and failing test details.
Scans for hardcoded secrets, vulnerable NuGet packages, missing auth attributes, and CORS misconfigurations.
Runs dotnet format --verify-no-changes to ensure consistent code style.
Reviews the diff against the base branch for logical issues, missing tests, and architecture violations.
The /verify health command produces letter grades (A through F) across multiple dimensions:
| Dimension | What It Measures | Tools Used |
|---|---|---|
| Code Quality | Antipatterns, analyzer warnings, formatting | detect_antipatterns, get_diagnostics |
| Architecture | Dependency direction, circular deps, module boundaries | get_project_graph, detect_circular_dependencies |
| Test Coverage | Types with corresponding test classes | get_test_coverage_map |
| Dead Code | Unused types, methods, properties | find_dead_code |
| Security | Secrets, auth, OWASP compliance | Manual scan + antipattern detection |
- A: Excellent. Production-ready with confidence.
- B: Good. Minor issues that should be addressed but are not blocking.
- C: Acceptable. Notable gaps that need attention before scaling.
- D: Concerning. Significant issues that risk production stability.
- F: Critical. Fundamental problems that must be resolved immediately.
Each grade includes specific findings and recommended actions.
The instinct system learns project-specific patterns and conventions over time.
- Observation: As you work, the system observes patterns in your codebase (naming conventions, architecture choices, testing patterns).
- Correction capture: When you correct Claude, the
instinct-systemskill captures the pattern and writes it toMEMORY.md. - Confidence scoring: Each instinct has a confidence score (0-100) that increases with repeated observations and decreases when contradicted.
- Application: High-confidence instincts are applied automatically. Low-confidence instincts are suggested but not enforced.
"show instincts" # View all instincts with confidence scores
"export instincts" # Export for sharing across projects
"import instincts" # Import from another project
Instincts are stored in .claude/instincts.json and are project-specific. Exporting creates a portable format that another project can import and adapt.
When starting a new session, the system:
- Loads
CLAUDE.mdand anyMEMORY.mdfor project context - Checks for handoff notes in
.claude/handoff.mdfrom the previous session - Loads instincts from
.claude/instincts.json - Makes rules from
.claude/rules/available (always-apply)
Use /wrap-up checkpoint to save progress at any point:
- Creates a descriptive git commit with conventional commit prefix
- Writes a handoff note with completed work and next steps
- Useful before risky changes or when switching tasks
Use /wrap-up when done for the day:
- Summarizes completed work
- Lists pending tasks and open questions
- Captures learnings and new instincts
- Writes handoff to
.claude/handoff.mdfor the next session
Symptom: MCP tools return errors or are not available.
Fixes:
- Verify the tool is installed:
cwm-roslyn-navigator --version - Check that a
.slnor.slnxfile exists (the server discovers it via BFS up to 3 levels) - Verify
.mcp.jsonhas the correct server configuration - Check that
${workspaceFolder}is replaced with the actual path - The server needs time to load on first use -- it returns "loading" status during initialization
Symptom: /build-fix hits the iteration limit without a green build.
Fixes:
- Check if errors are decreasing per iteration -- if not, the fixes may be introducing new errors
- Look for circular dependency issues with
detect_circular_dependencies - Check for missing NuGet packages (
dotnet restoremay be needed) - Some errors require manual intervention (architecture-level issues, missing project references)
Symptom: Format or antipattern hooks do not trigger.
Fixes:
- Verify
hooks/hooks.jsonis present and well-formed - Check that the plugin is loaded (
claude plugins list) - Ensure hook scripts are executable (
chmod +x hooks/*.sh) - Review hook matcher patterns --
Edit|Writematches those tool names
Symptom: Context window fills up quickly, responses get truncated.
Fixes:
- Use MCP tools instead of reading files (see Token Optimization above)
- Load fewer skills -- only what the current task needs
- Use subagents for research tasks to keep main context clean
- Read
docs/claude-code-workflow.md("Treat context as a budget") for advanced strategies - Consider splitting large tasks into smaller, focused sessions
Symptom: Integration tests fail with Docker-related errors.
Fixes:
- Verify Docker is running:
docker info - Check Docker has enough resources allocated (memory, disk)
- Ensure the Testcontainers NuGet package version matches your test framework
- On CI, use Docker-in-Docker or a dedicated Docker host
- Check for port conflicts if tests run in parallel
Symptom: Previously learned patterns are not being followed.
Fixes:
- Check instinct confidence by asking "show instincts" -- low-confidence instincts are suggestions, not enforced
- Verify
.claude/instincts.jsonexists and is not corrupted - Instincts are project-specific -- they do not transfer automatically between projects (use the instinct-system export and import modes)
Skills follow the Agent Skills open standard. To create a new skill:
mkdir -p skills/my-skillEvery skill needs frontmatter and four required sections:
---
name: my-skill
description: >
What this skill does and when Claude should load it.
Include trigger keywords and specific scenarios.
---
# My Skill
## Core Principles
1. **First principle** -- Rationale for why this matters.
2. **Second principle** -- Another opinionated default with explanation.
3. **Third principle** -- Keep to 3-5 principles.
## Patterns
### Pattern Name
[Working C# code example]
Brief explanation of why this is the recommended approach.
## Anti-patterns
### Anti-pattern Name
```csharp
// BAD
[code to avoid]
// GOOD
[correct approach]Explanation of why the bad pattern is harmful.
| Scenario | Recommendation |
|---|---|
| When X | Do Y |
| When A | Do B |
### 3. Quality Checklist
- [ ] Maximum 400 lines -- every line earns its place
- [ ] Every recommendation has a "why"
- [ ] Code examples use modern C# 14 (primary constructors, collection expressions, records)
- [ ] BAD/GOOD comparisons in anti-patterns section
- [ ] Frontmatter has `name` (kebab-case, matches directory) and `description`
### 4. Register with Agents
Add the skill to relevant agent skill maps in the agent's `.md` file and update `AGENTS.md` if the skill introduces a new routing pattern.
### 5. Test the Skill
Load the skill in a Claude Code session and verify it activates on the trigger keywords defined in the description. Test that code examples compile conceptually and that anti-pattern comparisons are clear.