Topic 2 of 5 · 3 min read
Pointing the agent at files and examples
Goal: Add file paths and a reference implementation to an instruction so the agent follows the codebase's existing patterns.
Name the files to start from, point at one existing implementation to copy the style of, and say where the agent may and may not edit.
Check yourself · 1 of 3
What is the main benefit of linking an existing implementation in your instruction?
Why it matters
An agent can search a repository, but searching costs time and can go wrong. In a large codebase it may find an older, deprecated module and imitate that. It may invent a new pattern when the project already has one. Pointing at the right files removes both risks. This is the cheapest improvement you can make to an instruction.
How to do it
- Give the entry points. The route file, the component, the failing test. "Start in
src/routes/orders.tsandsrc/services/orderService.ts." - Link a reference implementation. "Follow the structure of
src/services/invoiceService.tsand its test." One good example teaches naming, error handling and test layout together. In most tools you can attach a file by path, with@src/services/invoiceService.tsin Claude Code or Cursor, or by opening it in Copilot's editor. - Limit the edit area. "Edit only files under
src/services/andtests/services/." If a change elsewhere seems needed, tell the agent to stop and ask. - Mark off-limits files. Generated code, lockfiles, vendored libraries, migrations already applied.
- Say which docs to trust. If an old design document is wrong, say so.
Before and after
Weak:
Add a refund endpoint.
Better:
Add POST /orders/:id/refund.
Start in src/routes/orders.ts and src/services/orderService.ts.
Follow the pattern of the cancel endpoint (cancelOrder in orderService.ts and its test in tests/orders/cancel.test.ts): same validation helper, same error classes, same response shape.
Edit only src/routes/orders.ts, src/services/orderService.ts and tests/orders/. Do not touch src/legacy/ (deprecated) or any generated file under src/gen/.
The agent now reads three files instead of guessing among two hundred, and the diff has a clear boundary to check.
What goes wrong
- Pointing at the wrong example. If the reference is old or inconsistent, the agent copies its flaws. Pick the best-kept example, not the nearest one.
- Paths that no longer exist. A stale path in a standing file sends the agent searching or inventing. Keep it current.
- Pasting whole files. Dumping ten large files into the prompt buries the part that matters. Name them and let the agent open what it needs.
- No edit boundary. Without one, a small feature can turn into a cross-repo change that is hard to review.
Examples
Reference implementation in one line
Instruction: Add a listRefunds service function. Follow listInvoices in src/services/invoiceService.ts: same pagination helper, same error classes, same test layout in tests/services/invoice.test.ts.
The agent inherits the project's real conventions without you listing each one.
An edit boundary with an escape hatch
Instruction: Edit only files under src/billing/. If a change outside that folder seems necessary, stop and tell me which file and why, instead of making it.
The escape hatch keeps the agent from either breaking the rule or getting stuck.
Key points
- Name the entry-point files so the agent starts where the work is, not in a search.
- Point at one well-kept existing implementation to copy naming, errors and test layout.
- Say where the agent may edit and where it may not, including generated and deprecated code.
- Attach or name files rather than pasting large amounts of code into the prompt.
- Choose the reference carefully; the agent will copy its flaws as faithfully as its strengths.
Common mistakes
- Giving no paths and hoping the agent finds the right module in a large repository.
- Pointing at a deprecated or messy file as the example, so the agent copies its problems.
- Pasting many long files into the prompt instead of naming them, which hides the relevant part.
- Setting no edit boundary, so a small task becomes a wide diff that is hard to review.
Check yourself · 2 of 3
Which instruction best limits where an agent may edit?
Check yourself · 3 of 3
Your reference implementation file is an old module with known bugs. What is the risk of pointing the agent at it?
Practice items, not counted towards your mastery.
Start here
- Best practices for Claude Code (Claude Code docs) (opens in a new tab)DocsFree
A vendor's own advice: give the agent a way to verify its work, name files and explore before coding.
- Best practices for using GitHub Copilot (opens in a new tab)DocsFree
Guidance on writing clear prompts, breaking tasks down and giving context to a coding assistant.
- AGENTS.md (opens in a new tab)DocsFree
The open convention for a standing instruction file that coding agents read before each task.