Claude Code for .NET Developers: A Practical Agentic Workflow
Claude Code is an agent that reads a repository, plans changes, edits files and runs dotnet build and dotnet test until the code passes. Mehdi Mohseni's guide shows how a .NET team can set it up with a CLAUDE.md, a PostToolUse build hook, plan mode and permission guardrails. It is worth reading if you want the agent to check its own work.
Key points
- Keep CLAUDE.md under 200 lines; put shared conventions in AGENTS.md and import it with @AGENTS.md.
- Add a PostToolUse hook on Edit|Write that runs dotnet build and exits with code 2 to send compiler errors back to Claude.
- Start non-trivial changes in plan mode (--permission-mode plan or /plan) and review the steps before any edit.
- Use --worktree for large multi-file changes so the main working tree stays untouched until review.
- Enforce hard rules with deny permission rules or PreToolUse hooks, because PostToolUse runs after the action.
- Add Read deny rules for .env and appsettings.*.json so secrets stay out of Claude's file reads.
Claude Code, Anthropic's terminal agent, goes beyond suggestions: it reads a repository, plans a change, edits files, runs dotnet build and dotnet test, and fixes what fails. Mehdi Mohseni's article, Part 1 of an agentic engineering series for .NET teams, shows how to set up that loop. It covers a CLAUDE.md that imports a shared AGENTS.md, a PostToolUse hook that builds after each edit, and a plan-first workflow for larger changes.
The advice centres on guardrails. Plan mode lets you review steps before any file changes, and git worktrees isolate big renames from your main working tree. PostToolUse hooks run after an action and cannot block it, so hard rules belong in deny permission rules or PreToolUse hooks. The piece also covers recent permission-mode changes and how to keep secrets such as .env files out of the agent's reads. The original has the full scripts and settings.
Real-world use
- A Clean Architecture ASP.NET Core service where the agent must follow layer rules and build after every edit.
- Adding an endpoint with validation and integration tests to an existing minimal API using the WebApplicationFactory fixture.
- A solution-wide rename of a domain entity, isolated in a git worktree until it is reviewed.
Why it matters
A CLAUDE.md, a build hook and plan-first habits turn Claude Code from a code writer into a tool that checks its own output, so compiler and test failures are caught inside the session.