DEV Community

ServBay
ServBay

Posted on

One sentence in my prompt moved Claude Fable 5.2 from under 10% to 75% on duplicate code

The number that made me rethink how I write prompts

I write business code for a living, so I know exactly how the mess gets built. A deadline lands, the logic just needs to work, and the feature ships. Requests stack up, the same validation block gets pasted into a third file, patches land on top of older patches. Six months later a one-line change means opening half a dozen files, and the fix quietly breaks two things that used to work.

I had been looking for a way to get a model to clean that up on its own instead of waiting for me to point at every duplicate. Anthropic's official prompting guide for Claude Fable 5.2 had the answer buried in a single test result.

What the test actually measured

On small coding tasks, when the prompt says nothing about who owns the code, or frames the codebase as someone else's project, the model keeps extending whatever structure is already there. That holds even when the new logic is nearly identical to code sitting a few files away. In that setup, Claude Fable 5.2 consolidated duplicate code less than 10% of the time.

Add one sentence saying the model owns and maintains this codebase for the long haul, and the same set of tasks flips. Duplicate code got pulled into shared functions about 75% of the time, and the model often fixed small related issues while it was in there.

The sentence itself

You are the owner and long-term maintainer of this codebase, and its design is up to you.
Enter fullscreen mode Exit fullscreen mode

Three things arrive at once with that line. Ownership first, so the model stops treating the repo as a one-off job for a stranger. Timeline second, since it now has to assume it will be back in these files after this conversation ends. Authority third, which is the part people tend to miss. It is allowed to refactor. Awkward legacy code is no longer something to tiptoe around, because deciding how to straighten it out is part of the job.

Why the role changes what the model does

My day-to-day instructions are blunt. Fix this error. Add a field to this endpoint. With nothing said about ownership, the model falls back on a habit from its training data. Leave other people's legacy code alone, make the smallest change that closes the ticket. The conversation ends, the task is delivered, and copying the block is the safest path because it is the least likely to break something.

Give it the maintainer role and that calculation inverts. The code is no longer a one-off assignment. It is a project the model meets again on the next feature request and the one after that. So before editing, it starts asking questions one step ahead.

01

  • Does this new logic overlap something already written, and should that be extracted and merged?
  • If I take the shortcut now, does the next change get harder?
  • Do the neighbouring files have the same problem, and should those be cleaned too?
  • Are the folder layout and naming consistent, or does the structure need straightening?

Removing redundancy, extracting shared methods, keeping the structure consistent, all of that moves to the top of the list. Code that belongs to someone else only has to run. Code the model will be carrying later is a different proposition.

What shows up in the diff

From my own sessions, cross-checked against Anthropic's test notes, these are the things the model tends to take on by itself once the maintenance prompt is in.

  • Similar validation logic, data transforms or business branches scattered across files get merged into shared functions or utilities, and every call site gets updated.
  • Unreachable branches, unused old variables and stale comments that no longer match the logic get removed.
  • Inconsistent variable names, folder hierarchies and API parameter shapes get aligned.
  • Small related issues get fixed while it works the current task. Anthropic also found that a large share of the extra changes were new unit tests and documentation, which heads off a good number of knock-on problems in later changes.

The bill goes up 70% to 80% in output tokens

Why the output grows

Diligence is not free. With the ownership framing in place, output token usage rises 70% to 80%.

The reason is easy to follow. A maintainer opens more files before writing anything and needs to work out how modules depend on each other. A local patch is a few lines. A structural refactor touches many files, so the analysis and the proposed changes both get longer. Add the tests, comments, docs and related fixes it volunteers, and each conversation produces far more output.

When it is not worth it

I do not leave this on by default. When I have set aside time to clean up a core module, rework an architecture or pay down technical debt, the extra tokens buy better code and that trade is fine. When I am renaming a few variables, tweaking a config line or fixing a small well-defined bug, keeping the prompt in is just burning quota. High-frequency automation scripts and a close eye on the API bill make the timing matter even more. I keep my provider keys behind a single endpoint with ServBay, an AI development management tool, so per-project usage and cost stay visible in one place instead of scattered across environment variables. That makes it obvious which projects can afford the maintainer prompt and which cannot.

02

Changes that spread beyond what I asked for

Cost is not my main worry. Scope is.

Hand over ownership and design authority and the model reaches wide. I ask for one method to change and it tidies a dozen files around it. The review view fills with additions and deletions and checking them by hand is slow. Worse, Anthropic's tests note that in some cases Claude Fable 5.2 changed the existing behaviour of features that were working. Sometimes, in pursuit of a cleaner structure or a design it prefers, it refactored away code written specifically to handle edge cases. That is how an incident gets shipped.

There is a smaller version of the same problem. The change summary at the end often leaves out the small things it touched along the way. Skim the summary, skip the diff, and those changes go straight to main.

The obvious guardrail does not hold

My first instinct was to put a restriction in front of the ownership line and tell it not to touch anything else.

Anthropic's tests shut that down. They prefixed a constraint like No drive-by refactors, renames or cleanups while keeping the ownership framing, and the model still consolidated duplicate code in more than half of the tests. A single restriction does not hold back the urge to refactor.

The official advice is more practical. If I am changing an open source project someone else maintains, working in a shared repository, or just want this commit to be as small as possible, delete the ownership prompt and leave it out.

Process rules instead of prompt rules

I use the prompt only when the code is mine to manage and I actually want the structure cleaned along the way. Then I fence it with hard process rules.

  • Stop before editing any files, list the analysis and the plan, and wait for approval.
  • Lock down which files may change, and require a flag on anything touched outside the scope of the request.
  • State up front that existing public APIs and business behaviour are off limits, and that anything that might affect existing functionality needs a sign-off first.
  • Change one small piece at a time, review the diff and run the tests before going further. Never let it rewrite an entire module in one go.

03

How I write the prompt now

A one-line role is not enough. I write the whole request in five layers.

  1. Role, the owner and long-term maintainer framing.
  2. Goal, exactly which duplicate logic this task deals with.
  3. Boundaries, which files may change and which APIs and business behaviour must not.
  4. Process, analysis and a plan first, code changes only after I confirm.
  5. Verification, tests pass at the end and every change is listed against the real diff.

A template I reuse

If I want duplicate validation logic in the sign-up flow cleaned up, the instruction looks roughly like this.

You are the owner and long-term maintainer of this codebase. Please resolve the duplicate validation logic in the user sign-up flow.
Before modifying any code, first analyze where the duplicate code appears and propose a refactoring plan.
Only modify files directly related to sign-up validation this time, and keep existing public APIs and business behavior unchanged.
For any change that might alter existing functionality, explain the impact first and wait for confirmation. Do not make the adjustment on your own.
When finished, run the relevant unit tests and summarize all changes and potential risks against the actual code diff.
Enter fullscreen mode Exit fullscreen mode

Broken into layers, the model still hunts redundancy, but the file edits sit behind plan approval, file boundaries and test verification. It feels much safer to run.

Where this fits in my workflow

When I turn it on, when I leave it out

A prompt of about a dozen English words takes the duplicate consolidation rate from under 10% to about 75%. It also adds 70% to 80% more output tokens and the risk of changes spreading out of control.

The useful part is switching it on and off by situation. Long-lived personal projects, or a legacy module whose debt has become impossible to ignore, get a dedicated refactor task with the prompt plus boundaries, automated tests and a line-by-line diff review. Everyday small fixes, urgent production hotfixes and pull requests to someone else's repository never see it.

Most of the time the model can write clean code. The problem is the instruction only pushes it to ship the feature and never says the code will be its responsibility afterwards. Put long-term maintenance into the prompt and the spaghetti stops growing.

Top comments (0)