Counterproof

Install and use Counterproof

Counterproof decides whether a code change is proven by the tests around it. It never edits your working tree: every run happens in isolated git worktrees under your cache directory.

Install

Counterproof is a Python command-line tool, published on PyPI. Install it with pip, or once, globally, with pipx or uv:

pip install counterproof
# or, isolated from your projects
pipx install counterproof
uv tool install counterproof

Upgrade to the latest release the same way, and check which version you have:

pip install --upgrade counterproof     # pipx upgrade counterproof / uv tool upgrade counterproof
counterproof --version

Then check that it can see git, your test runner and the run directory:

counterproof doctor

Counterproof needs Python 3.11 or newer and git. It runs your tests with the project's own environment, so it never installs packages for you.

Your first run

From your repository, after an agent (or you) has made a change:

counterproof verify                       # the working tree against HEAD
counterproof verify --base main --head HEAD
counterproof verify --task-file task.md   # what the change was meant to do
counterproof verify --transcript ~/.claude/projects/<project>/<session>.jsonl

The task text helps Counterproof infer the intent (bug fix, feature, refactor, tests only) and is what the blind oracle writes its tests from. The transcript turns on the claim audit. Without either, the probes that need them are skipped with no penalty.

Read the certificate

Every run ends with a proof certificate: the verdict and the rule that decided it, one line per probe, the reasons, and the evidence each reason rests on. Choose the format with --format text|md|json|html|sarif; counterproof report RUN_ID re-renders a stored run and counterproof explain RUN_ID r002 shows one mutant's diff, the tests that ran and the missing test.

Each run also writes a sealed evidence bundle (manifest, probe results, logs, the seed's commitment). The same inputs and seed give the same verdict.

How the verdict is decided

A pure function evaluates fourteen rules from top to bottom; the first terminal rule sets the verdict and every matching rule adds a reason. An LLM can propose mutants and oracle tests, but never decides the verdict.

#RuleWhenVerdict
1R-INC-BUILDBase or head cannot collect tests, no selected tests, or the budget ran out firstINCONCLUSIVE
2R-INC-FLAKYMore than 20% of selected tests are flakyINCONCLUSIVE
3R-REF-CLAIMThe agent claimed passing tests that fail, or claimed a run it never made while the baseline failsREFUTED
4R-INC-HEADREDSelected tests fail on the changeINCONCLUSIVE
5R-REF-INTEGRITYA high-severity integrity finding: assertion removed, test deleted, skip added, assertion neutralised, test inputs special-cased, test detectionREFUTED
6R-UNP-OVERFITThe overfit mutant (the change minus its general logic) survivesUNPROVEN
7R-UNP-NOREDGREENA bug fix or feature whose tests also pass on the old code, with a kill ratio below 0.8UNPROVEN
8R-UNP-WEAKTESTSKill ratio below 0.5 over at least 3 valid mutantsUNPROVEN
9R-WEAK-SURVIVORA high-plausibility survivor, or a kill ratio in [0.5, 0.8)WEAK
10R-WEAK-APIONLYTests fail on the old code only because the API is missing, and some mutant survivesWEAK
11R-WEAK-ORACLEThe blind oracle found a likely bug (confident triage)WEAK
12R-WEAK-MEDIUMA medium-severity integrity or claim findingWEAK
13R-WEAK-FEWMUTANTSFewer than 3 valid mutants could be generatedWEAK
14R-PROVENOtherwise: strong red-green, kill ratio at least 0.8, nothing above low severityPROVEN

Gate CI on the strictness you want with --fail-on weak|unproven|refuted: only that verdict or worse exits non-zero. The exit codes are 0 PROVEN, 10 WEAK, 20 UNPROVEN, 30 REFUTED, 40 INCONCLUSIVE, 2 usage error, 1 internal error.

An integrity finding can be waived with a committed comment on or above the line, # counterproof: allow FR-IN-07 <reason>. A waiver added by the change under test is only a proposal, so an agent cannot excuse itself.

Profiles

ProfileProbesMutantsBaseline runsTarget time
fastRed-green, integrity, mutants, claim audit4290 s
full (default)All five835 min
paranoidAll five, oracle and mutants from two models16515 min

Configuration

counterproof init writes a counterproof.toml for the detected stack. The file is read from the base commit by default, so a change cannot loosen its own thresholds (--config-from worktree reads the file on disk). Unknown keys are rejected; flags override the file.

[run]
profile = "full"            # fast | full | paranoid
mode = "audit"              # audit | coach

[llm]
provider = "none"           # anthropic | openai | deepseek | ollama | none
budget_usd = 0.30

[mutants]
budget = 8
unproven_below = 0.5
proven_at_least = 0.8

[paths]
exclude = ["migrations/**"]  # never mutated, never sent to a provider

The full annotated file is counterproof.example.toml.

LLM providers and privacy

LLMs are optional. With provider = "none", the default, nothing leaves your machine and the mutants come from rules alone.

ProviderKeyDefault models
anthropicANTHROPIC_API_KEYclaude-sonnet-5-5, claude-haiku-5-5
deepseekDEEPSEEK_API_KEYdeepseek-v4-pro, deepseek-flash
openaiOPENAI_API_KEYset the models explicitly
ollamanone, localqwen2.5-coder:7b

Only the changed lines, their context, the task text and test snippets are sent. Secrets are redacted; .env files, lockfiles and paths.exclude are never sent. Every run has hard token, dollar and time limits, the certificate says which provider saw code, and answers are cached so re-running the same change is free. The blind oracle sees signatures, docstrings and public constants, never a function body, and prefers a model family other than the one that wrote the code.

Python and TypeScript projects

Python (pytest). Tests run in your interpreter: COUNTERPROOF_PYTHON, then the repository's .venv, then $VIRTUAL_ENV. Install pytest-cov there for coverage-based test selection.

TypeScript and JavaScript (Vitest, Jest). Counterproof uses the repository's own runner from node_modules (run npm ci first). Tests are selected from the changed test files and the test files that import a changed module. Install fast-check to fuzz surviving mutants.

Command reference

CommandWhat it does
verifyVerify a change and write a sealed evidence bundle
report RUN_IDRe-render a stored run as text, Markdown, JSON, HTML or SARIF
explain RUN_ID MUTANTA mutant's diff, the tests that ran and the missing test (for humans)
export-oracle RUN_IDList blind-oracle tests; --accept NAME copies one into your tests
initWrite counterproof.toml; --claude or --git-hook install integrations
mcpRun the stdio MCP server
eval CORPUS_DIRRun an evaluation corpus and write the results table
doctorCheck git, runners, providers and the run directory
gc --older-than 7dRemove old run directories