Targeting the Proper Context with Claude Code

Targeting the proper context means giving Claude Code only what it needs. Use file and selection scope plus fast at-mentions to assemble precise prompts.

Choose the right scope

  • Whole file: Open the file and prompt—Claude reads it automatically.
  • Selection: Highlight a block; the prompt scopes to only those lines.
  • Multi-file: Build context by adding several files/selections to the same prompt.

Two fast targeting workflows

  1. At-mention with @
    Type @ in the Claude prompt to fuzzy-find any file/dir and insert it into your message.

  2. Editor-first + Insert At-Mentioned

  • Cmd/Ctrl+P to open a file quickly
  • Trigger Insert At-Mentioned to add that file/selection to the prompt
  • Repeat to build multi-file context

Tip: Bind Insert At-Mentioned to a convenient key (e.g., Option+T) for rapid multi-file assembling.

Try it

Prompts:

Summarize these two files and identify cross-cutting concerns.
Only update the selected function to remove duplication.
Claude Code Essentials
Lesson 2 of 17

Claude Code Essentials

Learn the fundamentals of Claude Code as well as tips and tricks for optimized workflows using the CLI in conjunction with your favorite editor.

Share with a coworker

Transcript

[00:00] Type the at sign and then you can fuzzy search for any file to include that in the context of your current conversation. This also works with directories if we want to include the source directory, or you can navigate down the directories doing search as normal. When you find the file you want, hit enter. It will complete the entire path to the file, and then add a space. So you're essentially telling Cloud to read these files as part of the prompt.

[00:23] Now this does support fuzzy search, so you can type JSON and navigate up and down to the file you want, or at tsx, and then you can even type the name of the file after tsx like wordlist, hit enter, and it will expand it. Or part of the path, so at lib, then you can select that, backspace, and invoke the search again, and type out store to quickly navigate to files inside of directories. Then currently the quickest way to clear out a file you've added is just ctrl-w to delete word. Since I'm much more proficient with using cursor to explore files, I like to update this command to option-t or alt-t, and then with command-p when I'm browsing files where I can type things like lib and then store to get this true fuzzy matching, then hit enter and then option T will add the file to the cloud input. Then I can invoke another search.

[01:17] I'll search for components, and then select, hit enter, option T, and bring in files that way. So for me the cursor navigation and cursor search is just far superior, because I'm often thinking in directory and file name, or even something like subscription store where I want to match on partials of the word to filter them out, since so many files usually have consistent naming patterns. And one thing to note here, if you're ever focused over in your editor and you want to jump focus over to this panel, Command 1 will focus on the editors on the left. Command 2 will focus on the second one. And say if we hit Command T again to open another session, Command 2 will jump back here, and Command 3 over here, 2, 1, and it becomes much easier just to jump between editor, clod sessions, and so forth.

[02:03] So I can jump to 3 with command 3, hit command W, close that out, and manage our sessions like that. Now an important thing to note here is if I say something like, please summarize all of these files, and let this run, you'll see it'll start to read each of the files, because they're automatically brought into context. But as an example, if I clear out this session, which essentially starts a brand new session, and I reference a much longer file like package lock, and I say please summarize this file, you'll see that approach it'll take, instead of immediately invoking read, it will attempt to read it in chunks, so reading 100 lines at a time. And you can hit ctrl-o to see exactly what it's doing. Since ctrl-o shows the detailed transcript, You can see the commands it's running and Ctrl-O to go back.

[02:49] But something I'll do often if I want to force multiple large files and context is to use a tool called RepoMix. Now you'll see if I start a new terminal and I run RepoMix help, You'll see we have a lot of options here. The important ones are going to be repo mix include, and I'm going to include the entire source directory, and then standard out to make sure it's all printed out in the terminal, to make sure the contents of all the files are printed out the terminal. So once I hit enter and I scroll back up you will see all of the files and all of their contents. Now if I run the same command with output show line numbers this time we'll get all the contents with all of their line numbers.

[03:29] And this way we can force everything in a directory into context. So I'll clear this out. I'll type to enter command mode, type repo mix, include, source, then standard out, and output, show line numbers, hit enter, And now all of this was forced into context. If we hit Ctrl-O, you can see the entire context which was brought in. Ctrl-O will toggle back.

[03:53] And now if I say summarize all of these files, you'll see it no longer has to read individual files, and it doesn't have to read them 100 lines at a time. You forced all of that context into Cloud to save all of that time it would have had to use searching and reading, which makes a lot of larger tasks like this much faster at the cost of adding a lot of context up front. So even though this video you're watching was edited, that prompt literally only took about three seconds to run.