← Back to library

Make your coding agent write the behavior before the code

u/cannyshammy on r/ClaudeCode shares the block he keeps in CLAUDE.md to stop agents drifting from what he asked for: describe the expected behavior first, turn it into tests, see them fail, then implement. He writes the scenarios himself and lets the agent write the tests. We show his block word for word with credit.

  • OutcomeAdd a short standing rule to your coding agent's project file so every user-facing change starts as plain-language scenarios, becomes a failing test and only then gets the smallest code change that makes it pass.
  • SetupMinutes
  • LevelIntermediate
  • Creditu/cannyshammy on r/ClaudeCode
View original
Works with
Claude CodeCustom agentChatGPT

Published Nov 21, 2026Updated Nov 21, 2026AI dry run on sample input: passed Nov 21, 2026Source verified Nov 21, 2026

When should you use it?

  • Your coding agent builds something close to, but not quite, what you asked for
  • You want requirements that keep being checked in CI after the chat is over
  • Non-developers on the team want to describe features in plain language

Not for: Projects with no test runner or CI where tests could actually run; Pure refactors, renames and styling changes with no visible behavior; Throwaway prototypes where speed matters more than lasting checks

What do you need, and what do you get?

You need

  • A project instructions file the agent reads, such as CLAUDE.md or AGENTS.md
  • A test setup that can run scenario-style or ordinary tests
  • One example scenario file to show the format

You get

  • Written scenarios for each user-facing change
  • Tests that fail before the change and pass after it
  • A minimal code change tied to those tests

How does it work, step by step?

  1. Paste the blockAdd the poster's block to your agent's project instructions file.
  2. Add one exampleCommit a single scenario file so the agent copies a real format instead of inventing one.
  3. Write the scenarios yourselfFor each feature or bug, describe what should happen in plain language before asking for code.
  4. Check the failing testAsk the agent to show the new test failing before it implements anything.
  5. Let CI keep scoreRun the scenarios in CI so the behavior stays checked long after the session ends.

The prompt

The original prompt by u/cannyshammy, word for word, with a link to where it was published. Below it is our adapted version with fill-in blanks, if you want it. Works in Claude Code, Custom agent and ChatGPT. Values in lime are placeholders.

Original prompt by u/cannyshammy

Word for wordby u/cannyshammy
## Behaviour-First Default
This project follows BDD. See the `.feature` files for examples. For any user-visible feature, bug fix, or workflow change, start from the behaviour.

1. Write down the expected behaviours or acceptance criteria first.
2. Turn those behaviours into executable tests before implementation.
3. Make the relevant new test fail first when practical.
4. Implement the smallest change that makes the behaviour pass.

Do not start by coding the solution and only think about tests later.

Exactly as published by u/cannyshammy in I added this to my CLAUDE.md to help stop my agents drifting away from what I originally asked them to build.

Our adapted version (optional)

Fill in the blanks (optional; the copied prompt uses your values)

Adapted prompt2 variables
Project rule: for any change a user would notice ({scope}), start with behavior, not code.
List the expected behaviors as short given/when/then scenarios and wait for me to confirm them.
Turn the confirmed scenarios into tests in {test_framework}, run them and show me they fail.
Then make the smallest code change that makes them pass, and tell me if any scenario was unclear instead of guessing.

What can go wrong?

  • Letting the agent write both the scenarios and the code. The value comes from a human stating the behavior.
  • Skipping the failing run. A test that never failed may not test anything.
  • Applying it to every change. Renames and styling tweaks do not need scenarios, and the rule says user-visible work.
  • Vague scenarios. 'It should work well' cannot become a test; name the starting state, the action and the result.

Our take

This is one of the more useful CLAUDE.md snippets we have seen because it puts the instruction somewhere the agent cannot quietly drift from: the test suite. A paragraph of guidance fades as a session gets long, while a failing scenario keeps saying no until the behavior is right. The poster's key point, that the human writes the behaviors and the agent writes the tests, is the part to keep; if the agent writes both, it can make its own misunderstanding pass. The rule is also sensibly scoped to user-visible work, so renames and styling changes are not slowed down. It does need a working test setup and some discipline about keeping scenarios specific. This is one developer's experience on his own app, not a measured study. In our dry run on a fictional dog-walking booking app, the agent wrote fee scenarios before any code, showed them failing, then passed them, and raised an unclear late-cancellation case as a question instead of guessing.

Where the time goes back: Catching a misunderstood feature at the scenario stage takes a minute of reading, while finding it after the code is written means a second round of changes and review.

FAQ

Do I need a BDD framework?
It helps, but the core habit works with ordinary tests: write down the expected result, see the test fail, then change the code.
Does it work outside Claude Code?
Yes. Any coding agent that reads a project instructions file, such as AGENTS.md, can follow the same rule.
Who should write the scenarios?
Ideally the person who knows what users need. The poster writes them himself and leaves the test code to the agent.

Source and credit

The original prompt on this page is by u/cannyshammy, shown word for word with a link to where it was published. The summary, notes and adapted version are ours.

Original
I added this to my CLAUDE.md to help stop my agents drifting away from what I originally asked them to build
Creator
u/cannyshammy on r/ClaudeCode
Published on
Reddit
Original date
Nov 19, 2026
License
Not openly licensed; the original prompt is shown word for word with credit and a link to the original
Originally for
Claude Code
AI dry run
Nov 21, 2026: passed. Dry-run tested by our AI test agent on sample input. Behavior-first order, failing test first, minimal change and the user-visible scope limit all held; simulated repository, no real code shipped.
AI dry run on sample data; not run with live connected accounts. The playbooks.bot test agent filled the prompt with synthetic inputs, produced the output and checked it against the page's stated outputs and guardrails.
Verified
Nov 21, 2026: source link resolves to the original, the credited creator published it, our excerpt or prompt matches it, and the license allows our use.

Are you the creator? Claim or correct this page.

More in IT & Security

All 82 IT & Security playbooks →

Related playbooks

IT & SecurityPrompt✓ AI dry run

Question an agent's pull request instead of skimming reviews

Have a fresh agent list every concrete change in an agent-written pull request (schema, scheduled jobs, features, new services, settings, endpoints and removals) without judging it, then press it on each item you cannot explain, give it the product context it lacks, and cut whatever nobody can justify before you merge.

Credit: u/EstablishmentGood414 on r/codex

Minutes
IT & SecurityWorkflow✓ AI dry run

Put a reviewer AI between your agent and anything it sends

Let a long-running personal agent act on your behalf while a separate model checks every outgoing message, post or code push, and dangerous commands are blocked.

Credit: Justin Headley

An afternoon+
IT & SecurityRoutine✓ AI dry run

Schedule a daily repo brief that reports, not edits

Skip the morning scramble of figuring out where a project stands, using a scheduled agent that summarizes what changed and what needs attention, without touching code.

Credit: Developers Digest

Under an hour
IT & SecurityWorkflow✓ AI dry run

Onboard a coding agent like a junior engineer

Get real work out of an autonomous coding agent on a mature codebase by teaching it your conventions, the way you would onboard a new hire.

Credit: Varun Jindal, Engineer @ Lumos / Andrew Wang, Engineer @ Lumos

An afternoon+