Summary
The tech lead is the main session and the only agent that talks to me. It reviews the ticket, writes failing tests, runs the developer and QA until a PASS it can trust, saves lessons, and reports. It writes tests and never writes feature code. The file is about 9 KB and runs on Opus 5.5, pinned, with Fable as its advisor. In my team runs, time tracked QA rounds: 92 to 103 seconds with one round, 231 seconds after one INVALID bounce. This post does not measure whether any of it ships faster.
Previously in this series: Part 1, I replaced a long chat with four small Claude agents showed why one chat grades its own work, and how four small agents split the job. This part opens the tech lead file.
The test is a promise made before the code exists.
Most bad code starts as a bad ticket. A ticket that says "add a retry to the payout call" looks clear. Then someone asks how many times to retry. What if the first call went through? If nobody asks, the developer guesses, and the guess ships.
The tech lead asks those questions before any code exists. Fixing a sentence in a ticket is easier than fixing a merged change.
What I built
The input is a tech design, a PRD, or a ticket, as a ticket ID, a URL, or pasted text. The agent reads it, then reads the code it touches.
The file lays out six steps: worktree, review, split, tests, build loop, learn and report. Each step has one owner and one output, which keeps the loop from turning back into a long chat.
The file also caps how many agents run at once. At most 3 developers, each on its own subticket and worktree. At most 1 of anything else. It may spawn only the agents I defined (developer, qa, documenter, and two read-only search agents), never a general-purpose one.
Name the steps and the agent limits in your own file. A step without an owner is the step that gets skipped.
Every ticket gets its own worktree
Each ticket gets its own git worktree, never the main checkout.
A worktree is a second copy of the repo on its own branch, in its own folder. Think of a separate desk for each job, so papers from one job never land in another's pile.
First it pulls. It runs git fetch origin and builds the worktree from the fresh remote base, never from a stale local branch:
git fetch origin git worktree add ../<repo>-<ticket-id> -b <ticket-branch> origin/<base> That rule came from a real conflict. One PR clashed with the main branch because another ticket had landed in the meantime.
Before creating one, it checks git worktree list for a worktree that already belongs to this ticket. It reuses one only when no other agent is working in it, and then pulls and merges the base in before editing anything. If it cannot tell whether the worktree is busy, it asks me.
The worktree path goes into every developer, QA and documenter brief. The tech lead never runs migrations and never touches uncommitted changes in my main checkout.
Put the worktree path in every brief. An agent that has to search for the folder will eventually edit the wrong one.
The review finds the gap before code does
Before reading the ticket, the tech lead checks its sub-tickets. For a Linear ID it lists the children in every status, plus open and merged PRs and branches for each. If a child already covers the work, it works under that child's ID. It never opens a PR under a parent ticket. This rule exists because one PR went out under the parent instead of its sub-ticket and had to be closed.
Then it reports three things:
- Gaps: missing acceptance criteria, unclear edge cases, conflicts with existing code.
- Scope cuts: anything the ticket asks for that does not need to exist.
- Size: small (one change, one PR) or large (several independent pieces).
The scope-cut line comes from ponytail. The best code is code nobody wrote.
A review for the retry ticket looks like this:
Gap: ticket says "retry on failure" but not which errors. 4xx should not retry. Scope cut: "make retry count configurable". Nobody asked for it. Hardcode 3. Size: small. One service, one function, one PR. Ask for the review before the split. A gap found here costs a sentence. The same gap found during QA costs a rewrite.
A large ticket splits only when the pieces stand alone
For a large ticket, the tech lead writes one subticket per independent piece, each with a title, acceptance criteria, and the files it touches. It shows me the list and waits. Nothing goes into the tracker until I approve.
The test is independence. If piece B cannot be tested until piece A is merged, they are one ticket with two steps.
Write that test into the file: if B needs A merged before its tests can pass, the split is wrong.
The tests come before the code
Picture a teacher who writes the exam and also takes it. The exam matches what the teacher already knows. Tests written after the code, by the same author, do the same.
Here the tech lead writes the tests first. Its file says, "You plan and write the tests. You do not write the feature code."
The rules:
- Write failing tests that encode the acceptance criteria.
- Use the repo's existing test framework, layout and helpers.
- One test per behavior.
- Cover the edge cases found in the review.
- When a criterion names a range (a 4xx, a 5xx), test at least two values from it.
That last rule is about cost. QA treats one value from a range as a missing test and returns INVALID. Each rejection costs a full round, and a round is not cheap: 231 seconds after one bounce against about 100 without.
For the retry ticket:
describe('payout retry', () => { it.each([502, 503])('retries a %d up to 3 times', async (status) => { /* ... */ }); it.each([400, 404])('does not retry a %d', async (status) => { /* ... */ }); it('returns the first success without extra calls', async () => { /* ... */ }); }); Read the test list back against the ticket line by line. Any criterion that says "a 4xx" and has one status code under it will bounce.
A red test has to fail for the right reason
The tech lead runs the tests and checks they fail for the right reason: missing behavior, not a typo or a broken import.
A test that fails on Cannot find module './retry' says nothing about retry logic. Fix the import and it may pass or fail for some new reason, and nobody knows whether it ever checked the real behavior.
The brief that goes with the tests has the ticket, the test file paths, the exact test command, the files the developer may touch, and the worktree path.
The developer does not run that command. It reads the tests to learn what they expect, builds the change, and hands the command to QA, which runs it. When a test turns out wrong, the developer may not touch it. QA returns INVALID and the tech lead fixes it. Part 4 covers this.
Read the failure message on every new test before the developer gets it. If the message names an import or a typo, the test is not ready.
A PASS counts only if nothing changed after it
The tech lead runs this for each ticket:
- Spawn
developer(Sonnet) with the brief. The developer implements every criterion, checksgit difffor leftoverTODOs or stubs, then spawnsqa(Haiku), one at a time. It fixes anyFAILitself. - The developer reports back one of three ways:
-
DONE: its last QA run wasPASS, and it pastes QA's full report. -
BLOCKED: the same cause failed twice, or 3 rounds passed. The tech lead asks the advisor, then sends guidance to the same developer. After 2BLOCKEDreports on one ticket, it stops and tells me. -
INVALID: QA says the tests are wrong. The tech lead fixes them and starts again.
-
- Validate. If the developer pasted QA's full
PASSand nothing in the worktree changed after it, thatPASSis the validation. QA is a separate agent with no edit tools, so the developer cannot touch its verdict. If anything changed, including a test the tech lead fixed, the tech lead runsqaitself.
An earlier version always ran QA a second time. Now the second run happens only when something moved.
Why write down "anything changed"? Because in 2 of 3 earlier team runs, the tech lead added tests after QA's last verdict and did not run QA again. The PASS it reported covered code and tests that no longer matched the worktree.
QA itself spawns nothing. Before it returns PASS, it re-reads the ticket, the tests and the diff once more as a second reviewer would.
Count your QA rounds per ticket. If time follows rounds, the cheapest fix is a test that does not bounce.
Memory turns one run's mistake into the next run's rule
The tech lead reads its project memory before step 1. After each ticket it writes down what would have saved time:
- Every
FAILorINVALIDround, with the cause and one rule that prevents it. Example: "tests insrc/**needTZ=UTC, else date asserts fail." - My corrections to its review, split, or tests.
- Repo facts it had to look up, like the test command and helpers.
One lesson per line, with the date. Update a lesson instead of adding a near copy. Keep MEMORY.md under 150 lines.
Open your memory file after the next failed round and add the rule, not the story.
The report is one short message
The last step ends each ticket. The tech lead tells me in plain words what changed (file list), the test results, anything skipped, any risk, and the lessons saved. Then I open the worktree to review.
Keep the report to one screen. If it needs a table of contents, the ticket was too large for one run.
The advisor sits at three moments
The tech lead runs on Opus 5.5, pinned so a change of session model does not change who plans. It asks its Fable advisor at three moments: before the plan locks, when the developer is stuck, and before a ticket is called done. Part 6 covers them.
The file also says never to guess on money, auth, or data loss. A wrong guess on a button label costs a minute. A wrong guess on who may move money is an incident.
Write the three advisor moments and the never-guess list on the same page.
When to use the tech lead, and when not to
Use it for a real ticket with acceptance criteria: a feature, a behavior change, or a bug fix that needs a test. It earns its cost in auth, money, RBAC or data, and on large tickets that need a split.
Skip it for one-line fixes, renames, config tweaks, questions, spikes, unclear tickets, and urgent hotfixes. A ticket takes about 15 to 20 minutes and a few hundred thousand tokens.
If a ticket matches more than one skip rule, use a normal session.
Results: six steps, one owner each
Step
Output
Who checks it
Worktree
One folder and branch per ticket, from fresh origin/<base>
Tech lead
Review
Sub-ticket check, gaps, scope cuts, size
Tech lead, then me for gaps
Split
Independent subtickets
Me, before the tracker
Tests
Failing tests, two values per range
Tech lead, then QA
Build loop
Green code and a PASS with nothing changed after it
Developer's QA, or the tech lead's QA if anything changed
Learn and report
MEMORY.md lines and one message
Me
The table is the design, not a measurement. The one number I have is time against QA rounds: 92 to 103 seconds for one round, 231 seconds after an INVALID.
Print your own version and put it beside the agent file. The blank owners are the steps you have not built yet.
What this does not prove
I cannot say this loop catches a fixed share of defects or saves a number of hours. The timings come from a few team runs on my own tickets, not a benchmark.
Writing tests first does not guarantee good tests. A test can encode the wrong criterion and pass for months. A wrong ticket still produces a confident wrong test.
Trusting the developer's PASS rests on one fact: QA has no edit tools. If your QA agent can edit files, run it again yourself.
Memory can carry a wrong lesson. Review the file and delete lessons that stop being true.
If a ticket is small enough that the table feels heavy, run a single agent and keep the review and QA steps.
Try it
- Write the six steps into your tech lead file, one output per step.
- Add the worktree rule with
git fetch originfirst, and the brief format. - Add the test-first rule, the two-values-per-range rule, and the "does not write feature code" line.
- Accept the developer's pasted
PASSonly if nothing changed after it. Otherwise run QA again. - Cap the loop at 3 developer rounds, 2
BLOCKEDreports, and 3 developers at once. - Add a
MEMORY.mdwith the 150-line limit. - Run one small ticket and count the QA rounds.
I build payment and agent systems at work; these agent files come from my own use, not a customer setup.
When your agent fixes a test after QA said PASS, does anything in your setup make it run QA again?
References
- Claude Code advisor docs: https://code.claude.com/docs/en/advisor


