Slopwatch.Cmd
0.5.0
dotnet tool install --global Slopwatch.Cmd --version 0.5.0
dotnet new tool-manifest
dotnet tool install --local Slopwatch.Cmd --version 0.5.0
#tool dotnet:?package=Slopwatch.Cmd&version=0.5.0
nuke :add-package Slopwatch.Cmd --version 0.5.0
<p align="center"> <img src="https://raw.githubusercontent.com/Aaronontheweb/dotnet-slopwatch/dev/images/logo.png" alt="Slopwatch Logo" width="256" height="256"> </p>
<h1 align="center">Slopwatch</h1>
<p align="center"> <strong>// LLM anti-cheat</strong><br> A .NET tool that detects LLM "reward hacking" behaviors in code changes. </p>
<p align="center"> <a href="https://www.nuget.org/packages/Slopwatch.Cmd"><img src="https://img.shields.io/nuget/v/Slopwatch.Cmd.svg" alt="NuGet"></a> <a href="https://github.com/Aaronontheweb/dotnet-slopwatch/blob/dev/LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" alt="License"></a> <a href="https://discord.gg/2smteJ8sGh"><img src="https://img.shields.io/discord/1494176300657545318?label=Discord&logo=discord&color=5865F2" alt="Discord"></a> </p>
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
VersionOverrideor inlineVersionattributes - 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 statusto 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
partialtype 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 ausingalias or a namespace declared in scope. An unrelated attribute such asAcme.GeneratedCodedoes 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
- Fork and create a feature branch
- Make changes and add tests
- 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
- Slopometry - Python equivalent for Claude Code
- Incrementalist - Git diff analysis patterns
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.5.0 | 10,371 | 11/16/2026 |
| 0.4.2 | 83,478 | 6/10/2026 |
| 0.4.1 | 7,800 | 5/28/2026 |
| 0.4.0 | 14,844 | 3/2/2026 |
| 0.3.4 | 5,873 | 2/18/2026 |
| 0.3.3 | 10,283 | 1/21/2026 |
| 0.3.2 | 255 | 1/17/2026 |
| 0.3.1 | 1,474 | 1/15/2026 |
| 0.3.0 | 24,623 | 1/12/2026 |
| 0.2.1 | 262 | 1/12/2026 |
| 0.2.0 | 3,600 | 1/11/2026 |
| 0.1.1 | 168 | 1/11/2026 |
| 0.1.0 | 181 | 1/11/2026 |
**Features:**
* New rule **SW021 — Dynamic Keyword Ban**. Flags any use of the `dynamic` keyword at error severity. Dynamic bypasses compile-time type checking, defeats static analysis, breaks trimming/AOT, and is a common LLM escape hatch for silencing type errors instead of fixing them (#139)
* Generated code is now skipped by default — files with an `<auto-generated>` header or a generated filename (`*.g.cs`, `*.Designer.cs`, `*.generated.cs`, `*.g.i.cs`, `TemporaryGeneratedFile_*`) are no longer analyzed. These are the same signals Roslyn's analyzers use, so slopwatch skips what the compiler skips (#141)
* `[GeneratedCode]` / `[DebuggerNonUserCode]` attribute detection is available as an opt-in via `generatedCode.detectAttributes`. It is off by default because attribute identity cannot be resolved without a compilation, and a wrong answer would silently drop hand-written findings (#141)
* New `generatedCode` section in `.slopwatch/config.json` with `skip` (default), `analyze`, and `analyzeAndReport` modes. `init` and `analyze` both honor it (#141)
* Generated filename patterns (`*.g.cs`, `*.Designer.cs`, `*.generated.cs`, `*.g.i.cs`) are no longer in the default exclude list — the `generatedCode` mode now owns that decision, so `analyze` mode can reach those files (#141)
* `analyzeAndReport` findings carry `isGeneratedCode` in JSON output and a `[generated]` marker in console output (#141)
* `--update-baseline` now preserves baseline entries for files skipped entirely as generated code, so changing modes later does not resurface a wall of findings. Files that are analyzed with individual generated findings filtered out are pruned normally (#141)
**Behavior Changes:**
* **SW021 is on by default at error severity, and there is no way to disable a rule.** There is no rule-filter flag and no config key for rule enablement — only `[SlopwatchSuppress]` or baselining. Combined with `--fail-on error` (the default) and hook mode failing on warnings, **any codebase that uses `dynamic` will start failing CI and blocking edits on upgrade.** If that is not what you want, baseline the existing occurrences before upgrading (#139)
* Generated files that were previously analyzed are now skipped by default. If you rely on findings in generated files, set `generatedCode.mode` to `analyze` or `analyzeAndReport` (#141)
* **Baseline schema is now version 2, and existing baselines must be regenerated.** SW001–SW006 entries used to hash on the display snippet, so two identical occurrences in one file collapsed to a single identity and baselining one silently exempted the other. Entries now hash on a structural path. A version 1 baseline cannot match the new hashes, so `analyze` stops before running and tells you to regenerate (#142):
```
slopwatch init --force
```
Review the regenerated `.slopwatch/baseline.json` before committing it. A baseline with no `version` property at all is treated as version 1 and rejected the same way. If you run `analyze` with a custom `--baseline` path, the error names that path and the remedy becomes `slopwatch init --force --baseline <path>` — `init` now accepts `--baseline` so it can regenerate the file that actually failed. A real migration path — recording which identity scheme produced each entry — is tracked by #107.
* Baseline churn increases: adding or reordering sibling declarations changes the group fingerprint and invalidates those entries. This is deliberate — it rejects false exemptions rather than silently carrying them forward (#142)
**Bug Fixes:**
* Nested git worktrees are now skipped structurally instead of by directory name. The default exclude list contained `**/worktrees/**`, which skipped **any** directory named `worktrees` — including ordinary source — and reported a clean scan for code it never read. A project keeping source under `worktrees/` got `0 files analyzed` and exit 0. Detection now identifies a linked worktree by Git's administrative layout: a `.git` file whose gitdir carries both a `commondir` file and a reciprocal `gitdir` pointer. Submodules and `git init --separate-git-dir` checkouts also use `.git` files but carry neither, so their source is analyzed (#99, #158)
* SW021 no longer flags `using dynamic;` and `using static dynamic;`. A using directive's name is a namespace-or-type reference, never a dynamic-typed slot, so both were false positives. `using D = dynamic;` still reports — that aliases the builtin type and is a genuine dynamic slot (#143)
* SW001 no longer reports a method in the active `#else` or `#elif` branch of an `#if false` block as disabled (#142)
* `[SlopwatchSuppress]` now works on lambdas. It was silently ignored because the suppression checker had no lambda case (#139)
* `[SlopwatchSuppress]` is now valid on `struct`, `interface`, `constructor`, `delegate`, `event`, `enum`, destructor, indexer, operator, conversion operator, local function, and accessor. These were compile errors before (#139)
* `init --config` now forwards the config path to the suppression checker, so suppressions declared in the selected config are honored (#141)
* `init` now honors the `generatedCode` config, so the baseline it writes agrees with the next `analyze` run (#141)
**Performance:**
* SW021 identity generation is now linear in dynamic occurrence count instead of quadratic. Sibling-group fingerprints and structural path segments are memoized per analysis call, so a file with many `dynamic` occurrences no longer rehashes every sibling and rebuilds every ancestor segment per occurrence (#144)
* Structural path caching for SW001–SW006. XML identities dropped from 57 GB to 30 MB at 2,000 findings, and named-method siblings from 3.47 GB / 6.4 s to 2 MB (#142)
* Baseline creation is now linear. `AddEntry` invalidated the hash lookup after every insertion, which was quadratic in entry count (#142)
**Dependencies:**
* Bumped Microsoft.CodeAnalysis.CSharp from 5.3.0 to 5.6.0
* Bumped Microsoft.Extensions.FileSystemGlobbing from 8.0.0 to 10.0.9
* Bumped Microsoft.SourceLink.GitHub from 8.0.0 to 10.0.301
* Bumped Microsoft.NET.Test.Sdk from 18.0.1 to 18.9.0
* Bumped Akka.Streams from 1.5.68 to 1.5.74
* Bumped dotnet-sdk from 10.0.300 to 10.0.401
* Bumped actions/checkout from 6.0.2 to 7.0.1
* Bumped actions/setup-dotnet from 5.3.0 to 6.0.0
* Bumped codecov/codecov-action from 6 to 7
* Bumped incrementalist.cmd from 1.2.1 to 1.2.2