Zum Inhalt springen

Architecture feedback for coding agents in .NET projects

How a coding agent receives architecture findings while it works, and which check before merge tells a suppression apart from a fix.

by CodeCharter
  • ai
  • code-quality
  • code-review

A coding agent is asked to add a discount to an order system. It gives OrderService.PlaceOrder a discount parameter, creates a public static class for it and writes two new tests:

/// <summary>Applies discounts to order totals.</summary>
public static class DiscountHelper
{
    public static decimal Apply(decimal total, decimal discount)
        => Math.Max(0m, total - discount);
}

The build runs without a warning, all three tests in the solution pass, and the agent reports the task as done. The team, however, has a rule that business logic is injected through interfaces. Neither the compiler nor the tests check that rule. The sections below walk through the example with CodeCharter v1.7.0. The agent gets the violation reported while it works and then reaches a green run in two ways. Only the check before merge tells the two apart. The solution is constructed and the agent's steps are reenacted. Commands and outputs come from real runs.

Findings while the agent works

The agent first has to apply a written guideline to its code, and the guideline takes up space in the model context next to code, task and tool output. In its article on context engineering, Anthropic treats this context as a scarce resource and recommends tools that answer sparingly. An executable rule checks the changed code itself and reports only what violates it. Through the MCP server, the agent calls analyze_diff with git_ref: "main..HEAD" and include_context: true and gets two findings back (shortened):

{"findings": [
  {"ruleId": "bad-suffixes-avoid-helper-suffix", "severity": "info",
   "filePath": "…\\src\\Shop.Ordering\\DiscountHelper.cs", "line": 4,
   "message": "Avoid 'Helper' class suffix: Shop.Ordering.DiscountHelper"},
  {"ruleId": "static-class-non-extension", "severity": "info",
   "filePath": "…\\src\\Shop.Ordering\\DiscountHelper.cs", "line": 4,
   "message": "Static class has public non-extension methods: Shop.Ordering.DiscountHelper",
   "recommendation": "Preferred: extract the logic into an instance class, define an interface, and register it in DI …"}],
 "diffLinesAnalyzed": 39, "filesAnalyzed": 3, "isInconclusive": false}

The recommendation of the second rule names the refactoring the team rule demands. Both rules are set to info in the profile codeguard/csharp-all. A gate with --fail-on error therefore lets them through, and error is also the default of the GitHub Action. If the rule should block, the team raises its severity in .codecharter/config.yml:

version: 1
profiles:
  - codeguard/csharp-all@^1.0
overrides:
  static-class-non-extension:
    severity: error

The MCP server comes with no instruction on when the agent calls analyze_diff. The team therefore writes into the project instructions, for example in CLAUDE.md or AGENTS.md, that the agent checks after every change and fixes findings. Only CI shows whether it follows them.

Fixing it with an interface

The agent follows the recommendation. It deletes DiscountHelper, creates a contract with an implementation and passes it to OrderService as a third constructor parameter:

public interface IPricingPolicy
{
    decimal ApplyDiscount(decimal total, decimal discount);
}

public sealed class PricingPolicy : IPricingPolicy
{
    public decimal ApplyDiscount(decimal total, decimal discount)
        => Math.Max(0m, total - discount);
}

The tests pass new PricingPolicy() and still pass. Calling analyze_diff again returns "findings": [], and the CLI reports No violations found. Compared with the first state, the agent has changed six files. OrderService now depends on the contract IPricingPolicy, and a test can pass it a different implementation.

Suppression as a second way

The agent reaches the same empty result with a single line above the class:

/// <summary>Applies discounts to order totals.</summary>
// codecharter-disable-next-line static-class-non-extension bad-suffixes-avoid-helper-suffix
public static class DiscountHelper

In the example, the commit carries the message fix(ordering): resolve analysis findings. The three tests pass, and every analysis is green:

> codecharter analyze Shop.slnx --git-ref main..HEAD --diff-context --fail-on info
  No violations found.
  0 violations
  Analyzed 10 types, 9 methods in 1,4s

analyze_diff also returns "findings": []. CodeCharter removes suppressed findings before it builds a report. Console, JSON and SARIF then contain no trace of them, and --fail-on does not see them. After the fix and after the suppression, the reports differ only in the number of analyzed types and methods. Only the diff shows what happened: six changed files against one new comment line.

If the agent works with the hook package for Claude Code, the local CodeCharter host records the session. At the end of the session, it searches the diff since the session's start commit for the text of a suppression. Its web UI then shows the entry "A suppression was added" with file and line under "Red flags". If the agent changed code after its last analyze_diff, the list also shows "No analyze_diff after the last change". If two agents share a working directory, the host also attributes the other agent's changes to each session. The view helps the developer who runs the agent before they open the pull request. The reviewer does not see it, because it lives only in the host on the developer machine. For the reviewer, what counts is what CI reports in the pull request.

Check before merge

For the merge, what counts is the state that goes into the main branch. The checkout determines which state CI checks, because CodeCharter analyzes the files in the working directory. Without ref, actions/checkout checks out the merge commit on pull_request, and with ref: ${{ github.event.pull_request.head.sha }} it checks out the head of the branch. CI checks in two steps. The first applies the rules to the changed lines. The second searches for new suppressions that the first does not see. The following script does both, and CI calls it with origin/main as the base:

#!/bin/sh
base="$1"
status=0

codecharter analyze Shop.slnx --git-ref "$base...HEAD" --diff-context --fail-on info || status=1

if git diff -U0 "$base...HEAD" -- '*.cs' '*.razor' \
   | grep -nE '^\+.*(codecharter-disable|codeguard-disable|SuppressMessage|#pragma warning disable)'; then
  echo "New suppression in this branch: needs an explicit review."
  status=1
fi

exit $status

The script treats every exit code other than 0 as a failure. Besides 1 for findings, CodeCharter returns 2 when the run was inconclusive or the invocation was invalid. The list of exit codes names the others. --fail-on info blocks every info finding of the profile in the changed lines. In the example, the uncleaned starting code already reported 14 of them, mostly missing XML documentation. If only the architecture rules should block, the team raises them to error through overrides and calls the analysis with --fail-on error.

On the suppression state, the first step stays green and the second one fails:

  No violations found.
  0 violations
10:+// codecharter-disable-next-line static-class-non-extension bad-suffixes-avoid-helper-suffix
New suppression in this branch: needs an explicit review.
gate-exit=1

A new suppression keeps the check red, even a justified one. The team therefore decides who approves it, for example a code owner through a label that makes CI skip the second step.

The agent keeps changing code after the fix as well. analyze_diff has reported "findings": []. After that, without a new check, it adds rounding in another static class PriceRounding and commits. The tests stay green, and the script on the new head reports PriceRounding.cs:4 and ends with exit 1. The agent's last check applied only to the state it ran on.

According to its code, the GitHub Action v1.11.0 takes over the first step when diff: 'true' and fail-on: info are set or the rule is set to error through overrides. It does not pass --diff-context. With a CLI up to v1.7.1, it then does not report a class-level finding as blocking when the pull request does not change the class's declaration line. Later CLI versions gate such a finding at the fail-on threshold without --diff-context (analyze documentation). Teams that need this call the CLI as in the script. In both cases, the search for suppressions remains a separate step.

A pre-push hook with the same script reports both before the push. CodeCharter does not ship such a hook, and the team creates .git/hooks/pre-push itself. In the example, the agent pushed agent/discount-fix while agent/discount-late was checked out. The hook checked the checked-out state and blocked the push because of PriceRounding.cs:4, a file that does not exist on agent/discount-fix. git push --no-verify bypasses the hook entirely. Only the check in CI is therefore binding.

Review order

The reviewer works in this order. First, the rule step of CI has to be green on the checked commit. Then the reviewer looks at every suppression the second step reports. A justified exception carries its reason after -- on the same line, for example // codecharter-disable-next-line static-class-non-extension -- approved exception, see ADR 12. CodeCharter neither requires this justification nor evaluates it. The reviewer decides in the pull request whether it holds. The reviewer checks changes to .codecharter/config.yml just as closely, because that is where rules get their severity. Only then does the reviewer read the code for design questions that no rule decides. Does the code calculate the discount correctly for the business? Does it belong in the order flow? Does the new rounding already exist elsewhere? In its guide to reviewing agent pull requests, GitHub names duplicated logic as a typical mistake. The agent finds a pattern and replicates it without seeing the existing solution elsewhere.

In 2022, Gunawardena, Tempero and Blincoe analyzed 417 review concerns from seven open source Java projects. Tools such as SonarQube, Checkstyle and PMD could detect 22% of the concerns with no false positives or false negatives. A further 16% would have been detectable with new rules, in the authors' assessment often project-specific concerns that general rules do not cover. The study, by contrast, names "Poor design" and "Low class cohesion" as examples of concerns that cannot be detected reliably by automation. No general tool checks a team rule such as "business logic through interfaces" on its own. The team records it as a rule, and the agent gets it reported while it works. Whatever cannot be expressed through types, methods and dependencies, such as whether the discount is correct for the business, remains a matter for review.