All articles

Use @ File Mentions Instead of Copy-Paste

It is tempting to copy a chunk of code into the prompt when you want Claude to look at it. Skip that. Type @ followed by the path, and Claude reads the actual file from disk.

Why does @lib/db.js reset the connection promise on failure?

As you type @, Claude Code offers path completions, so you can find files without remembering the exact name. Claude reads the file before it answers, so it works from what is really there.

Why this beats copy-paste:

  • It is always current. A pasted snippet is a snapshot that goes stale the moment the file changes. An @ mention reads the live version every time.
  • It keeps the context. Pasting a function strips away its imports and the code around it. Claude reads the whole file, so it sees how the piece fits.
  • It is less error-prone. No half-copied blocks, no missing lines, no mangled indentation.
  • You can reference several at once. "Compare @lib/articles.js and @lib/serialize.js" points at both in one line.

Mentions are not limited to source files. You can point at config, docs, logs you have saved, or a data file. Anything on disk that Claude can read is fair game.

A natural pattern is to combine a mention with a specific instruction:

Refactor the duplicated validation in @app/api/comments/route.js
into a helper, and use it in @app/api/articles/route.js too.

Claude reads both files, finds the duplication, and works from the real code. You spend your effort describing the change instead of shuttling text into the prompt. Once this becomes a habit, copy-pasting code into a chat starts to feel like the slow, fragile way it always was.

Comments

Be the first to comment.