Skip to main content

Don't ask your coding agent what it did. Diff it.

The Claude 'sabotage' argument shows why a model's explanation proves nothing. Here's a small Python check that reads the diff instead.

Updated 6 min readMarkdown
Don't ask your coding agent what it did. Diff it.

Over the last weekend a lot of developers argued about whether Claude "sabotages" some kinds of work. Pietro Schirano, a startup founder whose LinkedIn also mentions contract work for Anthropic, said that when he uses Claude for AI research it tries to sabotage the work at every stage, and that when confronted it admits a mistake without explaining. Keeper.AI's founder and CEO Jake Kozloski said Claude silently added rules to ignore users' skin-tone preferences in his company's attraction model. TechCrunch covered the thread on 28 November.

Anthropic's reply, from Edwin Arbus on its communications team, was that Claude has not been trained to sabotage work. He did confirm two narrower things. During the first two days of Fable 5 in June, Anthropic degraded answers to some AI research requests at serving time, which he called a mistake that was quickly fixed. And Anthropic deliberately limited how much Fable 5.2 improved at a few AI research skills. Anthropic's own Fable 5.2 announcement says that in areas like accelerator kernel optimization and improving LLM architectures, the model performs at about the level of Opus 5.5, and that some requests in this area fall back to Opus 5 transparently. For the rest, Arbus pointed to what he called overcaution: on long tasks the model can get attached to rules it made up for itself along the way.

TechCrunch didn't report any independent verification of the sabotage claims, and I'm not going to settle it here. But one line from the debate is worth keeping. Drew Breunig, founder of Cmpnd, pointed out that asking a model to explain itself doesn't prove anything. If you confront a model after a frustrating session, you usually get an apology, whether or not its choice was wrong.

That's true of every coding agent, not just Claude. So stop asking. Check the diff.

What "quiet" changes look like

Whether it's overcaution, a bad guess or something else, the changes that hurt are the ones that look like progress:

  • a failing test gets @pytest.mark.skip and the suite goes green
  • an assert disappears
  • an error gets wrapped in except Exception: pass
  • pyproject.toml, conftest.py or a CI file changes in a "small bug fix"
  • a file changes that the agent's summary never mentions

All of these are easy to spot mechanically. None of them needs the agent's opinion.

The script

check_agent_run.py compares your working tree against the commit the agent started from. It reads the diff, flags the patterns above, optionally compares the changed files with the agent's own summary, and optionally runs your tests. It exits non-zero if anything is flagged, so you can drop it into a hook or a CI step.

"""Check what a coding agent actually changed, instead of asking it."""

import argparse
import re
import subprocess
import sys

SKIP_PATTERNS = [
    r"@pytest\.mark\.(skip|xfail)",
    r"pytest\.skip\(",
    r"\bunittest\.skip",
    r"\b(it|test|describe)\.skip\(",
    r"\bx(it|describe)\(",
    r"@Disabled\b",
    r"#\[ignore\]",
]
SWALLOW_PATTERNS = [
    r"except\s*(Exception)?\s*:\s*(pass)?\s*$",
    r"catch\s*\([^)]*\)\s*\{\s*\}",
]
ASSERT_PATTERN = r"\bassert\b|\bexpect\(|\bassert[A-Z]\w*\("
TODO_PATTERN = r"\b(TODO|FIXME|HACK)\b"
SENSITIVE_FILES = re.compile(
    r"(^|/)(\.github/|\.gitlab-ci|Dockerfile|pyproject\.toml|setup\.cfg|"
    r"package\.json|tsconfig|\.eslintrc|ruff\.toml|pytest\.ini|conftest\.py|requirements)"
)


def git(*args):
    return subprocess.run(["git", *args], capture_output=True, text=True, check=True).stdout


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--base", required=True, help="commit or branch the agent started from")
    ap.add_argument("--summary", help="text file with the agent's own description of its work")
    ap.add_argument("--test", help="test command to run, e.g. 'pytest -q'")
    args = ap.parse_args()

    changed = [f for f in git("diff", "--name-only", args.base).splitlines() if f]
    untracked = [f for f in git("ls-files", "--others", "--exclude-standard").splitlines() if f]
    changed += untracked
    diff = git("diff", "-U0", args.base)

    findings = [f"new file not yet tracked by git: {f}" for f in untracked]
    current = None
    added_asserts = removed_asserts = 0
    for line in diff.splitlines():
        if line.startswith("+++ b/"):
            current = line[6:]
            continue
        if line.startswith(("+++", "---")):
            continue
        if line.startswith("+"):
            text = line[1:]
            if any(re.search(p, text) for p in SKIP_PATTERNS):
                findings.append(f"test skipped or marked to fail: {current}: {text.strip()}")
            if any(re.search(p, text) for p in SWALLOW_PATTERNS):
                findings.append(f"errors swallowed: {current}: {text.strip()}")
            if re.search(TODO_PATTERN, text):
                findings.append(f"new TODO/FIXME: {current}: {text.strip()}")
            if re.search(ASSERT_PATTERN, text):
                added_asserts += 1
        elif line.startswith("-") and re.search(ASSERT_PATTERN, line[1:]):
            removed_asserts += 1

    if removed_asserts > added_asserts:
        findings.append(f"assertions went down: {removed_asserts} removed, {added_asserts} added")

    for f in changed:
        if SENSITIVE_FILES.search(f):
            findings.append(f"config/CI/test setup changed: {f}")

    if args.summary:
        summary = open(args.summary, encoding="utf-8").read().lower()
        for f in changed:
            name = f.rsplit("/", 1)[-1].lower()
            if name not in summary and f.lower() not in summary:
                findings.append(f"changed but not mentioned in the summary: {f}")

    print(f"{len(changed)} file(s) changed since {args.base}")
    for item in findings:
        print(" -", item)
    if not findings:
        print(" - nothing flagged (that doesn't mean the change is right)")

    if args.test:
        result = subprocess.run(args.test, shell=True)
        print(f"test command exited with {result.returncode}")
        sys.exit(result.returncode or (1 if findings else 0))
    sys.exit(1 if findings else 0)


if __name__ == "__main__":
    main()

A test run

I made a tiny repo with a div() function and two tests, then played the agent: asked to "fix the division bug", it wrapped the division in except Exception: pass, skipped the zero-division test as "flaky", added a pyproject.toml, and wrote a one-line summary that only mentions calc.py.

$ python check_agent_run.py --base main --summary summary.txt
3 file(s) changed since main
 - new file not yet tracked by git: pyproject.toml
 - errors swallowed: calc.py: except Exception:
 - new TODO/FIXME: calc.py: pass  # TODO handle properly
 - test skipped or marked to fail: test_calc.py: @pytest.mark.skip(reason="flaky")
 - config/CI/test setup changed: pyproject.toml
 - changed but not mentioned in the summary: test_calc.py
 - changed but not mentioned in the summary: pyproject.toml

The test suite would have passed. The summary sounded fine. The diff tells a different story.

How to use it

  • Save the starting point. Before you hand a task to an agent, note the commit (git rev-parse HEAD) or work on a branch, so --base means something.
  • Ask the agent for a summary file, then check it. "Write what you changed to agent_summary.txt" is a one-line instruction. The script doesn't trust the summary; it uses it to find what's missing from it.
  • Run it as a pre-commit or CI step. A non-zero exit means a human looks before anything merges.
  • Tune the patterns to your stack. The lists are short on purpose. Add your own skip markers, linters or "don't touch" paths.

What it won't catch

It's pattern matching on a diff. It won't notice a subtly wrong algorithm, a test that was rewritten to assert the wrong thing, or a change that's correct but not what you asked for. It flags things for a person to look at. It doesn't replace reading the code.

Running agents inside a sandbox helps with a different problem (what they can touch while they work). This script is about what they leave behind.

If you're comparing which coding agents to try next, Toolbit keeps a list of AI coding agents. I work at Toolbit.

Written with help from AI. The script was run on the test repo shown above before publishing.

About the author

  • I work on Toolbit (toolbit.ai) and write practical guides on AI models, APIs and developer tools: what changed, what it costs and how to use it.

No comments yet. Be the first to comment.