Loading lesson…
Git bisect is a precision tool — and AI agents are excellent bisecters. Learn to structure a bisect session with an agent, including auto-bisect with an AI-written test script.
A regression is a bug that didn't used to be there. Knowing when it appeared is more than half the fight. `git bisect` performs binary search through your history, asking you to mark each commit good or bad until it finds the first bad one. AI agents are surprisingly good at running this loop for you.
# 1. Start the bisect at a known-bad and a known-good commit git bisect start git bisect bad HEAD # current commit is broken git bisect good v2.4.0 # last release was fine # Git checks out a middle commit and waits for your verdict. # 2. Test it. Either run a script, run the app, or both. npm test -- --grep "login flow" # 3. Tell git what you found git bisect bad # or `good` if the test passed # 4. Repeat (5-7 iterations for ~100 commits) # 5. When done git bisect resetManual bisect, the textbook flow. AI changes step 2 and step 3 dramatically.| Step | Manual | With AI |
|---|---|---|
| Decide good vs bad | You run the test, eyeball output | Agent runs the test and reports verdict |
| Diagnose between commits | You diff the commits, read the changes | Agent summarizes commit diffs and risk areas |
| Write the repro test | You write it before bisecting | Agent generates a minimal repro from your bug report |
| Final root cause | You read the offending diff | Agent explains why that diff broke things |
`git bisect run` takes a script and runs it on each candidate commit. The script's exit code (0 = good, non-zero = bad) decides the verdict. Have an AI agent write the script for you, then unleash bisect on it.
# Step 1: ask the agent to write a minimal repro script # Prompt: "Write a bash script test-regression.sh that exits 0 # if our login redirects to /dashboard, and 1 if it 500s. # Use curl. No browser. Save the response." # Step 2: make sure the script works on HEAD (should fail) and on v2.4.0 (should pass) chmod +x test-regression.sh ./test-regression.sh; echo $? # 1 git checkout v2.4.0 ./test-regression.sh; echo $? # 0 # Step 3: run automated bisect git bisect start HEAD v2.4.0 git bisect run ./test-regression.sh # Git crawls the history, runs the script per commit, # and prints the first bad commit when done. ~30 seconds for 100 commits.The agent writes the test, git does the search. You drink coffee.# Useful prompt to a Claude Code session "I have a regression. Bug: <description>. Steps to reproduce: <steps>. 1. Find the last commit where this worked (assume it's tagged or in the last 200 commits). 2. Write a minimal bash script test-regression.sh that returns 0/1 based on whether the bug is present. 3. Validate the script works on HEAD (returns 1) and on the suspected good commit (returns 0). 4. Run `git bisect run ./test-regression.sh` and report the first bad commit. 5. Open that commit's diff and summarize, in 3 bullets, why this change introduced the bug."End-to-end automated regression hunt — works in any git project.Once the agent finds the first bad commit, the next prompt is gold: "Read the diff of <commit-hash>. Explain in plain English what changed, why someone made that change, and the most surgical fix that preserves the original intent." You get history, intent, and a fix in one turn.
Bisect is the closest thing software has to a time machine.
— Linus Torvalds, more or less
The big idea: bisect plus AI agent equals a near-automated regression detective. Spend your effort writing a tight repro script and let the machinery handle the search. The first-bad-commit you find is usually so small the fix is obvious.
8 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-coding-debug-bisecting-with-ai-creators
What is the main idea of "Bisecting Bugs With AI Help"?
Which concept is most central to "Bisecting Bugs With AI Help"?
Which use of AI fits this topic best?
What should a careful learner remember about "The repro script is the hard part"?
You want to use AI after this lesson. What is the safest next step?
How should AI output about git bisect be treated?
Name one way to verify an AI answer about git bisect.
Which action would help you apply "Bisecting Bugs With AI Help" responsibly?