Last week your app worked. This morning it doesn't, and your coding agent has pushed twenty-something commits since then. Ask it to "figure out what broke" and you'll pay for an hour of confident, wrong guesses across your whole repo.
There's a command built into Git that answers this exactly: git bisect. You give it one commit you know was good and one you know is bad. It checks out a commit in the middle, you tell it whether that one works, and it halves what's left every time. Twenty commits or two thousand, you usually land on the culprit in a handful of steps. Then your agent gets one small diff to fix, with a failing check attached, instead of a vague crime scene.
When bisect fits
Bisect needs three things, and they're all about you, not the tool. You need a known-good commit: something that worked, and a rough idea of when. You need a known-bad commit: today's HEAD will do. And you need a quick way to check one commit: a build that fails, a script that errors, a page that breaks when you click the thing.
If you can't describe the bug as a check, bisect has nothing to chew on, so get that part right first. We have a whole post on making your agent reproduce a bug before it fixes it; a reliable repro is half of bisect already done.
How it works in plain words
Say there are 64 commits between good and bad. One check on the middle commit cuts it to 32, the next to 16, then 8, 4, 2, 1. Six checks pin down one bad commit, and the math only grows slowly: double the commits, add one check. It's a binary search over your history, nothing fancier, and the official docs describe the same loop in Git's own words.
Two practical notes before you start. Bisect assumes the bug appeared once and everything before it was fine. And if a commit can't be tested at all, you don't have to guess about it; more on that below.
The manual run, once, by hand
Do it manually the first time so you trust what's happening. Four commands and a few test rounds:
git bisect start
git bisect bad # HEAD is broken
git bisect good 1a2b3c4 # this one worked
# git checks out a commit in between. Test it, then:
git bisect good # works here
git bisect bad # still broken here
# repeat until git prints: abc1234 is the first bad commit
git bisect reset # put your working tree back
Don't skip git bisect reset. It returns you to the branch and commit you started on. Walk away mid-bisect and your checkout is sitting on some random historical commit, which is its own confusing afternoon.
Automate it with a check script
The manual loop is fine for five steps and miserable for fifteen. So turn your test into a script that exits 0 when the commit is good and 1 when it's broken, and let Git drive:
#!/usr/bin/env bash
# check.sh: 0 = good, 1 = broken, 125 = can't test here
npm install --silent >/dev/null 2>&1 || exit 125
npm run build >/dev/null 2>&1 || exit 1
node check-checkout.js || exit 1
Then run one command and walk away:
git bisect run ./check.sh
Git checks out each candidate, runs your script, reads the exit code, and works through the whole range without you. Exit code 125 is the escape hatch for commits you can't test, like a build that never compiled in that era; the docs list what each code means.
One move here changes the whole outcome, and it costs nothing: have your coding agent write the check script before you ask it for any fix. Describing a failure as a pass/fail test is exactly what agents are good at, and it's exactly what bisect needs. Ask for the fix first and you get a nervous rewrite. Ask for the test first and you get a target.
Hand the agent the culprit
When bisect stops, you hold three things, and none of them is "it's broken, please look at everything":
- The commit:
git show <sha>, the exact diff that introduced the bug. - The failing check: your script and its output at that commit.
- The constraint: smallest possible change.
That third one matters more than it sounds. Left loose, agents refactor while they fix, and a tidy-looking rewrite of half a module is a great way to produce regression number two.
Copy-paste prompt
The commit below introduced a regression. check.sh fails on it; output:
<paste the failing output>
Fix the regression with the smallest possible change to this diff.
Do not refactor, rename, or "clean up" anything else.
Keep check.sh in the repo as a test. Run it and confirm it passes
before you commit.
That prompt plus a one-commit diff is a task any agent can finish in minutes.
If you're setting up an agent harness for the first time, you can try the zcode agent harness free. And if this workflow becomes your daily driver, there's 10% off GLM coding plans.
Make your next bisect cheap
A checklist worth keeping next to your terminal:
BISECT-FRIENDLY HABITS
[ ] Commit small and often; each commit does one thing
[ ] Keep the build green; a broken build poisons the whole range
[ ] Keep one script that checks the thing users actually touch
[ ] Note the last-known-good commit whenever a release works
[ ] Always run git bisect reset when you're done
That's the whole discipline. Small commits shrink the blast radius, and a standing check script means the next "it broke" costs minutes instead of an evening.
Bisect turns "the app is broken and nobody knows why" into "commit abc1234 did it, here's the diff." Your agent is still the one doing the fixing. You're just pointing it at the right door.
There's more on our blog if you want to keep going.
If this saved you an afternoon, a tip on this post is a nice way to say so.






Latest comments
0