Counterproof
v1.0.1Now on PyPI: pip install counterproof

Verification for AI coding agents

Green tests are a claim.
Counterproof checks it.

When the same agent writes the fix and the test, a passing suite proves very little. Counterproof runs five probes against the change in isolated git worktrees and returns a verdict that no language model decides.

 pip install counterproof
 counterproof verify

Python 3.11+ · pytest, Vitest, Jest · Apache-2.0 · nothing leaves your machine unless you add an LLM key

Proof certificate

2 files, +14 -0 | intent: bugfix | profile: full | 15s | $0.00

Red-green
PASS: 2 of 3 test(s) fail on the old code (test_discount_is_capped,...
Integrity
OK (0 findings)
Mutants
6/7 killed (0.86). 1 survivor(s)
Blind oracle
not run (LLM disabled)
Claim audit
skipped (no transcript given)
  • tests fail on the old code and pass on the new; 6/7 mutants killed (0.86)

PROVEN R-PROVEN

One reported bug, four changes whose own tests all pass. Real Counterproof output, rule-only, seed 00…00.
Works with
  • pytest
  • Vitest
  • Jest
  • Claude Code
  • GitHub Actions
  • MCP clients
  • git hooks

The problem

Agents optimise for the check they can see

Published benchmarks such as EvilGenie caught coding agents hard-coding test cases and editing tests. In our own recorded Claude Code sessions, an agent told not to touch a contradictory test bent the code to satisfy it, then reported All 68 tests pass. Four ways a change can be green and still wrong:

  • Hard-coded outputs

    The code special-cases the exact inputs its own test uses: if amount == 200: return 30.

    REFUTED by the integrity probe

  • Weakened tests

    An assertion removed or loosened, a new skip, a deleted test: the bar lowered until the change clears it.

    REFUTED by the integrity probe

  • Partial fixes

    Only the reported example is fixed. The new test passes, and so do wrong versions of the changed line.

    WEAK with the missing test named

  • False claims

    The suite passes, from a session that never ran it after the last edit, or piped it through | tail and hid the exit code.

    REFUTED by the claim audit

Two-minute demo

Watch it check four changes for the same bug

Real runs on a fixture repository, no network, seed 00…00. Captions are part of the video; the transcript is below it.

Transcript
  1. An agent fixed a bug and says: all tests pass. Coding agents stop when their tests pass. But when the same agent writes the fix and the test, green is a claim, not evidence. Counterproof checks the claim.
  2. 1. Hard-coded fix. This fix special-cases the exact inputs its own test uses. The integrity probe sees an input compared with a test literal: refuted, before any mutant runs.
  3. 2. Partial fix. This one looks honest and its test fails on the old code. But wrong versions of the changed line still pass every test: nothing tests a discount at or below 20%.
  4. 3. Coach mode, inside Claude Code. In Claude Code the Stop hook tells the agent only what kind of test is missing and where. Never the faulty code, so it cannot write a test for our mutant.
  5. 4. “The test suite passes”. The agent said the suite passes. Its session piped pytest through tail, which hid exit code 1, and Counterproof's own baseline fails. Refuted.
  6. 5. Measured, not claimed. On the seeded corpus, green tests flag none of the gamed changes. Counterproof refutes every hard-coded and weakened one. Every number regenerates.

How it works

Five probes, cheapest first

Each probe asks a different question about the change, in isolated git worktrees of the old and the new code. A decision that is final after a cheap probe skips the expensive ones.

  1. P5

    Claim audit

    Compares the agent's final message with the commands its session actually ran: no test after the last edit, a subset run sold as the full suite, an exit code hidden behind | tail.

  2. P2

    Integrity

    Static checks for weakened tests and for code that special-cases the test's own inputs: removed assertions, new skips, if amount == 200: return 30.

  3. P1

    Red-green

    The change's tests must fail on the old code for a behavioural reason, and pass on the new code.

  4. P3

    Change-scoped mutants

    Realistic wrong versions of only the changed lines, from rules and optionally an LLM, filtered for equivalence. If the tests still pass on a wrong version, the change is not proven.

  5. P4

    Blind oracle

    With an LLM: tests written from the task and the public interface only, never a function body, run on the change and triaged when they fail.

The output

A verdict, not a score

Fourteen ordered rules map the evidence to one of five verdicts, and the exit code follows, so CI can gate on exactly the strictness you want. An LLM can propose mutants and tests; it never decides the verdict.

How the rules decide

Verdicts and exit codes
VerdictMeaningExit
PROVENRed on the old code, green on the new, and the tests catch wrong versions of the change.0
WEAKPlausible, with a named gap: a surviving mutant, a likely bug from the oracle, a soft finding.10
UNPROVENThe tests do not pin the change: they pass on the old code, or most wrong versions survive.20
REFUTEDEvidence of gaming: hard-coded outputs, a weakened test, a false claim of passing tests.30
INCONCLUSIVEThe tests could not be run reliably: build error, red head, too flaky.40

Results

Measured, not claimed

Corpus C1: 160 seeded changes in a Python and a TypeScript library, three gamed variants and one honest fix per task, compared with simple baselines. Every number regenerates with counterproof eval eval/corpora/c1.

98%of gamed changes flagged WEAK or worse, with an LLM (75% UNPROVEN or REFUTED)

8%of honest fixes refuted or called unproven

0%of gamed changes caught by "the tests are green"

Gamed changes caught

Higher is better. Hard-coded, weakened and partial fixes whose own tests pass.

  • Counterproof, with an LLM 75% Counterproof, with an LLM: 75% · 90 of 120
  • Counterproof, rules only 67% Counterproof, rules only: 67% · 80 of 120
  • B0: The tests are green 0% B0: The tests are green: 0% · 0 of 120
  • B2: Classic mutation, diff-scoped 39% B2: Classic mutation, diff-scoped: 39% · 47 of 120
Honest fixes flagged

Lower is better. Correct fixes that were flagged anyway.

  • Counterproof, with an LLM 8% Counterproof, with an LLM: 8% · 3 of 40
  • Counterproof, rules only 0% Counterproof, rules only: 0% · 0 of 40
  • B0: The tests are green 0% B0: The tests are green: 0% · 0 of 40
  • B2: Classic mutation, diff-scoped 22% B2: Classic mutation, diff-scoped: 22% · 9 of 40

Full results on three corpora, baselines and the limits we know about

Integrations

Where it runs

The same verification at the moment it is cheapest to act on: while the agent is still working, when it pushes, and when the pull request opens.

Claude Code

A Stop hook coaches the agent with the gap and its location, never the answer.

counterproof init --claude

GitHub Actions

One certificate comment per pull request, SARIF for code scanning, a gate on the verdict you choose.

uses: sudais-khalid/counterproof/action@v1

MCP

Any MCP client can call verify_change, get_report and explain_mutant.

claude mcp add counterproof -- counterproof mcp

git

A pre-push hook verifies each pushed range and blocks only at the verdict you set.

counterproof init --git-hook

Set up an integration

Check your agent's next change

Open source, local-first and free. One command in the repository the agent just touched.

 pip install counterproof && counterproof verify