Direct answer
A C# source generator is a compiler extension that adds source files to a compilation. The generator, not the developer, owns those files, so the review unit is the contract behind the output: which inputs feed it, what state its incremental pipeline caches, which diagnostics it reports, and which generated files exist. A diff of generated code answers the wrong question. The concrete win is a generator change reviewed through its inputs, so a regenerated diff traces to a template or analyzer change instead of a hand patch. The concrete loss is that a generated file which compiles is not a generated file that is correct, and no compile proves semantics. The practical implication is that generated output is a build artifact, and editing it by hand is editing something the next build replaces. Ask Claude Code to name the generator’s inputs, pipeline state, diagnostics, and output ownership before interpreting any generated diff.
Why patching generated code costs a sprint
Generated source looks like source. It sits in the project, it has types and methods, and an editor will happily refactor it. A developer who fixes a bug by editing a generated file has produced a change that disappears on the next generation, which is the failure that costs the most time because it looks like it worked.
The second failure is subtler. A generator changes because its input changed, and a reviewer who reads only the emitted output cannot tell whether the output moved because the input moved or because the generator itself changed. That distinction is the whole review, and it is invisible in a raw file diff.
Evidence and its limits
Official, F035: Microsoft’s source generators overview describes source generators as compiler participants that produce additional source files the compiler can analyze. The Microsoft source-generator pages were not fetched in this pass, so verify current wording and examples before drafting.
Official: The incremental generators section describes the incremental pipeline model, which is the mechanism that determines when output is recomputed.
Official: The Roslyn SDK hub links the source generator cookbook and related references.
Official: PackageReference in project files documents how a generator is referenced by a project.
Official, agent loop: Claude Code best practices recommends pairing an edit with a pass-or-fail check and cautions against editing generated output by default.
Derived, F036: The input-to-output map, pipeline state inventory, and ownership matrix below are an editorial contract checklist, not a claim that emitted code is semantically correct.
No claim here depends on a Roslyn version, a generator package version, or any performance benchmark.
Where source generators run
A generator runs as part of compilation, before the compiler analyzes the final set of source files. It receives a compilation context and contributes additional syntax trees. The generated trees are then compiled alongside the handwritten ones.
| Phase | What happens | Who owns it | Review question |
|---|---|---|---|
| Compilation context | The compiler hands the generator the current compilation | Compiler | What can the generator see? |
| Generation | The generator produces syntax trees | Generator author | What inputs drove this output? |
| Analysis | The compiler analyzes all trees together | Compiler | Do diagnostics point at generated code? |
| Output | Generated files exist in the compilation | Generator | Can a human edit them safely? |
Treat the table as an ownership statement. The developer owns the input that triggers generation. The generator owns the output. Neither owns the other’s file.
Read generator inputs
Every generator consumes something. The common inputs are the compilation’s syntax trees, its semantic model, assembly attributes, and configuration such as analyzer options or additional files.
dotnet build -property:EmitCompilerGeneratedFiles=trueEnabling emitted generated files writes them to disk so the output can be inspected without a decompiler. The exact property support depends on the generator and tooling, so treat it as a thing to verify for the generator you are reviewing rather than a universal switch.
Record three things about the inputs: which source constructs trigger generation, which configuration or attributes parameterize it, and which additional files the generator reads. A generator whose output changed without any of these changing is the case that deserves the most suspicion.
| Input kind | Example | Change that moves output |
|---|---|---|
| Syntax trees | A class marked with an attribute | Adding or renaming the marked member |
| Attributes | A generator-specific attribute | Changing an attribute argument |
| Additional files | A text or JSON input file | Editing the file’s content |
| Analyzer config | An option in .editorconfig or project |
Changing the option value |
Understand incremental generators
Incremental generators run through a pipeline of steps, and each step caches its result. When an input changes, the pipeline recomputes from the first step whose input differs and reuses everything downstream that is still valid. The incremental section in F035 describes this model.
The pipeline matters for review because it explains partial recomputation. A generated file that did not change when you expected it to may be a cache hit, not a stale generator. A generated file that changed unexpectedly may be downstream of an input you did not consider.
| Pipeline state | What it holds | Invalidated by |
|---|---|---|
| Syntax provider output | Filtered candidate nodes | A change to matching syntax |
| Transform step | Semantic interpretation of candidates | A change to symbols or attributes |
| Equality comparison | Whether the value changed | Any change in the compared value |
| Emit step | The generated text | A change upstream in the pipeline |
Record the pipeline states for the generator under review. The inventory is what turns “the output changed” into “this input changed, so this step reran”.
Inventory emitted sources
Before interpreting a diff, list what the generator emits: the file names, the types and members in each, and the namespaces they land in. The inventory is the baseline that makes a generated diff readable.
dotnet build -property:EmitCompilerGeneratedFiles=true -property:CompilerGeneratedFilesOutputPath=generatedScan the emitted files for two things. Whether the file names are stable across generations, and whether the types they declare match the input the generator consumed. An emitted file whose name changed between builds is usually a naming decision in the generator, and it shows up as a rename in every downstream diff.
| Emitted file | Declares | Driven by | Stable name |
|---|---|---|---|
Widget.g.cs |
Widget partial class |
Widget definition |
Yes |
WidgetSerializer.g.cs |
Serializer type | Widget definition plus config |
Yes |
Generated_42.g.cs |
Internals | Position in pipeline | No |
A generated file without a stable name is a review hazard. Diffs against it are meaningless between builds, and the naming decision belongs in the generator, not in a rename review every cycle.
Review generator diagnostics
Generators can report diagnostics, and those diagnostics are part of the contract. A generator that emits a warning when an input is malformed is telling the developer something, and treating that warning as optional noise is the mistake to avoid.
Read diagnostics for three things. Which inputs produce them, whether they are errors or warnings, and whether the build treats them as blocking. A generator diagnostic that the build suppresses is a contract the team has decided to ignore, and that decision deserves to be written down rather than inherited silently.
| Diagnostic | Trigger input | Severity | Build effect |
|---|---|---|---|
| Missing required member | Marked type without the member | Error | Blocks compile |
| Deprecated input form | Old attribute usage | Warning | Warns |
| Unsupported target | Framework the generator cannot emit for | Error | Blocks compile |
A diagnostic inventory is short work and prevents the long argument about whether a warning “counts”. The compiler, not the reviewer, is the authority on whether the build blocks.
Separate generated and handwritten files
The ownership matrix is the artifact that makes the review durable. One row per file kind, with an owner and an edit policy.
| File kind | Owner | Edit policy | Review evidence |
|---|---|---|---|
| Handwritten source | Developer | Edit freely | Normal code review |
| Generated source | Generator | Do not edit; change the input | Input diff plus regenerated output |
| Handwritten partial partner | Developer | Edit the handwritten half only | Confirm the generated half is untouched |
| Additional input files | Developer | Edit as configuration | Regenerate and inspect output |
The partial class case deserves its own row because it is the one that looks editable. A generated half and a handwritten half meet at the type boundary, and the rule is to edit the handwritten half and let the generator produce the other.
Evaluate a generator change
A generator change is complete when a reviewer can answer five questions from the change description.
| Question | Where the answer lives | Pass condition |
|---|---|---|
| What input changed | Input inventory diff | Named explicitly |
| Which pipeline step reran | Pipeline state inventory | Named or marked unchanged |
| Which diagnostics apply | Diagnostic inventory | Listed with severity |
| Which files were emitted | Emitted file list | Stable names confirmed |
| Who owns each changed file | Ownership matrix | Generated files untouched by hand |
The fifth row is the concrete check. A generated diff that includes hand edits is a defect even when it compiles, because the next generation removes them.
Ask Claude Code to produce all five before interpreting the output. The generated-code ownership question here is the same one the OpenAPI generator customization guide covers for a different generator family.
A worked walkthrough of one generator change
Consider a generator that reads a class marked with a custom attribute and emits a serializer for it. A developer renames a property on the marked class and expects the serializer to follow. Configure and build succeed, and the generated diff shows the serializer unchanged except for one method that now throws at runtime because it references the old property name.
The instinctive fix is editing the generated file. That fix survives until the next build, because the generator owns the file and regenerates it from the input. The review question is not what the output looks like but which input moved.
Start with the input inventory. The renamed property is the input change. Trace it through the pipeline: the syntax provider re-runs because the marked class changed, the transform re-interprets the member, and the emit step produces new text. The generated diff should now trace to the rename, and the method that throws is the finding, not a mystery.
dotnet build -property:EmitCompilerGeneratedFiles=trueEnable emitted files and read the generated output directly rather than through a decompiler. Confirm three things: the file name is stable across generations, the declared types match the input, and no generated file was hand-edited in the diff under review.
Record the input change, the pipeline step that re-ran, and the emitted files in the change description. A reviewer reading those three can tell whether the output moved because the input moved or because the generator itself changed, which is the whole review.
Anti-patterns that look like fixes
Four patterns recur around generator work, and each one hides a decision a reviewer needs to see.
| Pattern | What it looks like | Why it hurts | Do instead |
|---|---|---|---|
| Editing generated output | Patching a .g.cs file |
The next build replaces it | Move the fix to the input |
| Treating diagnostics as noise | Suppressing a generator warning | A contract the team ignores silently | Inventory diagnostics with severity |
| Reading only the output diff | Reviewing emitted code alone | Cannot tell input change from generator change | Read the input first |
| Claiming correctness from compile | “It compiles, so it works” | Compile proves validity, not semantics | Separate executed check |
Editing generated output deserves the most caution because it looks finished. The patch compiles, tests may pass, and the change disappears at the next generation. The ownership matrix is the artifact that keeps generated files out of hand-edit territory.
None of these is a Roslyn defect. They are review hazards, and the input inventory plus the ownership check are what catch them.
A runbook for the next generated diff
The checklist earlier in this post is the pass condition. The runbook below is the sequence to follow when a generated diff arrives for review.
Identify the input that changed. If no input changed and the output did, the generator itself changed, and that is a different review with a different owner.
Trace the input through the pipeline and name the step that re-ran. A generated file that did not change when expected may be a cache hit rather than a stale generator.
Read the diagnostics the generator produced, with severity. A warning the team has decided to ignore is a decision that belongs in writing.
Enable emitted files and inventory what was produced, including whether file names are stable across generations.
Confirm no generated file was hand-edited in the diff. This is the concrete check, and a hand edit in generated output is a defect even when everything compiles.
The runbook takes minutes and produces the artifacts a reviewer needs: the input change, the pipeline step, and the ownership confirmation. Skipping it produces a review that reads the output and misses the cause.
Where this habit pays across the batch
The input-first habit in this post is the same one the rest of the batch applies to different generators and constructs. OpenAPI generator customization covers keeping templates and config in sync, GraphQL code generator client presets covers reviewing generated boundaries, and sqlc query annotations covers aligning SQL and generated types. Cargo build scripts covers generated-artifact contracts including rerun conditions.
The other .NET posts apply the same discipline to package versions. NuGet central package management asks for a props and override inventory before centralizing, and .NET multi-targeting asks for a per-framework matrix and build, which matters because a generator can behave differently per target.
The JVM and C++ posts apply it to resolution and configure boundaries. Gradle constraints vs dependencies, Gradle capability conflicts, Gradle variant attributes, and Maven optional dependencies each ask for tool evidence before an edit, as do CMake presets, CMake find_package vs FetchContent, and Conan CMakeDeps.
That consistency is deliberate. The constructs differ, but the shape is the same: read the evidence the tool already produces, then make the smallest change the evidence supports.
The same shape extends to the ecosystems covered in earlier batches. On the Python side, dependency groups versus extras separates local workflow requirements from published optional features, and stub drift audits a package’s declared types against its documented runtime surface. TypedDict boundaries covers separating truly optional keys from missing data before replacing broad dictionary annotations.
On the Go side, module compatibility covers keeping an exported API change inside an import contract, and graph pruning covers why an indirect dependency entry is graph metadata rather than something to delete. Workspace boundaries covers deciding what belongs in go.work versus what stays a module requirement.
On the Rust side, feature unification covers mapping which optional APIs a workspace build actually exposes, and workspace inheritance covers centralizing metadata without hiding crate-local exceptions. Profile boundaries covers separating diagnostic and optimization settings from options that change observable program behavior.
Generated-output ownership has a direct analog in Cargo build scripts, where the same “the build owns its artifacts” question applies to build-time generation rather than compiler codegen. Both are ownership questions, and both reward reviewing the input before the emitted file.
Working alongside the review bottleneck
A generated diff with a pasted input change and ownership check is cheap to review. A diff described as “regenerated” is a reviewer reproducing the work, and reproduction is the expensive part. The Claude Code code review bottleneck covers what happens when generation outpaces the review that has to accept it.
The same reasoning appears in Claude Code cost per verified change, which treats verified work as a separate unit from generated output. An input-to-output trace is a verified unit. A raw generated diff is not.
When the review queue is long enough that verification slips, the failure mode is a merge that nobody actually checked. Prevent false success from passing tests covers the case where a green build is the only evidence, and generated output is exactly the case where green proves less than it appears to.
The concrete win, loss, and implication
The concrete win is a generated diff that traces to an input. A reviewer reading the input change and the regenerated output can tell what the generator did and why, without reverse-engineering the emitted code.
The concrete loss is the correctness gap. Compiling generated code proves it is valid syntax the compiler accepts. It does not prove the generated logic is right, and no compile substitutes for the executed check that would. That verification is separate work this post does not pretend to automate.
The practical implication is that generated output is a build artifact with an owner, and artifacts are not edited by hand. Teams that keep the input-to-output map resolve fewer “why did this file change” questions. Teams that patch generated files pay for the same fix again at the next build.
Related reading on generated-code boundaries
Generated output ownership continues across the batch. OpenAPI generator customization covers templates and config staying in sync, and GraphQL code generator client presets covers reviewing generated boundaries from schema and operations. sqlc query annotations covers aligning SQL and generated types.
For .NET dependency context, NuGet central package management covers where package versions live, and .NET multi-targeting covers per-framework package versions, which matters because a generator can behave differently per target.
For Rust builds, the Cargo build scripts guide covers generated-artifact contracts including inputs, outputs, and rerun conditions, which is the same ownership discipline in another ecosystem.
Review habits sit upstream of every generator change. Ask what Claude Code verification requires before calling generated output done, and Claude Code cost per verified change treats verified work as a separate unit from generated output.
Checklist before accepting a generator change
Run this list against the diff. Each row is a pass condition.
| Check | Pass condition | If it fails |
|---|---|---|
| Input change | Named and diffed | Identify the input first |
| Pipeline step | Named or marked unchanged | Review the pipeline state |
| Diagnostics | Listed with severity | Read the diagnostic output |
| Emitted files | Listed with stable names | Fix naming in the generator |
| Hand edits | None in generated files | Move the fix to the input |
| Ownership | Generated and handwritten separated | Complete the ownership matrix |
| Correctness | Not claimed from a compile | Separate executed check |
Working with Claude Code on a generator change
Give the agent the generator project or package reference, the input that changed, and the emitted output location. Ask for the input-to-output map before interpreting any diff. The agent session works best when the check is a build that emits generated files plus a pass-or-fail ownership check, which is the shape the official best-practices guidance recommends.
Ask the agent to report five things when it finishes. The input that changed. The pipeline step that reran. The diagnostics that applied. The emitted files and whether their names are stable. Confirmation that no generated file was hand-edited. A report that omits the ownership check has not finished, because a hand edit in generated output is the defect the review exists to catch.
Reviewing whether the emitted logic is right is the reviewer’s job. The agent reads inputs and can regenerate output, but deciding whether the generated behavior is correct requires executed evidence nobody has produced yet. The Claude Code verification guide covers the review questions: what changed, what proves it, and what was not checked.
Data gap and future update
F035 and F036 rest on Microsoft source-generator pages that were not fetched in the research pass, so exact pipeline terminology, API names, and the emitted-files property support should be rechecked against current documentation before a real change. A future update should record, per generator, which inputs drive output, which pipeline states exist, and which diagnostics the team treats as blocking.
No generator performance result, benchmark, or generated-code correctness claim is made here. Whether a generator’s output is efficient or semantically right requires executed evidence this post does not have.
One AI API Key option for OpenAI-format agents
Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.
OpenAI-format agents have a separate route: One AI API Key offers https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. It is a different client and request format, not a workaround for Claude Code authentication. Check the free model list and eligibility notes before choosing an agent route, or read the quickstart for the request shape.
FAQ
Can I edit a generated file to fix a bug?
No. The next generation replaces it, and the fix disappears. Move the fix to the input that drives the generated file, regenerate, and review the new output.
Why did a generated file change when I did not touch the generator?
Because its input changed, or a downstream pipeline step recomputed. Record the input inventory and the pipeline state so the change traces to a cause instead of a mystery.
Does a compiling generated file mean it is correct?
No. A compile proves the generated syntax is valid. Correctness of the emitted logic needs an executed check, and this post makes no correctness claim for any generated output.
How do I tell generated files from handwritten ones?
Check the generator’s output naming convention and the ownership matrix. Generated files are conventionally suffixed and are reproduced by the build. A handwritten partial partner is the exception, and it is owned separately from its generated half.
What are incremental generators for?
They cache pipeline steps so output is recomputed only when an input to a step changes. The incremental section in F035 describes the model. For review, the pipeline explains partial recomputation.
Related reading in this batch
This post is one of ten build-system and generated-code guides written together. NuGet Central Package Management and .NET Multi-Targeting complete the .NET set.
The JVM posts cover dependency and variant boundaries: Gradle Constraints vs Dependencies, Gradle Capability Conflicts, Gradle Variant Attributes, and Maven Optional Dependencies.
The C++ posts cover build inputs and dependency boundaries: CMake Presets, CMake find_package vs FetchContent, and Conan CMakeDeps.
More from this batch
- NuGet Central Package Management: Plan a Cross-Project Migration
- .NET Multi-Targeting: Separate Framework Dependencies for Claude Code
- OpenAPI Generator Customization: Keep Templates and Config in Sync
- sqlc Query Annotations: Align SQL and Generated Types With Claude Code
- CMake Presets: Give Claude Code Reproducible Configure Inputs
More Claude Code troubleshooting
- Python Protocols vs ABCs: Preserve Interface Contracts With Claude Code
- pnpm Peer Diagnostics: Read Resolution Reports Before Claude Code Pins
- TypeScript Project References: A Claude Code Boundary Guide
- Protocol Buffer Reserved Fields: A Claude Code Wire Compatibility Guide
- Django Deprecation Runway: Plan Framework Maintenance With Claude Code
- Rails Upgrade Sequence: Order Major Changes With Claude Code
- Angular Update Guide: Build a Migration Plan With Claude Code
Sources
- Official: Microsoft Learn: Source Generators Overview, supporting F035 on generators producing additional source files.
- Official: Microsoft Learn: Incremental Generators, incremental pipeline model.
- Official: Microsoft Learn: Roslyn SDK and Source Generator Cookbook, reference hub.
- Official: Microsoft Learn: PackageReference in Project Files, how a generator is referenced.
- Official: Claude Code Docs: Best Practices, supporting the generated-output ownership caution.