Skip to content

About

Catch naughty LLM reward-hacking and bad behavior for .NET coding

Resources

Code of conduct

Contributing

Stars

126 stars

Watchers

0 watching

Forks

Repository files navigation

Slopwatch Logo

Slopwatch

// LLM anti-cheat
A .NET tool that detects LLM "reward hacking" behaviors in code changes.

NuGet License Discord


Runs as a Claude Code hook or in CI/CD pipelines to catch when AI coding assistants take shortcuts instead of properly fixing issues.

What is "Slop"?

When LLMs generate code, they sometimes take shortcuts that make tests pass or builds succeed without actually solving the underlying problem. These patterns include:

  • Disabling tests instead of fixing them ([Fact(Skip="flaky")])
  • Suppressing warnings instead of addressing them (#pragma warning disable)
  • Swallowing exceptions with empty catch blocks
  • Adding arbitrary delays to mask timing issues (Task.Delay(1000))
  • Project-level warning suppression (<NoWarn>, <TreatWarningsAsErrors>false</TreatWarningsAsErrors>)
  • Bypassing Central Package Management with VersionOverride or inline Version attributes
  • And more...

Slopwatch catches these patterns before they make it into your codebase.

Installation

# Install as a global tool
dotnet tool install --global Slopwatch.Cmd

# Or install locally
dotnet new tool-manifest
dotnet tool install --local Slopwatch.Cmd

Quick Start

# 1. Install slopwatch
dotnet tool install --global Slopwatch.Cmd

# 2. Initialize in your project (creates baseline from existing code)
cd your-project
slopwatch init

# 3. Commit the baseline to your repository
git add .slopwatch/baseline.json
git commit -m "Add slopwatch baseline"

# 4. From now on, only NEW slop is detected
slopwatch analyze

The baseline approach ensures slopwatch catches new slop being introduced without flagging legacy code. Your CI/CD pipeline will fail if someone introduces new slop patterns.

Usage

Initialize a Project

# Create baseline from existing code
slopwatch init

# Force overwrite existing baseline
slopwatch init --force

This creates .slopwatch/baseline.json containing all existing detections. Commit this file to your repository.

Analyze for New Issues

# Analyze current directory (requires baseline by default)
slopwatch analyze

# Analyze specific directory
slopwatch analyze -d src/

# Skip baseline and report ALL issues (not recommended for CI)
slopwatch analyze --no-baseline

Update Baseline

When you intentionally add code that triggers slopwatch (with proper justification):

# Add new detections to existing baseline
slopwatch analyze --update-baseline

Output Formats

# Human-readable console output (default)
slopwatch analyze

# JSON for programmatic use
slopwatch analyze --output json

Exit Codes

# Fail if errors found (default)
slopwatch analyze --fail-on error

# Fail on warnings too
slopwatch analyze --fail-on warning

Performance

If you're concerned about performance on large projects, use --stats to see how many files are being analyzed and how long it takes:

slopwatch analyze --stats
# Output: Stats: 44 files analyzed in 1.64s

Detection Rules

Rule Severity Description
SW001 Error Disabled tests via Skip, Ignore, or #if false
SW002 Warning Warning suppression via pragma or SuppressMessage
SW003 Error Empty catch blocks that swallow exceptions
SW004 Warning Arbitrary delays in test code (Task.Delay, Thread.Sleep)
SW005 Warning Project file slop (NoWarn, TreatWarningsAsErrors=false)
SW006 Error CPM bypass via VersionOverride or inline Version attributes
SW021 Error Any use of the dynamic keyword

Claude Code Integration

Add slopwatch as a hook to catch slop patterns during AI-assisted coding. Add the following to your project's .claude/settings.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "slopwatch analyze -d . --hook",
            "timeout": 60000
          }
        ]
      }
    ]
  }
}

The --hook flag enables Claude Code integration mode which:

  • Uses git status to only analyze dirty files - makes hooks near-instant even on large repos
  • Outputs errors to stderr in a readable format
  • Suppresses all other output
  • Blocks on warnings and errors
  • Exits with code 2 on failure (blocking the edit)

Claude will see the formatted error message and can then fix the issue properly.

Note: Hook mode requires git. If git is unavailable, it falls back to full analysis.

CI/CD Integration

GitHub Actions

- name: Install Slopwatch
  run: dotnet tool install --global Slopwatch.Cmd

- name: Run Slopwatch
  run: slopwatch analyze -d . --output json --fail-on error

Note: The baseline file (.slopwatch/baseline.json) should be committed to your repository. Run slopwatch init locally first.

Azure DevOps

- task: DotNetCoreCLI@2
  displayName: 'Install Slopwatch'
  inputs:
    command: 'custom'
    custom: 'tool'
    arguments: 'install --global Slopwatch.Cmd'

- script: slopwatch analyze -d . --fail-on error
  displayName: 'Run Slopwatch'

Configuration

Create a .slopwatch/config.json file to define suppressions:

{
  "suppressions": [
    {
      "ruleId": "SW002",
      "pattern": "**/Generated/**",
      "justification": "Generated code from tooling cannot be manually changed"
    },
    {
      "ruleId": "SW006",
      "pattern": "src/Legacy/**",
      "justification": "Legacy CPM migration in progress; tracked in issue #123"
    }
  ],
  "globalSuppressions": []
}

Use the -c or --config option to specify a custom suppression config file location:

slopwatch analyze -d . --config path/to/config.json

To exclude files or directories from analysis entirely, use --exclude:

slopwatch analyze -d . --exclude "**/Generated/**,**/obj/**,**/bin/**"

Generated Code

Slopwatch skips generated code by default. Findings in generated files cannot be acted on — the file is regenerated on the next build — so reporting them only trains people to ignore the tool.

A file counts as generated when any of these is true:

  • Its name matches a generated-code convention: TemporaryGeneratedFile_*, *.Designer.cs, *.generated.cs, *.g.cs, *.g.i.cs
  • A leading comment contains <auto-generated> or <autogenerated>
  • The enclosing type carries [GeneratedCode] or [DebuggerNonUserCode]

These are the same signals Roslyn's own analyzers use, so slopwatch skips what the compiler skips. The attribute check is per-type, so a hand-written type in a file that also contains a generated type is still analyzed. Partial types are treated as hand-written, matching Roslyn's behavior.

Two deliberate deviations from Roslyn, both in the conservative direction (a file is analyzed rather than skipped):

  • A partial type is never treated as generated, even when its only declaration carries the attribute. The attribute may live on a declaration in another file, and resolving that requires a compilation.
  • Attribute identity is resolved from syntax alone. A global::-qualified name binds to the framework type unconditionally. Any other name must survive shadowing checks: an unqualified name needs its declaring namespace imported in the attribute's lexical scope with no shadowing alias or local type, and a qualified name needs its root segment unshadowed by a using alias or a namespace declared in scope. An unrelated attribute such as Acme.GeneratedCode does not cause a skip.

Attribute detection is opt-in. Slopwatch analyzes one file at a time, so a same-named attribute or a shadowing namespace declared in another file of the same project is invisible. A wrong answer there silently drops hand-written findings, so attribute detection is off by default. Enable it if your project uses [GeneratedCode] and does not declare its own attribute of that name:

{
  "generatedCode": {
    "detectAttributes": true
  }
}

Filename and header detection are always active and are decided from syntax alone.

Control this with the generatedCode section in .slopwatch/config.json:

{
  "generatedCode": {
    "mode": "skip"
  }
}
Mode Behavior
skip (default) Generated files are not analyzed
analyze Generated files are analyzed exactly like hand-written source
analyzeAndReport Generated files are analyzed and findings are marked as generated

Baseline entries for skipped files are preserved during --update-baseline, so switching modes later does not resurface a wall of findings.

Building from Source

dotnet build
dotnet test
dotnet pack

Contributing

  1. Fork and create a feature branch
  2. Make changes and add tests
  3. Submit a pull request

Note: This project uses slopwatch on itself - your PR will be analyzed for slop patterns!

License

Apache 2.0 - see LICENSE for details.

Inspiration

About

Catch naughty LLM reward-hacking and bad behavior for .NET coding

Resources

Code of conduct

Contributing

Stars

126 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages