ailiteracynepal 🇳🇵
Text size

Chapter 02 · Section II · 10 min read

Anchoring with paths and code

Every time you reference something specific — a file, a function, a symbol — write it in a form Claude Code can grab. Loose references cost tokens and turns. Tight references save them.

Claude Code is very good at working with things it can see. It is much less good at working with things you have described in the abstract. So a large part of prompting well is: whenever you mean a specific piece of the codebase, refer to it by a handle the tool can actually grab.

Paths are cheaper than descriptions

Compare:

Weak: “There is a function that formats the user’s name for the header — it needs to handle the case where the family name is missing.”

Strong: “In src/components/UserBadge.tsx, formatDisplayName() needs to handle the case where user.familyName is empty. Return just givenName in that case.”

Both prompts contain the same information. But the strong version gives Claude an exact file path and function name it can Read directly. The weak version forces it to grep — costing a couple of tool calls, and giving it the chance to guess wrong about which file you meant.

Rule of thumb: if you have the path in your head, put it in the prompt.

Line numbers are usually overkill

You do not need to say “line 47” — Claude reads the file. What you do want to give it is a stable identifier: the function name, the variable name, the CSS class, the SQL table. Names survive edits; line numbers do not.

When to paste code inline

Paste code into the prompt when:

  • The file is huge and you want Claude to focus on one specific chunk.
  • You are describing an intended change and want to show the “before” version.
  • You are asking about someone else’s code — a snippet from a PR review, a stack trace, an issue.

Do not paste code when it already lives in a file in the current repo. Give the path instead. Pasting is duplication, and duplicated content in the prompt eats context you might need for the reply.

Anchoring across a task, not just one prompt

For multi-turn work, anchor once and reuse. If you tell Claude “we’re working on src/api/notes.ts today” in the first message, subsequent messages can say “the createNote function” without qualification, and it will resolve correctly. This is one of the reasons a focused session outperforms a scatter-shot one.

Check your understanding

Quick check

You want Claude to change the return type of a specific TypeScript function. Which framing is best?