Topic 5 of 5 · 3 min read
Coding instruction anti-patterns
Goal: Find the anti-pattern in a coding instruction and rewrite it so an agent can follow it.
Most bad agent output traces back to a bad instruction, and the bad instructions fall into a few repeating shapes you can learn to spot and fix.
Check yourself · 1 of 3
Which instruction is a kitchen-sink request?
Why it matters
When an agent returns the wrong thing, it is tempting to blame the model. Often the instruction was vague, enormous, self-contradicting or hidden in a thread of two hundred messages. Fixing the instruction is cheaper than fighting the output, and the same fix works on Claude, ChatGPT, Gemini, Copilot and open-weight models.
Four shapes to look for
- The vague ask. "Clean up the auth code." Clean by what measure? The agent picks its own and rewrites more than you wanted. Fix: name an outcome and a boundary.
- The kitchen sink. "Add pagination, fix the date bug, upgrade the ORM, rename the service and update the docs." Five tasks in one request give a five-part diff nobody can review, and the agent drops some parts. Fix: one task per request, ordered, each with its own check.
- The contradiction. "Keep changes minimal" and "refactor for readability" in the same message, or a prompt that disagrees with
AGENTS.md. The agent obeys one at random. Fix: decide which wins, and say so. - The buried instruction. A key rule given in message 3 of a long chat is far from the point of use, and long contexts dilute attention. Fix: restate the rules that matter in the new task, or start a fresh session with a short brief.
Before and after
Weak:
Clean up the checkout code, make it faster, add tests and also migrate to the new payments SDK. Keep it simple but make it extensible. Don't change much.
Better, first request:
Goal: add tests for calculateTotal in src/checkout/total.ts, covering empty cart, discounts and tax rounding.
Change no production code. Run pnpm test src/checkout and paste the output.
The payments migration, the speed work and the cleanup become separate requests, each with their own goal and check. "Simple but extensible" disappears because nobody can act on it.
What goes wrong
- Fixing it with emphasis. Capital letters and "very important" do not make a vague instruction clear.
- Piling on patches. Each failed attempt gets another rule appended, until the prompt contradicts itself. Rewrite it from scratch instead.
- Blaming the tool. If three tools give three different wrong answers, the instruction is the likely cause.
- Never rereading your own prompt. Read it as a stranger would: could two people build different things from it? If yes, it needs work.
Examples
Splitting a kitchen sink
Before: Add pagination, fix the date bug, upgrade the ORM and update the docs.
After: Four requests in order. First: add pagination to GET /orders only, with a test, and paste the test output. The others wait until that diff is reviewed.
Resolving a contradiction
Before: Keep the change minimal. Also refactor the module for readability.
After: Priority: minimal change. Fix the null check in parse() only. Do not refactor; list any readability issues you notice at the end instead.
Key points
- The vague ask gives the agent license to pick its own measure, so name an outcome and a boundary.
- A kitchen-sink request produces a diff nobody can review; split it into one task per request.
- Contradictory rules, including a prompt that clashes with the standing file, get obeyed at random.
- Key instructions buried deep in a long chat fade, so restate them or start a fresh session.
- When an attempt fails, rewrite the instruction instead of stacking on more rules or emphasis.
Common mistakes
- Writing several unrelated tasks in one message and then reviewing one large, mixed diff.
- Giving rules that conflict, such as minimal change and full refactor, without saying which wins.
- Relying on a rule stated an hour ago in a very long conversation.
- Answering a failed attempt by adding more rules and capital letters instead of rewriting the instruction.
Check yourself · 2 of 3
A prompt says keep changes minimal and also refactor for readability. What is the best fix?
Check yourself · 3 of 3
In message 3 of a long chat you gave a key rule. Fifty messages later the agent ignores it. What helps most?
Practice items, not counted towards your mastery.
Start here
- Best practices for Claude Code (Claude Code docs) (opens in a new tab)DocsFree
A vendor's own advice: give the agent a way to verify its work, name files and explore before coding.
- Best practices for using GitHub Copilot (opens in a new tab)DocsFree
Guidance on writing clear prompts, breaking tasks down and giving context to a coding assistant.
- AGENTS.md (opens in a new tab)DocsFree
The open convention for a standing instruction file that coding agents read before each task.