Product case study · November 13, 2026
Claude Code and Git Bisect: Find the Commit That Broke It
Turn a bug report into a small executable check with Claude Code, validate both endpoints, and use Git bisect to locate the first failing commit.

Ask the agent to help define the failure, then make Git search with a reviewed check. A plausible explanation is weaker than a reproducible boundary.
The most suspicious commit message can be completely innocent. When a feature worked last week and fails today, I would rather ask an agent for a tiny executable check than a theory about which developer broke it.
That check gives git bisect something useful to search with. Claude helps translate the bug report into code; Git tries historical revisions until it isolates the transition. The interesting work is deciding what counts as failure.
This exercise uses a fictional shipping rule: an order of exactly 50 units qualifies for free shipping. You need Bash, Git and Python 3. The optional agent step needs an installed, authenticated Claude Code. Sources checked November 13, 2026. The local fixture and reference check below were tested; an authenticated Claude session was not. Agent responses are yours to inspect, not reported results.
Make a history worth searching
Run the blocks in one Bash terminal, without enabling set -e: some commands deliberately return a failure status. Everything lives in a new temporary directory.
bisect_lab=$(mktemp -d /tmp/agent-bisect.XXXXXX)
mkdir "$bisect_lab/project"
cd "$bisect_lab/project"
git init -q
git config user.name 'Practice Author'
git config user.email 'practice@example.invalid'
git config commit.gpgsign false
git config core.hooksPath /dev/null
printf 'def free_shipping(total):\n return total >= 50\n' > shipping.py
git add shipping.py
git commit -qm 'Add shipping rule'
git tag lab-good
printf 'Shipping calculator practice\n' > README.md
git add README.md
git commit -qm 'Describe calculator'
printf 'def free_shipping(total):\n return total > 50\n' > shipping.py
git add shipping.py
git commit -qm 'Adjust shipping comparison'
printf 'Use whole-number totals in this exercise.\n' >> README.md
git add README.md
git commit -qm 'Clarify example inputs'
git tag lab-bad
The last commit only edits documentation. The regression is earlier: >= became >. This gives us a known answer against which to judge the search.
Ask Claude for the check, before asking for a fix
Start claude from the practice project. The CLI reference documents that interactive entry point. Paste this task:
This is a synthetic shipping-rule exercise. Read shipping.py only.
The requirement is: free_shipping(50) must return the Boolean True.
Return a Python 3 checker as text; do not edit files or fix the function.
The checker will run with a historical project as its working directory.
Read and execute that directory's shipping.py, then call free_shipping(50).
Exit 0 only for True; exit 1 for a different returned value.
Exit 125 if the file cannot load or the function cannot be called.
Use only the standard library. Print the observed value or the reason
it cannot be tested. Do not inspect Git history or guess the bad commit.
Anthropic’s testing workflow recommends specifying the behavior you want verified. Here, that means the exact input, return value and process status. “Check shipping” leaves too much room for a test that never exercises the boundary.
Review the answer before executing it. A checker that reads a fixed copy of the function will test the same version every time. A checker that repairs the function will erase the very evidence you need. The instruction to avoid edits is a task boundary, not a technical sandbox; review any requested tool approval.
Exit Claude before continuing. For a reproducible baseline, use this authored reference checker, saved outside the repository so historical checkouts cannot replace it:
cat > "$bisect_lab/check.py" <<'PY'
import runpy
import sys
try:
module = runpy.run_path("shipping.py")
actual = module["free_shipping"](50)
except Exception as exc:
print(f"Cannot test: {type(exc).__name__}: {exc}")
sys.exit(125)
print(f"free_shipping(50) = {actual!r}; expected True")
sys.exit(0 if actual is True else 1)
PY
This executes the checked-out Python file. It is appropriate for this synthetic fixture; do not point it at unreviewed third-party code.
Prove the endpoints disagree
A test that always fails can still produce a confident-looking answer. Check it against both ends first:
git switch --detach lab-good
python3 "$bisect_lab/check.py"
printf 'Good revision exit: %s\n' "$?"
git switch --detach lab-bad
python3 "$bisect_lab/check.py"
printf 'Bad revision exit: %s\n' "$?"
Expect True and exit 0, then False and exit 1. If you see anything else, stop and repair the checker or fixture before searching. If you use Claude’s version instead, it must pass this same rehearsal.
Let Git narrow the history
The Git bisect manual defines run statuses: 0 means good, 1 through 127 mean bad except 125, which skips an untestable revision. Other statuses abort. A missing dependency must not masquerade as the shipping bug.
git bisect start lab-bad lab-good
git bisect run python3 "$bisect_lab/check.py"
git bisect log > "$bisect_lab/bisect.log"
git show --format=fuller --stat refs/bisect/bad
git show refs/bisect/bad -- shipping.py
git bisect reset
For this fixture, the reported first bad commit should be Adjust shipping comparison. Its patch removes >= 50 and adds > 50. Commit hashes vary because your local commit metadata differs. The saved log remains outside the project after git bisect reset returns you to the starting revision.
The search identifies a transition for this particular check. It does not prove that the whole commit is wrong or that reverting it is the best fix. In a real change, the same commit might contain a useful feature and a broken edge case.
When the answer is ambiguous
| What you observe | What to do next |
|---|---|
| Both endpoints return 0 | Tighten the reproduction; the check does not capture the reported bug. |
| Both endpoints return 1 | Confirm the requirement and the supposedly good revision. |
| A revision returns 125 | Inspect why it cannot run; skipped revisions can prevent a unique answer. |
| Repeated runs disagree | Remove timing, network or random inputs before trusting the search. |
| The bug disappeared and returned in the interval | Narrow to one known transition; a single search is not a complete history of recurring failures. |
For your own project, work in a separate clean checkout, preserve current work, and establish a repeatable build environment for historical commits. Keep the checker independent of files that disappear as you move backward.
My preferred handoff to an agent is now small: the failing input, the identified patch, and a request for the smallest correction that preserves the intended feature. Keep the regression check when you make that fix. It has already earned its place.
Sources
Checked November 13, 2026:
- Git: git bisect — search commands, exit statuses, skipped revisions and reset behavior.
- Anthropic: common workflows — debugging and behavior-specific test prompts.
- Anthropic: CLI reference — starting an interactive Claude Code session.
Put this to work
Separate writing a useful test from locating the change that first fails it.
Try
Run a reviewed Python check across a small Git history with git bisect run.
Prove it worked
Save the bisect log and show the identified commit changes the failing behavior.
Keep in view
- Build a disposable history with one deliberately broken change.
- Give Claude a precise contract for a regression check.
- Verify good and bad revisions before automating the search.