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.
| # | Rule | When | Verdict |
|---|---|---|---|
| 1 | R-INC-BUILD | Base or head cannot collect tests, no selected tests, or the budget ran out first | INCONCLUSIVE |
| 2 | R-INC-FLAKY | More than 20% of selected tests are flaky | INCONCLUSIVE |
| 3 | R-REF-CLAIM | The agent claimed passing tests that fail, or claimed a run it never made while the baseline fails | REFUTED |
| 4 | R-INC-HEADRED | Selected tests fail on the change | INCONCLUSIVE |
| 5 | R-REF-INTEGRITY | A high-severity integrity finding: assertion removed, test deleted, skip added, assertion neutralised, test inputs special-cased, test detection | REFUTED |
| 6 | R-UNP-OVERFIT | The overfit mutant (the change minus its general logic) survives | UNPROVEN |
| 7 | R-UNP-NOREDGREEN | A bug fix or feature whose tests also pass on the old code, with a kill ratio below 0.8 | UNPROVEN |
| 8 | R-UNP-WEAKTESTS | Kill ratio below 0.5 over at least 3 valid mutants | UNPROVEN |
| 9 | R-WEAK-SURVIVOR | A high-plausibility survivor, or a kill ratio in [0.5, 0.8) | WEAK |
| 10 | R-WEAK-APIONLY | Tests fail on the old code only because the API is missing, and some mutant survives | WEAK |
| 11 | R-WEAK-ORACLE | The blind oracle found a likely bug (confident triage) | WEAK |
| 12 | R-WEAK-MEDIUM | A medium-severity integrity or claim finding | WEAK |
| 13 | R-WEAK-FEWMUTANTS | Fewer than 3 valid mutants could be generated | WEAK |
| 14 | R-PROVEN | Otherwise: strong red-green, kill ratio at least 0.8, nothing above low severity | PROVEN |
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
| Profile | Probes | Mutants | Baseline runs | Target time |
|---|---|---|---|---|
fast | Red-green, integrity, mutants, claim audit | 4 | 2 | 90 s |
full (default) | All five | 8 | 3 | 5 min |
paranoid | All five, oracle and mutants from two models | 16 | 5 | 15 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.
| Provider | Key | Default models |
|---|---|---|
anthropic | ANTHROPIC_API_KEY | claude-sonnet-5-5, claude-haiku-5-5 |
deepseek | DEEPSEEK_API_KEY | deepseek-v4-pro, deepseek-flash |
openai | OPENAI_API_KEY | set the models explicitly |
ollama | none, local | qwen2.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
| Command | What it does |
|---|---|
verify | Verify a change and write a sealed evidence bundle |
report RUN_ID | Re-render a stored run as text, Markdown, JSON, HTML or SARIF |
explain RUN_ID MUTANT | A mutant's diff, the tests that ran and the missing test (for humans) |
export-oracle RUN_ID | List blind-oracle tests; --accept NAME copies one into your tests |
init | Write counterproof.toml; --claude or --git-hook install integrations |
mcp | Run the stdio MCP server |
eval CORPUS_DIR | Run an evaluation corpus and write the results table |
doctor | Check git, runners, providers and the run directory |
gc --older-than 7d | Remove old run directories |