OmniscioGuidesCLAUDE.md examplesC# and .NET
CLAUDE.md for a C# and .NET project
A .NET solution looks regular: a strict compiler, uniform tooling, and an agent that can still put a query in an endpoint or silence a nullable warning with one character. The file below writes down the few decisions the compiler does not make for you.
Every block has its reason underneath, and the examples hub has the same page for eight other stacks.
- The file, ready to copy.
- Why each block is there.
- What was left out, and why.
- Adapting it to a single project, Blazor, or a different database.
Checked against Anthropic's Claude Code documentation and Microsoft's .NET documentation on November 25, 2026. By the Omniscio team. Updated .
The file
This one describes a web API that handles customer returns, with EF Core for the database. Save it as ./CLAUDE.md or ./.claude/CLAUDE.md beside the solution file, where every project in the solution inherits it.
# returns-api Web API for customer returns, C# on the modern .NET SDK. One solution: three source projects and one test project. Nullable reference types on. ## Commands dotnet build dotnet run --project src/Api dotnet test dotnet test --filter FullyQualifiedName~RefundTests dotnet format --verify-no-changes dotnet tool install --global dotnet-ef dotnet ef migrations add AddReturnReason --project src/Infrastructure --startup-project src/Api dotnet ef database update --project src/Infrastructure --startup-project src/Api ## Layout - src/Api/ endpoints and request models only - src/Domain/ entities and rules; no EF Core, no HTTP - src/Infrastructure/ DbContext, configurations, Migrations/ - tests/Api.Tests/ the Api tests; other projects get a suite as they earn one - Directory.Build.props shared settings, nullable among them ## Rules - Nullable reference types stay on. Reach for ! only where you can say why the value cannot be null; otherwise fix the code. - An async method returns Task or Task<T>, ends in Async, and takes a CancellationToken last when the work can be cancelled. - Domain code throws; an endpoint translates. Exceptions are never control flow for an ordinary outcome such as "not found". - A query lives in src/Infrastructure/. An IQueryable never crosses into Api/. - A request or response body is a record; a mutable class is not a DTO. - dotnet run is for development. Production starts the published output. - bin/ and obj/ are build output and never committed. ## Testing - Each project with rules worth pinning gets a test project, using the framework it already has; never add a second framework. - Every run prints how many tests it discovered and ran. Read that number before believing a pass. - A test that touches the database uses the production provider, not an in-memory stand-in. - A bug fix starts with a test that fails before the fix. ## Traps - On the VSTest runner, a --filter that matches no test prints a warning and still exits 0. A typo reads as a pass. - Nullable annotations are compile-time only. The runtime never acts on them, so `!` removes the only signal there is. - A migration is generated by comparing the model to a snapshot. Read it before you apply it; after it is applied, add a new migration rather than editing it. - dotnet run resolves from the NuGet cache and is not how production starts.
That is 56 lines. Anything an agent learns from the .csproj files or from one build was cut, and the commands that are not obvious were kept.
Why each block is there
The title and the one-line description
The opening names the workload and the shape of the repository, which is what makes the commands below unambiguous. Microsoft describes an SDK-style project as one associated with a project SDK that carries the MSBuild targets and tasks that compile, pack and publish it, and modern .NET projects are all of that shape.
The command block
Anthropic's guidance puts build commands among the facts a CLAUDE.md exists to hold, and asks for instructions concrete enough to verify. Every line here is one a reader can paste into a terminal.
There is no restore line, on purpose: Microsoft's build page says you do not have to run dotnet restore because the commands that need it run it implicitly, and that dotnet build produces the binaries with MSBuild. The run line is there because an agent otherwise guesses how the API starts. The test line is broader than it looks: dotnet test builds the solution and then runs the tests with whichever runner the project uses.
The format line is the one an agent skips. Microsoft describes dotnet format as a formatter that applies style preferences from .editorconfig, and gives --verify-no-changes a non-zero exit code when a file would change, which is what makes it usable in a pipeline.
The layout
Three projects, each with a rule that is invisible from its name. The one that earns its place is the boundary between Api and Infrastructure: a query belongs behind it, and an IQueryable crossing it is how an endpoint becomes untestable.
Anthropic's size target is what keeps the list at five lines. A tree of the whole solution is the quickest way to spend the budget on what an agent could read itself.
The rules
The nullable line is the highest-value rule in the file. Microsoft describes nullable reference types as a group of features that leave runtime behaviour unchanged and are entirely a compile-time feature, says recent templates set <Nullable>enable</Nullable>, and asks you to use ! sparingly because each occurrence is a place the compiler can no longer protect you.
The remaining rules are the ones a reviewer has already written in a pull request: the async shape, the record as a DTO, the boundary around a query, and the difference between a development run and a deployment. Each can be seen in a diff, which is the bar this page applies.
Testing
The "read the number" line exists for one reason: a filtered run that finds nothing is not a failure by default. Microsoft's VSTest documentation says the run prints a warning rather than an error and still returns 0, and that TreatNoTestsAsError in a .runsettings file is what turns that into a failure. A session that trusts the exit code alone will report a test that never ran.
The rest of the block names the choices a reviewer would otherwise argue about: which projects get a suite, the production provider, and a failing test before a fix.
Traps
The migration line is the one that keeps a schema honest. Microsoft describes EF Core comparing the current model against a snapshot of the old one to generate migration files, and recording every applied migration in a history table so it knows what has run. That is what makes a migration a generated artefact to read, and a new migration the way to change an applied one.
The last line is Microsoft's own advice: dotnet run resolves dependencies from the NuGet cache and is not recommended for running an application in production, where the published output is what runs.
What was left out, and why
- The package list. It is in the
.csprojfiles, it changes, and a copy here goes stale the first time somebody adds a package. - Analyzer and style settings. They live in
.editorconfigandDirectory.Build.props, where the compiler enforces them. A second copy here is a second source of truth, and Anthropic warns that contradicting instructions may be followed arbitrarily. - A rule for one project. That is a path-scoped rule with
pathsfrontmatter, which loads only when Claude touches a matching file. - The release procedure. A multi-step process belongs in a skill rather than in every session's context.
- A local connection string or a developer certificate. Those belong in user secrets or
CLAUDE.local.md, never in a committed file. - "Follow the SOLID principles." Uncheckable in a diff, and paid for on every turn.
Adapting it
Four swaps cover the common cases.
- One project instead of three. Collapse the layout, keep the rules and traps, and replace the query-boundary line with whatever the single project's own boundary is.
- Blazor or a desktop app instead of an API. Replace the endpoint language with your UI's, and drop the request and response line. The nullable, async, migration and test lines survive unchanged.
- A .NET Framework 4.x solution. This page describes a modern SDK-style solution. The nullable, async and test rules survive; the project layout, the format check and the EF commands do not. The Traps rule still applies: read a migration before you apply it.
- A database other than SQL Server. Keep the migration commands; only the provider in
src/Infrastructure/changes. The rule that a migration is read before it is applied is provider-independent.
Then prove it loaded. /context all lists the memory files read at launch, and a file missing from that list is not being ignored; it is not being seen.
How this page was written
The guidance on what belongs in a CLAUDE.md, how long it should be and how Claude treats it was read from Anthropic's Claude Code memory documentation on November 25, 2026. Every statement about .NET, C#, EF Core and the CLI was read from Microsoft's own documentation the same day, and each one is linked in the Sources below.
The example file was written for this page and has not been run against a live solution. Its rules are recommendations, not documented behaviour of C#, and you should check every command against your own repository before keeping it.
Sources
- Anthropic's How Claude remembers your project, for what belongs in a CLAUDE.md, the size target, the concreteness rule and the conflict rule, read November 25, 2026.
- Microsoft Learn, dotnet test, for what the command builds and runs, read November 25, 2026.
- Microsoft Learn, dotnet build, for implicit restore and the build output, read November 25, 2026.
- Microsoft Learn, dotnet format, for the formatter and
--verify-no-changes, read November 25, 2026. - Microsoft Learn, Nullable reference types, for the compile-time-only nature, the project setting and the
!guidance, read November 25, 2026. - Microsoft Learn, EF Core migrations, for the model snapshot and the history table, read November 25, 2026.
- Microsoft Learn, .NET project SDKs, for what an SDK-style project is, read November 25, 2026.
- Microsoft Learn, dotnet test with VSTest, for the filter syntax and the zero-test exit code, read November 25, 2026.
- Microsoft Learn, dotnet run, for why it is not a production entrypoint, read November 25, 2026.
Common questions
What should a CLAUDE.md for a C# project contain?
The dotnet commands you actually run, the project boundaries, the nullable and async rules a reviewer enforces, and the traps: a test filter that matches nothing still exits zero, nullable annotations are compile-time only, and an EF Core migration is generated from a model against a snapshot. Anthropic's target is under 200 lines, so anything Claude can read from the .csproj stays out.
Should the file insist on nullable reference types?
Yes, and it should say what to do with the warnings. Microsoft's documentation describes nullable reference types as entirely a compile-time feature that leaves runtime behaviour unchanged, and asks you to use the null-forgiving operator sparingly because each use is a place the compiler can no longer protect you. Fix the code, not the warning.
How should the file handle EF Core migrations?
Name the two commands and say who owns the generated file. Microsoft describes EF Core comparing the current model against a snapshot of the old one to generate a migration, and recording applied migrations in a history table. That makes a migration a generated artefact between the model and the database, so it is read before it is applied and committed beside the model change.
Why did a filtered dotnet test pass without running anything?
Because a filter that selects no tests is not a failure by default. Microsoft's VSTest documentation says the run prints a warning rather than an error and still returns 0, and that TreatNoTestsAsError in a .runsettings file is what changes it. A mistyped filter therefore reads as a green run, so the file tells Claude to check the discovered count.
Write CLAUDE.md once, and every agent reads it
Omniscio keeps your canonical CLAUDE.md or AGENTS.md mirrored to the filenames Codex, Gemini, Cursor and Copilot look for, and flags a copy that was edited outside it. Any model, any harness.
The features page covers what else it does, pricing covers the plans, and you can download it for Windows, macOS or Linux.