The Deska blog

Point at a Reference Implementation for Better LLM Code

Learn how to point at a reference implementation to guide AI coding agents toward better architectural patterns and consistent code quality.

· 10 min read

Large language models often struggle with architectural consistency because they prioritize the most probable next token rather than your specific project patterns. To solve this, you can point at a reference implementation to provide the model with a concrete blueprint of your expectations. This technique moves beyond vague instructions and gives the AI a literal source of truth for file structure, naming conventions, and logic flow.

Why Technical Context Fails Without Examples

When you ask an AI coding agent to build a new feature, it relies on its training data. This data includes millions of public repositories with conflicting styles. Without a clear anchor, the agent might suggest a functional component when your project uses classes, or it might use a library that you have explicitly avoided.

Providing a reference implementation acts as a constraint. It narrows the search space for the model. Instead of wondering how to handle error states, the model looks at your existing code to see how you have already handled them. This reduces the need for repetitive prompting and manual refactoring after the code is generated.

Strategies to Point at a Reference Implementation

There are several ways to provide this context depending on the tool you use. The goal is always to make the reference code as visible as possible to the inference engine.

  1. File Path Reference: Simply telling the agent to look at a specific file path.
  2. Code Snippet Injection: Copying the relevant logic into the prompt buffer.
  3. Active Workspace Context: Keeping the reference file open in an active editor tab.
  4. Structural Outlining: Providing only the types or interfaces of a reference.

When you use coding agents, the effectiveness of the reference depends on how much of the file the agent can actually see. Many chat-based tools truncate files to save on token costs. This is why having a dedicated workspace where you can manage context is vital.

Using Deska for Contextual Reference

Deska provides a unique environment for this technique through its infinite canvas. Unlike traditional IDEs where files are hidden behind tabs, Deska allows you to place panels anywhere. You can have a reference implementation open in one Monaco editor panel while an AI agent works in a terminal panel right next to it.

This layout is not just visual. When you use Ask Deska, the assistant can perceive the state of your workspace. You can point at a reference implementation by literally having it visible on the canvas. Because Deska is local-first, your reference code stays on your machine and is only sent to the model of your choice via your own API keys.

Comparing Context Management Approaches

FeatureStandard IDE ChatDeska CanvasRAG Based Tools
VisibilityHidden in tabsSide by side panelsAbstracted in index
Direct ControlManual copy pasteVisual placementAutomated retrieval
PersistenceLost on tab closeSaved in workspacePersistent index
PrivacyVaries by pluginLocal-first storageOften cloud based

Implementation Patterns for AI Agents

To get the most out of this technique, follow specific patterns when pointing to your code. If you are building a new API endpoint, point to an existing, well-tested endpoint.

The Mirror Pattern

Ask the agent to create a new module that mirrors the structure of an existing one. For example, if you have a UserService.ts, tell the agent to create ProductService.ts using the former as a reference implementation. Specify that it should match the constructor patterns and the way dependencies are injected.

The Boilerplate Pattern

Keep a directory of empty but structured files. When you need a new component, point the agent to these boilerplate files. This ensures that every new piece of code starts with the correct imports and base configurations. You can keep these templates open in notes panels within Deska for quick reference.

Technical Constraints and Token Limits

While pointing at a reference implementation is powerful, you must be mindful of token limits. Large files can consume the entire context window of models like Claude or GPT-4. To mitigate this, consider these steps:

  • Strip comments and documentation from the reference if they are not needed for the logic.
  • Use interface definitions instead of full implementation bodies if you only need the agent to follow a specific type structure.
  • Use terminals to run scripts that extract relevant parts of your codebase into a temporary context file.

Deska helps manage this by allowing you to run multiple agent threads in parallel. You can have one agent analyzing the reference implementation while another applies those lessons to the new code. This modular approach prevents a single context window from becoming overloaded and messy.

FAQ

How do I point an AI to a specific file in my project?

You can mention the relative path clearly in your prompt or use tools that support file attachments. In a canvas environment, keeping the file open in an active panel often helps the assistant identify it as high priority context for the current task.

Does the reference implementation need to be perfect?

No, but it should be representative of the pattern you want to replicate. The AI will likely copy the flaws of the reference implementation as well as the strengths. If the reference is outdated, explicitly tell the agent which parts to ignore or update.

Can I use multiple reference implementations at once?

Yes, but it is often better to provide one primary reference to avoid confusing the model. If you use multiple references, clearly label what the agent should learn from each one. For example, use one file for styling and another for business logic.

Build Your Next Feature on Deska

Managing context is the most important skill for developers using AI. Deska offers an infinite canvas where you can organize your reference implementations, terminal sessions, and coding agents without the constraints of a traditional window manager.

Whether you are using Claude Code, Codex, or OpenCode, Deska provides the infrastructure to run them side by side in a local-first environment. This ensures your intellectual property remains secure while giving you the flexibility to build faster.

Download Deska for Mac, Windows, or Linux and start organizing your development workspace today.

💡 Ideas+🐛 BugsSuggest a feature or report a bug