The Brains, the Good, the Bad and the Ugly: When SRP Meets GBU
2026-08-09 · [ leer en español ]
The previous article had a small limitation that I didn't notice until I started using the pattern more often, on more complex projects.
In this one we're going to fix it by adding a new character at the start of the pattern, and we'll see how to apply it to a real case with Claude Code. So here begins a new adventure in the Wild West of software.
Enter the Brains

Every group has one. The guy who leans back the moment a problem shows up and says "well, obviously, what you should've done is..." Mr. Know-It-All. (People usually call him something ruder, but you get the idea.)
That's exactly what the pattern was missing. And no, I don't mean the smart-a... (I can see you coming). I mean the Brains. Several of you pointed out the same thing after the first article: why did the Good have to do two different jobs, planning and programming?
And yes, the original pattern skipped right over the S in SOLID (that link's in Spanish), which, let's remember, doesn't only apply to raw code.
So the sheriff's office was missing someone who sits quietly rocking in his chair, watching everything:
- 🥸 The Brains: An agent that specializes in understanding the problem and turning it into an implementation plan. He doesn't write a single line of code. He only thinks and organizes the work. He's the one who analyzes the issue and shapes the plan the Good will start from.
The beauty of this upgrade is that now each agent has exactly one responsibility: the Brains thinks, the Good implements, the Ugly reviews and the Bad tries to break the result.
Following the template from the previous article, two things change:
🥸 The Brains (the thinker and strategist)
He's the quiet type who never draws first. When a new case comes in, he shuts himself in the sheriff's office with all the reports, studies the situation and comes out with a clear plan, so the Good doesn't improvise or wander into a dead end. He never writes a line of code: his job is done once the trail is clearly marked.
- Input: The functional spec, the technical spec and the current state of the project.
- Output: An incremental execution plan broken into small steps.
His short prompt could look something like this:
"You are the Brains. You are a Senior Software Architect who specializes in turning a spec into an incremental implementation plan. Read the functional and technical spec, analyze the current state of the project and produce a plan broken into small steps. Do not write code. Your only output must be the plan."
🤠 The Good (the optimistic developer)
You already know he's the agent in charge of the implementation. Now he takes the next step in the plan the Brains prepared and implements it, following the project's functional and technical spec. He no longer has to figure out what to do, just follow the trail.
- Input: The plan, the functional spec and the technical spec.
- Output: Production code, tests and changes ready for review.
His new short prompt:
"You are the Good. A Senior developer who specializes in the project's architecture and conventions. Read the next pending step in the PLAN and carry it out, following the functional and technical spec. Do not implement later steps or add features that are not described."
These are short sample prompts to give you the idea. In the hands-on part of the article you'll see much more complete prompts, tailored to a real workflow.
The law of the town: the pattern, clean
Before we get down in the mud with more complex examples, let's look at the whole flow:
🥸 The Brains (only once)
analyzes the task and the project and writes the plan:
Task + Context + Small steps with checkboxes
For each pending step in the plan:
🤠 The Good implements the step and leaves the tests green
│
🌵 The Bad attacks the implementation: if he breaks it, the Good
│ fixes it and the Bad verifies (with a cap on rounds)
│
👺 The Ugly audits it against the plan: if there are deviations,
│ the Good fixes them and the Ugly verifies (with a cap on rounds)
│
Step approved ──► next step
And these are the rules the pattern should follow, however you implement it:
- Each agent has exactly one responsibility. One thinks, one builds, one sabotages and one audits. Nobody's moonlighting.
- The plan is the only shared memory. The Brains is the only one who reads the project docs (
CLAUDE.md, README, team agreements). He boils everything relevant down into the plan's "Context" section, and the other agents work only with the plan and the code. That means less rereading and fewer tokens spent (and tokens are priced like gold nuggets these days). - The Ugly and the Bad don't know how the code was implemented. In the first version, the same model played all three characters in the same session. Splitting the prompts made it less of a people-pleaser, but the auditor "remembered" what the Good had just written, with all the bias that comes with it, since nobody in their right mind fails their own exam. The Bad and the Ugly have to start from scratch and judge only what's on disk. For me, this is the most important rule of all.
- Stabilize the behavior first, refactor after. In the first article the order was Ugly → Bad. Once I started using it, I found it works better the other way around: the Bad's adversarial tests become part of the suite, so when the Ugly asks for style tweaks, those tests are already standing guard and the Good can adjust names and structure without fear. With the old order, every style fix meant planning a whole new attack.
- Verdicts with an exact token, loops with a cap. The verifiers don't narrate their process or list what's fine: they answer with the exact approval token or with a report of what's failing. Nothing else. Demanding literally
SOBREVIVIO_AL_MALO("survived the Bad") andAPROBADO_POR_EL_FEO("approved by the Ugly") rules out the classic "I approve, although I'd suggest...", which would cost the Sheriff more inference and, a lot of the time, stop the run to ask you what to do. That's also why each verifier gets a maximum number of rounds per step: give an LLM a fuzzy stopping condition and it can go around in circles forever.
As you can see, there aren't hundreds of rules to learn, just five simple ones. Also notice there's nothing about which tool runs it, how it's launched, which model each agent uses, who commits or when, or what exactly happens when a verifier runs out of rounds. All of that depends on who implements it and what they need.
The roles don't come with an actor
Something else to keep in mind: nowhere did we say the same tool has to play every character. Or even that they all have to be AI. The pattern defines the plot each role follows in this western, but the casting is up to you.
- 🥸 The Brains can be a human. An architect or a tech lead who writes the plan by hand, or who corrects the draft the AI suggests. For very large tasks that's worth considering, since the plan is the cheapest moment in the whole movie to bring in human judgment. And even if an AI plays the part, there are tools made to help it: the spec kits sprouting up around SDD exist precisely to refine specs before anyone writes a line of code.
- 🤠 The Good is the natural role for an LLM, because that's where its speed pays off the most. But if a human plays him, that's fine too: it just becomes good old-fashioned development with automated verifiers standing guard.
- 🌵 The Bad has veteran actors who've never heard of an LLM. Fuzzers (AFL++, libFuzzer) have been breaking implementations with garbage input for decades without asking anyone's permission. Property-based testing (Hypothesis in Python, fast-check in JavaScript, and so on) systematically generates the nulls, empties and extreme sizes in his arsenal. And if you want tools for the concurrency and load angle, there's k6 or JMeter.
- 👺 At a lot of companies, the Ugly's last name is Sonar. The SonarQube quality gate is a binary verdict, passed or failed, which is basically an
APROBADO_POR_EL_FEO. The same casting agency also sends over linters in strict mode, Semgrep, ArchUnit (which audits architecture rules as if they were tests)... and the classic actor for the part: the good old human pull request reviewer. - ⭐ Even the Sheriff has a stunt double. A CI pipeline (Jenkins, GitHub Actions and friends) can end up orchestrating the whole flow based on each character's results, as long as those results are reasonably deterministic.
Looking at the list, you'll notice these are just the roles that have always existed: architect, developer, QA, reviewer. All we did was give this automation a name, but it's still the same cast every serious team already had.
One advantage of using some of these tools for the roles is that the actors who don't use AI are deterministic. Same input, same verdict, every time, which saves us hallucinations and tokens. And a role doesn't have to be played by a single actor, either: nothing stops you from casting a Bad who's really a whole gang, an LLM agent, a fuzzer and a property-based suite all working together, or an Ugly who's Sonar plus an agent that interprets whatever falls below a warning. In those cases, the role's verdict is the verdict of the group, so the output is still SOBREVIVIO_AL_MALO as long as nobody manages to break anything.
In the end, the pattern only asks three things of each role: that it exists, that it's isolated from whoever implements and that it delivers a clear verdict.
After all that, let's look at my personal cast for working with Claude Code. Every role is played by an LLM agent, with a Sheriff orchestrating. So this is a reference implementation, set up for one particular workflow. Feel free to copy it if it fits, but you're completely free to tweak every step. Also, I wrote the prompts in Spanish, so that none of the tricky parts are left open to interpretation because of a translation slip on my end. Like everything else here, write yours in whatever language you prefer.
Welcome to Code City: implementing the GBU pattern in Claude Code
Now it's time to get off the horse. The pattern lives in a handful of markdown files you can copy into any project. You'll find them all in the gbu repository.
your-project/
└── .claude/
├── agents/ # feo.md, malo.md (the isolated subagents)
└── commands/ # gbu.md, listo.md, bueno.md, feo.md, malo.md
There's nothing to compile or configure: Claude Code automatically loads the files in commands/ as slash commands and the ones in agents/ as subagents. The commands keep their Spanish names (listo is the Brains, bueno the Good, malo the Bad and feo the Ugly), and the cast ends up like this:
| Character | Command | Role | How it runs |
|---|---|---|---|
| ⭐ The Sheriff | /gbu |
Orchestrates the whole pattern | Main agent |
| 🥸 The Brains | /listo |
Turns the task into an incremental plan (PLAN.md) |
Role the Sheriff takes on, only at the start |
| 🤠 The Good | /bueno |
Implements the next step and leaves the tests green | Role the Sheriff takes on, with full context |
| 🌵 The Bad | /malo |
Adversarial QA: tries to break the implementation | Isolated subagent, starts from scratch |
| 👺 The Ugly | /feo |
Strict auditor: rejects any deviation | Isolated subagent, starts from scratch |
The Brains and the Good are roles the Sheriff himself plays, with all the context of the session: whoever implements needs to know everything. But the Bad and the Ugly are subagents that start without that context: they haven't seen the implementation or the conversation that produced it. All they have is the plan and the code on disk.
The central artifact is PLAN.md, with four sections: Task (the expected behavior), Context (the project conventions that shape the implementation), Execution mode (more on that in a second) and Steps (checkboxes). A checked box means that step is done.
I added the Execution mode section, which the pattern doesn't say anything about, because depending on the case I sometimes trust an automatic commit (test projects, mini PoCs and so on), and other times I'd rather take a look, even a quick one, at everything that was generated before pushing it. So the first time /gbu starts a plan, the Sheriff asks you what to do when each step closes.
The flow, phase by phase
PHASE 0 (only once)
🥸 The Brains analyzes the project and the team agreements
and writes PLAN.md: Task + Context + Steps with checkboxes
⭐ The Sheriff asks you for the Execution mode and notes it in the plan
For each pending step in the plan:
PHASE 1 — 🤠 The Good implements the step and leaves the suite green
│
│ (shortcut: if the diff only has comments, tests or automatic
│ formatting, the Sheriff skips the phases that add nothing)
│
PHASE 2 — 🌵 The Bad (subagent) attacks the changes: nulls, limits,
│ corrupt data, concurrency... His tests stay in the
│ suite as regression tests.
│ ├─ SOBREVIVIO_AL_MALO ──► carry on
│ ├─ failure report ──► the Good fixes everything in one
│ │ pass and the Bad verifies (max. 3 runs)
│ └─ 3 runs without surviving ──► whatever's left is
│ logged as technical debt and the step carries on
│
PHASE 3 — 👺 The Ugly (subagent) audits against the plan and conventions
│ ├─ APROBADO_POR_EL_FEO ──► carry on
│ └─ Deviation Report ──► the Good fixes it and the Ugly
│ verifies (max. 3 runs)
│
End of step — box checked in PLAN.md, then whatever the
Execution mode says: commit, push or stay staged
When no steps are left: COMPLETED SUCCESSFULLY
Each run of /gbu moves the plan forward step by step, and a step only closes once the Bad has said exactly SOBREVIVIO_AL_MALO (or whatever he couldn't break has been logged as debt, more on that later) and then the Ugly has said exactly APROBADO_POR_EL_FEO. If the Ugly rejects the work three times in a row, the Sheriff doesn't keep pushing blindly: he stops and asks you for help.
Day-to-day flows
With all the pieces on the table, let's see which hands you can play.
First run. There's no plan yet, so you pass the task to the command:
claude
> /gbu We need a website that converts SI units to non-SI units...
The text after the command reaches the prompt through the $ARGUMENTS variable, which Claude Code fills in automatically. Since there's no PLAN.md, the Sheriff takes on the Brains, generates the plan, asks you for the Execution mode and chains the first Good → Bad → Ugly cycle. From then on, the Brains leaves the scene.
$ARGUMENTS takes any way of pointing at the task:
- Free text:
/gbu Add a dark mode to the website - A spec file:
/gbu Implement the spec in specs/converter.md. This plugs straight into the SDD approach from From Vibe Coding Chaos to Architectural Rigor: the versionedspecs/folder is the natural input for the Brains. - An issue:
/gbu Start with the story at https://github.com/org/repo/issues/123. The Brains will read it with whatever tools he has available.
And once the plan exists, the arguments can also steer the Sheriff: a path to a different plan file, a specific step to start from, or "just one step" so he runs one and stops. None of this is part of the pattern. It's basically there to make the command nicer to use.
Later runs
The plan already exists, so a bare /gbu is enough: it checks which step the last run stopped at, skips the planning and goes after the first unchecked box. You can stop and restart whenever you like, because with the plan on disk the state doesn't live in the conversation.
The cautious version for big tasks
My advice is to run /listo <task> on its own first, and once it's done, review the plan yourself, since that's the cheapest moment in the whole movie to correct course. Once everything's reviewed, you can launch /gbu, which will see there's a plan and start with the first step.
The individual pieces
The way the code is set up, you can run each character separately: /bueno implements the next step without verification, /malo runs just the attack on the current changes and /feo only does the audit. That's handy for bringing the pattern back in when you're halfway through a task you started by hand.
Quirks of this implementation
The implementation carries a few decisions of its own that piled up from using it every day, each one born from a specific problem, not from a bout of architectitis. I'm telling you about them in case they're useful, and so you know exactly what to change if they don't fit.
- Git staging marks the border between steps: Whatever's approved gets staged, so the rest of the changes are the step in progress. That way the verifiers never re-audit work that's already been validated: they only look at the unstaged diff.
- An effort budget in proportion to the change: After the first tests a somewhat troublesome pattern showed up: the verifiers would send in the whole cavalry for a three-line change. A role with no limits scales its effort to its own ambition. So the Sheriff "measures" the diff before sending anyone in and tells them the size in their orders.
- The Ugly has no shell, on purpose: His frontmatter (the agent's metadata block) declares
tools: Read, Grep, Globand that's it: he can't run tests, build or run git commands. He doesn't need to, either, since the Good and the Bad already made sure the code works. Taking the shell away keeps him from doing things that aren't his job and muddying his mission. So the Sheriff hands him the diff in a file, along with the test, lint, build and type-check numbers the Good wrote down. He also runs on a faster model (model: sonnetin his frontmatter), since he doesn't need as much horsepower as the Brains, the Good and the Bad. - The snapshot patrol: The Bad is forbidden from touching production code: he attacks by writing tests, not by editing lines. But we all know an LLM sometimes hallucinates and skips its constraints. So the Sheriff, like a good lawman, makes sure the Bad doesn't break the law by saving a snapshot of the production diff before sending him in and comparing it when he's done. You could say he lets him work out how to crack the safe, but not lay a finger on it (this Sheriff is counting the days to retirement and doesn't want any trouble).
- Debt doesn't get lost: What if the Bad uses up his three attempts and keeps finding bugs? In my implementation that doesn't block anything. Whatever's left, along with his observations (the findings that don't block, either because the domain type declares them impossible or because fixing them goes beyond the step), is written to a
TECHNICAL_DEBT.mdto tackle later, his tests are marked as skipped (never deleted) with a reference to the entry, and the step moves on to the audit. The reasoning is that a persistent rejection from the Ugly almost always means an ambiguous spec that only you can sort out, so that's where the Sheriff does put his foot down; but the Bad's chronic failures tend to be edge cases that aren't worth blocking the whole plan for. You can change this and make the Bad block too. It's one paragraph in the Sheriff's prompt. - Aggregated reports, scoped verifications: The Bad and the Ugly finish their full pass and hand over every finding at once, so there's one list of fixes per iteration instead of stopping at the first failure. When they come back in after a fix, they only check the previous report and whatever the fix touched, without rerunning the whole battery. And if a fix the Ugly asked for changes behavior, the Bad comes back like a villain out for revenge for one single, scoped check; anything he finds there is logged as debt instead of reopening the cycle. If we let the Bad do his usual job, the fixes the Ugly suggests could keep the Bad going forever.
- Regression tests are verified by mutation: Every fix the Good makes has to be covered by a test that he verifies himself by breaking the line he just fixed, by hand: if the test doesn't fail, the test is no good. Restore it and move on. It costs a few seconds and saves you from a green test that isn't guarding anything.
- The Brains has a review mode: The pattern says the Brains comes in once and leaves. But the implementation adds an exception for when
PLAN.mdexists but doesn't meet the contract (it's missing the task, the context or the steps). This covers hand-written plans that leave something out.
The Sheriff's shortcuts
We already saw that the Sheriff can't wait to retire, so there are times he'd rather skip the paperwork. For example, if the step only changes comments, what's the Bad going to do? However badly written a comment is, it won't return a 500. So before calling in the verifiers, the Sheriff takes a look at the changes and decides whether there's a shortcut:
- Only comments or documentation: The Bad sits this one out, since there's no behavior to break. The Ugly sits it out too, as long as the comments don't document public contracts.
- Only tests, no production code: The Bad stays out here as well, since there's no new implementation to attack. The Ugly, however, always comes in, because tweaking a test so it passes with an assertion that breaks the domain is just a disguise for dodging trouble.
- Only automatic formatting: in other words, the output of a prettier or a linter. Both stay out, since in principle these are style changes that shouldn't touch the semantics of the code.
- Purely cosmetic assets: CSS, images and so on. The Bad stays out here too, he's not there to critique color palettes. The Ugly does come in, because if, say, the spec talks about a dark mode, the CSS has to match.
The bottom line: if the diff makes the shortcut obvious, we take it. If there's too much fog to see the end of the trail, we run the full flow.
When things go sideways
I don't think there's a western where nobody fires a shot. So here's a list of some of the less happy endings, and what you could do in each:
- The Bad won't stop finding bugs: after the third run, remember that whatever's left gets logged in
TECHNICAL_DEBT.mdand the flow carries on. When the step closes, you should review that debt:- If they're real bugs, decide what should happen, write it in the plan and re-enable the tests that were skipped.
- If they're cases your domain declares impossible, leave them logged and sleep easy.
- The Ugly rejects three times in a row: this almost always means the spec is ambiguous and the Good and the Ugly read it differently. Here the Sheriff does stop and ask for help. The fix is to clear up the ambiguity in the "Task" or "Context" section and run
/gbuagain. - The session cuts out in the middle of a step: the persistent state is
PLAN.mdplus git. The unchecked box tells you the step didn't finish. You can run/gbuagain and tell it step X was left halfway. - The plan turns out to be wrong halfway through: at the end of the day, you're the Sheriff's boss. Edit the plan by hand or ask
/listoto replan what's left. Remember that in the ideal flow the Brains "only comes in once", but in this case the plan was wrong. - The steps come out too big: ask for it explicitly in the task ("steps that touch fewer than X files") or edit the plan to spell out how small each step should be. A step should leave the project working, whether it's a complete feature or new domain entities that can be committed on their own.
Wrapping up
We started with three agents who cordially hated each other, and now the Sheriff's office is packed to the rafters, so you go from doing all the work to being a plain analyst who reviews the plan and decides how much to delegate each time a step closes.
The code for my specific Claude Code implementation is in the GBU repository. And if you adapt it to your favorite tool or find that some character needs a firmer hand, tell me on LinkedIn or Instagram: in the Wild West of software there's always room for one more stranger in town.
Also remember this isn't just for programming. Any task you hand off to an LLM can be run through this pattern, so you don't have to take a leap of faith every time a step finishes.
I hope GBU helps you get more out of automation in your projects and trust LLMs a bit more when you hand them the work.
All of this is turning into a book: AI-Assisted Development in a Zombie Apocalypse, the third in the series. I'm still writing the Spanish edition, and the English one comes after it. If you want to hear when it ships, follow the author on Amazon: the shelter doesn't send email, but Amazon does.