One Prompt Makes AI Refactor Code: Unpacking Claude 5.2's Ownership Mechanism

Telling Claude who owns the code triggers proactive refactoring more than telling it how to change it.
The article explores a detail in Anthropic's docs: whether Claude 5.2 refactors and merges duplicate code depends heavily on whether the prompt declares code ownership. Tests on small programming tasks show that adding an ownership declaration like "this code is yours" raises the merge-attempt rate from under one in ten to about half. The author argues LLMs are highly sensitive to role and responsibility boundaries, and that prompt engineering is shifting from clear instructions to context setting—while cautioning the effect is only validated on small tasks and alters risk preference.
Anthropic's official documentation contains an easily overlooked detail: when Claude 5.2 writes code, whether it refactors and whether it merges duplicate logic depends heavily on whether the prompt tells it "who owns this code." This finding comes from Simon Willison's excerpt of the official docs, but in engineering practice, its significance goes far beyond a prompt-engineering tip.

Ownership Declaration: An Underrated Prompt Dimension
According to the Anthropic documentation, in tests on small programming tasks, if the prompt says nothing about code ownership—or describes the codebase as "someone else's"—the model tends to keep piling onto the existing structure, even if that means duplicating existing code. In other words, it treats itself as a cautious visitor who doesn't dare touch the host's furniture.
When the prompt explicitly declares "this code is yours," however, the behavior changes markedly. The official suggested sentence is:
This codebase is yours: what it's for and how it's built are your call, and you'll keep building on it.
The meaning is that the purpose and construction of the codebase are up to the model itself, and it will keep evolving on that basis. Essentially, this repositions the model from "outsourced executor" to "long-term maintainer."
System prompt is a set of instructions preset by the developer in a conversation, invisible to the user (or not directly edited by the user), used to define the model's role, behavioral boundaries, and output specifications; it belongs to a different layer than what the user enters in each turn of the conversation. In API calls, the system field is usually processed first and remains in effect for all subsequent turns, so it's often used to carry global settings like "who you are and who you work for." When the article says "write ownership into the system prompt," it's exploiting the persistence of the system prompt to keep the model in a "long-term maintainer" self-identity throughout the session, rather than temporarily playing a role in a single message. By contrast, similar statements placed in ordinary user messages have a narrower scope and are more easily diluted by subsequent conversation.
The Data Speaks: The Probability Gap in Merging Duplicate Code
Anthropic's tests on small programming tasks give an intuitive comparison: with the ownership declaration above, the model merged duplicate code in roughly half of its attempts; without it, the rate was less than one in ten.
This gap is worth pondering. Merging duplicate code is a typical refactoring action—it requires the model to understand the global structure, judge which logic can be abstracted, and bear the risk of the change. Without an ownership hint, the model leans conservative: only addition, no surgery.
From a prompt-engineering perspective, this reveals an underlying mechanism of model behavior: an LLM's sensitivity to "role" and "responsibility boundaries" may be no lower than its sensitivity to specific instructions. Tell it to change the structure, and it may not; tell it "this is your project," and it will proactively optimize instead.
Duplicate code refers to the same or highly similar logic appearing in multiple places in a codebase. It isn't necessarily an error, but in engineering it's usually regarded as technical debt: a single logic change requires synchronized edits in multiple places, which is easy to miss and introduce inconsistent defects. The typical remedy for eliminating duplication is extracting common functions, modules, or abstraction layers—which is one of the core actions of "refactoring." Note that merging has its own cost—over-abstraction lengthens call chains and tightens coupling, so whether to merge often depends on judgment about the overall structure and future evolution of the code. This also explains why the model tends to only add when it lacks a sense of ownership: merging requires it to bear the responsibility of judging changes to the existing structure, and that is precisely what a "visitor mindset" avoids.
Practical Implications for Developers
This finding can be applied directly to everyday AI programming workflows. If you use Claude for code review or refactoring, consider explicitly stating ownership in the system prompt. For example, when having it maintain a long-term project, declare that the codebase belongs to it; when having it do only a one-off patch, emphasize that this is someone else's code so it doesn't change the structure on its own.
Interestingly, this phrasing is no master key. The documentation's tests focus on small programming tasks; effects in large codebases, multi-file refactoring, and similar scenarios have no public data yet. Moreover, "ownership" is a metaphorical prompt—the model's behavioral change is more probabilistic: half versus less than one-tenth is a significant difference, but not a deterministic switch.
Another easily overlooked point: the ownership declaration changes the model's risk preference. When the model believes the code is its own, it's more willing to make structural changes—which isn't always a good thing in production environments that need stability. The power of a prompt lies in direction, and direction needs a human to control it.
Risk preference here refers to the model's tendency to choose between "changing the existing structure" and "keeping the status quo and only adding incrementally." LLMs don't explicitly calculate risk, but their output distribution is influenced by the responsibility attribution implied in the prompt: when the model is set as the long-term owner of the code, its "psychological threshold" for structural changes is lowered, and it's more willing to accept the knock-on edits that refactoring brings; when set as an external collaborator, it leans conservative. This closely resembles how human engineers behave when facing code that isn't theirs. The practical implication: ownership prompts are both an efficiency lever and a risk switch—use them cautiously on production branches that need stability, or apply them together with constraints like "do not change public interfaces" and "keep changes minimal."
Prompt Engineering Is Shifting from Instructions to Settings
Placed in a broader context, this reflects a trend: the focus of prompt engineering is shifting from "writing clear instructions" to "setting up the right context." Early prompt techniques focused on formats, examples, and step-by-step reasoning; prompts like ownership touch on the model's self-identity and long-term intent.
Anthropic lists this recommendation separately in its documentation, indicating that internally they also consider it a reusable pattern. For teams building AI programming tools, this may mean adding a "project ownership" field to prompt templates, just as tech stack and code style are now commonly specified.
In one sentence: telling the model who owns the code is sometimes more effective than telling it how to change it.
One-line Summary
Telling Claude who owns the code triggers proactive refactoring more effectively than telling it how to change it.
Paragraph Summary
The article centers on a detail in Anthropic's documentation: whether Claude 5.2 refactors and merges duplicate code depends heavily on whether the prompt declares code ownership. Official tests on small programming tasks show that adding an ownership declaration like "this code is yours" raises the model's rate of attempting to merge duplicate code from less than one in ten to about half; without it, the model behaves more like a cautious outside visitor, only layering code onto the existing structure. The author argues this reveals the LLM's high sensitivity to role and responsibility boundaries, that prompt engineering is shifting from writing clear instructions to setting up context, and recommends specifying project ownership in the system prompt. It also cautions that the effect has only been validated on small tasks and that it changes the model's risk preference, so direction must be controlled by humans in production environments.
Related articles

Michael Nielsen Takes Down His Classic Neural Network Textbook, Sparking Community Discussion
Michael Nielsen's classic free textbook Neural Networks and Deep Learning has been taken offline, sparking discussion on Hacker News about the reasons and impact.

Inside the AI Training Data Market: The Trade-off Between Exclusivity and Discounts
G2i founder Gabe Greenberg reveals the dual-track pricing of the AI training data market: labs pay a premium for exclusive data or accept discounts that allow others to buy it.

SessionGraph: Unifying All Coding Agent Sessions in One Interactive Graph
SessionGraph aggregates coding agent sessions into an interactive graph, helping developers review, debug, and manage AI coding workflows across sessions. This article examines its positioning, value, and open questions.