The Deska blog
When Agents Copy Your Worst Existing Pattern
Learn why AI coding agents copy your worst existing pattern and how to fix technical debt using context-aware developer tools like Deska.
· 11 min read
Large Language Models have a tendency to mirror the environment they inhabit. While we often celebrate their ability to generate boilerplate or solve complex logic puzzles, a common frustration arises when agents copy your worst existing pattern. This phenomenon occurs because agents prioritize local context and consistency over abstract architectural ideals. If your codebase contains a legacy utility function that uses an inefficient loop or a non-standard error handling strategy, the agent will likely replicate that exact behavior in new files to ensure the new code fits in.
The logic behind this behavior is rooted in how transformer models predict tokens. They look for statistical probability within the provided context window. If the context is saturated with a specific style of implementation, the model assumes that style is the intended standard for the project. Understanding why this happens and how to intervene is critical for maintaining long term code quality.
Why Agents Prioritize Consistency Over Quality
Consistency is usually a virtue in software engineering. When an AI agent analyzes a repository, it interprets existing patterns as a set of implicit rules. This leads to several scenarios where the agent intentionally produces suboptimal code.
- The weight of precedence: If ten files use a deprecated library and one file uses the modern replacement, the agent will statistically favor the deprecated library. It views the majority as the ground truth.
- Contextual mimicry: Agents are designed to be helpful assistants that blend into your workflow. They try to match your variable naming conventions, indentation, and even your architectural mistakes to avoid introducing linting errors or style mismatches.
- Limited global awareness: Most agents operate on a subset of the codebase. If the specific files indexed in the current session contain technical debt, the agent has no way of knowing that a better pattern exists elsewhere in the repository.
This creates a feedback loop where technical debt is not just preserved but actively scaled. Every time an agent replicates a bad pattern, the statistical weight of that pattern increases, making it even more likely to be used in the future.
Breaking the Cycle of Bad Patterns
To prevent AI from scaling your technical debt, you must change how you provide context and how you interact with the agent during the generation phase. Relying on the agent to magically know the best practices for your specific stack is a recipe for regression.
Explicit Context Curating
The most effective way to stop an agent from copying a bad pattern is to provide a reference for a good one. Instead of letting the agent scan the whole folder, point it toward a gold standard file. This acts as a primary anchor for the generation. You can explicitly state in your instructions that the agent should ignore the patterns found in legacy modules and instead follow the structure of your chosen reference.
Iterative Refinement and Prompting
Never accept the first draft of a complex implementation if you notice it following an old pattern. Use the chat interface to challenge the output. For example, you can tell the agent that while it followed the existing error handling style, you are now transitioning to a new functional approach and it should refactor the suggestion accordingly.
Managing Agent Context in Deska
Deska provides a unique environment for managing these interactions through its infinite canvas. Because the workspace allows you to place multiple panels anywhere, you can physically organize your context to influence the agent.
- Side by side comparison: You can open a legacy file in one Monaco editor panel and a new, well-architected file in another. This allows you to see exactly where the agent might be pulling its inspiration from.
- Isolated agent threads: Using agent threads, you can isolate specific tasks. If you are refactoring a specific module, you can keep that conversation separate from the general codebase chat to avoid cross contamination of patterns.
- Multiple agents: Deska allows you to run Claude Code, Codex CLI, and OpenCode side by side. Different models have different biases toward following existing code. You might find that one model is more prone to copying bad habits than another.
By using panels to create a visual map of your project, you can better understand the context you are feeding into Ask Deska. The canvas allows you to zoom out and see the relationship between your terminals, code, and agent outputs, making it easier to spot when an agent is veering off course into legacy patterns.
Comparison of Agent Environments
The environment where you run your agent significantly impacts how you manage its output and the context it consumes.
| Feature | Standard CLI Agents | Integrated IDE Agents | Deska Canvas |
|---|---|---|---|
| Visual Context | Text only | File tree focus | Infinite canvas layout |
| Multi-Model | Usually one at a time | Tool specific | Side by side panels |
| Workflow Driving | Manual commands | Integrated UI | Voice and Chat assistant |
| State Management | Terminal history | File tabs | Persistent panels |
While standard CLI tools are powerful, they often lack the spatial awareness that helps a developer manage complex refactoring tasks. Deska's local-first approach ensures that while you are experimenting with these different models, your code remains on your machine, allowing for rapid iteration without privacy concerns.
Technical Debt and the Cost of Automation
The speed of AI generation can be deceptive. While an agent can generate a new feature in seconds, the cost of fixing a replicated bad pattern across twenty files is high. Developers must transition from being writers of code to being reviewers and curators of context.
- Review every pull request from an agent with the same scrutiny as a junior developer.
- Maintain a
CONTRIBUTING.mdor a style guide file that the agent can read to understand your preferred modern patterns. - Use notes within your workspace to keep track of which patterns are deprecated and should not be copied.
FAQ
How do I stop AI agents from using deprecated libraries?
The best way is to remove the deprecated code from the active context window or explicitly instruct the agent in your prompt to avoid specific libraries. Providing a snippet of the new library in a pinned panel or note helps the agent understand the preferred alternative.
Can AI agents refactor old patterns automatically?
Yes, but it requires a high level of oversight. You should use Ask Deska or chat to target specific blocks of code and provide a clear example of the desired end state. Doing this in small, incremental steps is more effective than asking for a global refactor of a large repository.
Does Deska store my code on its servers?
No. Deska is a local-first application. Your files, terminals, and session data stay on your machine. If you use your own API keys, the communication is between your machine and the model provider.
Take Control of Your Code Quality
The goal of using AI is to increase productivity without sacrificing the architectural integrity of your project. By understanding that agents are prone to mimicking what they see, you can take proactive steps to curate the context they consume.
Deska offers the tools to manage this complexity through its infinite workspace and multi-panel approach. Whether you are running Claude Code or using voice commands to drive your environment, you have the visual and functional control needed to keep your codebase clean.
Download Deska for Mac, Windows, or Linux and start organizing your agent workflows on a canvas designed for modern development. Dive into the documentation to learn more about how to configure your workspace for maximum efficiency.