# AI Coding Tip 042 - Stop AI Cowboy Vibe Coding

> TL;DR: Reject any vibe-coded diff that goes beyond the spec, and move the extras to their own case.

# Common Mistake ❌

You ask the AI to fix one validation rule.

It fixes the rule, renames three variables, [reformats the file](https://maximilianocontieri.com/code-smell-48-code-without-standards), changes two unrelated rules, and rewrites a class nobody mentioned.

The tests pass and the vibes are good, so you send the pull request.

Your reviewer now [reads a diff](https://maximilianocontieri.com/ai-coding-tip-006-review-every-line-before-commit) full of changes nobody asked for, and the real change hides inside it.

Good luck finding it.

That's [vibe coding](https://maximilianocontieri.com/explain-in-5-levels-of-difficulty-vibe-coding) with no brakes.

It's also [cowboy coding](https://maximilianocontieri.com/code-smell-227-cowboy-coding), and the AI finally made it affordable for everyone.

Another AI can do the same to the first one's work, with the same confidence.

# Problems Addressed 😔

- A reviewer can't tell the requested change from the extras, and the diff becomes a [big pull request](https://maximilianocontieri.com/code-smell-239-big-pull-request).
- A [defect](https://maximilianocontieri.com/stop-calling-them-bugs) in an unrequested change has no spec to blame, no ticket to trace, and no test written for it.
- You can't revert the requested change without losing the unrequested ones.
- A cleanup mixed with a behavior change hides regressions, the classic [refactor with functional changes](https://maximilianocontieri.com/code-smell-170-refactor-with-functional-changes).
- The spec stops being the source of truth, because the code does things nobody wrote down.
- Approving a diff means approving decisions nobody discussed and agreed, which is an interesting way to run a team.
- Every extra file adds merge conflicts for the rest of the team.

# How to Do It 🛠️

1. Write the change down before you prompt: the case description, the intention, the ticket, or the [spec](https://maximilianocontieri.com/ai-coding-tip-008-use-spec-driven-development-with-ai) is the whole scope.
2. List what's out of scope in the same document, and [force the AI to obey](https://maximilianocontieri.com/ai-coding-tip-015-force-the-ai-to-obey-you) it so it can't invent extras: no refactoring, no renames, no formatting, no new dependencies.
3. Grant the AI write access only to the files the change needs, following [least privilege](https://maximilianocontieri.com/ai-coding-tip-036-grant-ai-the-least-privilege-possible).
4. Ask the AI to [plan first](https://maximilianocontieri.com/ai-coding-tip-003-force-read-only-planning) and list the files it'll touch, then compare that list with the scope.
5. Send the diff to an adversarial reviewer: a [different model](https://maximilianocontieri.com/ai-coding-tip-029-stop-using-one-model-for-everything) in a [fresh context](https://maximilianocontieri.com/ai-coding-tip-005-keep-context-fresh) that sees only the spec and the diff.
6. Make the reviewer map every changed hunk to one numbered requirement, and flag each hunk it can't map.
7. Point the reviewer at the tests the diff impacts, so it can measure the change: a test edited or deleted that the spec never mentioned, or a test outside the scope that now fails, shows the diff went too far.
8. Wire that check into your [harness](https://maximilianocontieri.com/ai-coding-tip-022-give-ai-a-harness-to-work-with) as a [criteria check](https://maximilianocontieri.com/ai-coding-tip-024-force-a-criteria-check-before-the-task-ends) that fails the task when any hunk is unmapped.
9. Reject the pull request when the check flags unrelated hunks, and don't negotiate with it: every rejection is a [finding you can turn into a rule](https://maximilianocontieri.com/ai-coding-tip-041-turn-every-review-finding-into-a-rule).
10. Cherry-pick the useful extras into a new case with its own spec, tests, and review, and put every refactoring there.
11. Merge only when every hunk in the diff traces back to the spec.

# Benefits 🎯

1. **Review the requested change:** Your reviewer reads what someone asked for, and nothing else.
2. **Trace every line:** Every hunk points to a requirement, so a defect has an owner and a ticket.
3. **Revert cleanly:** You can back out one change without losing three others.
4. **Separate refactoring:** A cleanup gets its own tests and its own review.
5. **Control other agents:** The same check stops a second AI, or a teammate, from widening the change.
6. **Trust the spec:** The code does what the spec says, and nothing more.
7. **Shrink the diff:** A [small pull request](https://maximilianocontieri.com/ai-coding-tip-023-shrink-your-ai-s-pull-request) gets a real review instead of a skim.
8. **Measure the reach:** The tests a diff impacts show how far it went, even when the code looks small.
9. **Keep changes proportional:** A small functional change gets a small code change, so a big diff is a signal that something went wrong.

# Context 🧠

[Cowboy coding](https://en.wikipedia.org/wiki/Cowboy_coding) took effort once, and effort was a natural brake.

Now the AI sprawls in seconds, for anyone, human or agent.

[Vibe coding](https://en.wikipedia.org/wiki/Vibe_coding) means describing the goal and accepting the result with little close review.

Without a scope check, that's cowboy coding at machine speed.

The AI is a multiplier of the good and bad things.

Bertrand Meyer's modular continuity says a small change in the specification should trigger a small change in the code.

The [bijection](https://maximilianocontieri.com/the-one-and-only-software-design-principle) says it from the other side: the real world is the source of truth, and each thing in it has one object in the code.

%[https://maximilianocontieri.com/the-one-and-only-software-design-principle]

Google's review guide says [refactorings usually belong in a separate change](https://google.github.io/eng-practices/review/developer/small-cls.html) from feature changes or fixes.

[Scope creep](https://en.wikipedia.org/wiki/Scope_creep) is the same failure at project size.

You need a check in your [harness](https://maximilianocontieri.com/ai-coding-tip-022-give-ai-a-harness-to-work-with) that compares the diff with the spec.

## Prompt Reference 📝

## Bad Prompt 🚫

```markdown
Fix the discount validation in OrderService.

(Two prompts after)

While you're in there, clean up whatever looks messy.

(One prompt after)

Also refactor the Merchant Processor

(One prompt after)

Change the order number validator (just because I want it)

(One prompt after)

Rename unclear variables and update the old class.

(One prompt after)

Make the whole module better.
```

## Good prompt 👉

```markdown
You are an adversarial scope reviewer.
You didn't write this code, and you don't trust it.
Read the spec in SPEC.md.
Read the diff against main.
Map every changed hunk to one numbered spec requirement.
Mark each hunk you can't map as OUT OF SCOPE.
Find the tests the diff edits, deletes, or breaks.
A test change with no spec requirement is OUT OF SCOPE too.
These are out of scope unless the spec asks for them.
Renames and reformatting.
Refactoring and new dependencies.
Edits to files the change doesn't need.
Don't suggest fixes.
Don't praise the code.
Reply REJECT if any hunk is out of scope.
Reply APPROVE only when every hunk maps to a requirement.
List the out-of-scope hunks, one per line.
I'll cherry-pick them into a separate case.
```

# Considerations ⚠️

Vibe coding a throwaway prototype is fine.

This tip is about code you merge.

A tiny cleanup, like renaming a local variable, can stay in the change.

Your team decides where that line sits, and you should write it in the spec.

A vague spec makes every hunk arguable. You need to write accurate specs.

A signature change forces its callers to change, so those hunks map to the requirement.

The adversarial reviewer is also an AI.

Yes, the irony is intentional.

It can miss a hunk or invent one, so you still read the ones it flags.

# Type 📝

\[X\] Semi-Automatic

# Limitations ⚠️

The check needs a written spec, and it can't judge a change nobody described.

A hunk can map to a requirement and still hide an extra behavior inside it.

The tests only show the reach of a change where [coverage](https://maximilianocontieri.com/code-smell-175-changes-without-coverage) exists.

# Tags 🏷️

- Safety

# Level 🔋

\[X\] Intermediate

# Related Tips 🔗

%[https://maximilianocontieri.com/ai-coding-tip-008-use-spec-driven-development-with-ai]

%[https://maximilianocontieri.com/ai-coding-tip-023-shrink-your-ai-s-pull-request]

%[https://maximilianocontieri.com/ai-coding-tip-022-give-ai-a-harness-to-work-with]

%[https://maximilianocontieri.com/ai-coding-tip-024-force-a-criteria-check-before-the-task-ends]

%[https://maximilianocontieri.com/ai-coding-tip-036-grant-ai-the-least-privilege-possible]

%[https://maximilianocontieri.com/ai-coding-tip-003-force-read-only-planning]

%[https://maximilianocontieri.com/ai-coding-tip-005-keep-context-fresh]

%[https://maximilianocontieri.com/ai-coding-tip-015-force-the-ai-to-obey-you]

# Conclusion 🏁

The AI will go beyond the spec every time you let it.

Asking nicely hasn't worked so far.

A check that reads the diff works better, and so does a rule that rejects it and sends the extras to their own case.

# More Information ℹ️

[Cowboy coding, Wikipedia](https://en.wikipedia.org/wiki/Cowboy_coding)

[Scope creep, Wikipedia](https://en.wikipedia.org/wiki/Scope_creep)

[Vibe coding, Wikipedia](https://en.wikipedia.org/wiki/Vibe_coding)

[Small CLs, Google Engineering Practices](https://google.github.io/eng-practices/review/developer/small-cls.html)

[Modular Continuity, Software Concept](http://softwareconcept.blogspot.com/2009/06/modular-continuity.html)

# Also Known As 🎭

- Scope-Locked-Diffs
- Spec-Bound-Pull-Requests
- Diff-to-Spec-Audit
- Controlled-Vibe-Coding

# Disclaimer 📢

The views expressed here are my own.

I am a human who writes as best as possible for other humans.

I use AI proofreading tools to improve some texts.

Most AI detectors will flag this article as AI-generated. That's expected. It's a technical article. It has a rigid format and clear steps to follow.

That's exactly the pattern those tools are trained to catch. I've apparently been "writing like an AI" for decades, long before AI existed. This is a technical article, not a novel.

I welcome constructive criticism and dialogue.

I shape these insights through 30 years in the software industry, 25 years of teaching, and writing over 500 articles and a book.

# Credits 🙏

Photo by [Adam Young](https://unsplash.com/@hossua34) on [Unsplash](https://unsplash.com/photos/cowboy-on-horseback-views-monument-valley-desert-landscape-krkFypi5kqE)

---

This article is part of the *AI Coding Tip* series.

%[https://maximilianocontieri.com/ai-coding-tips]
