917 words Slides

3.1 File References with @

Course: Claude Code - Essentials Section: Basic Input & Interaction Video Length: 2-5 minutes Presenter: Daniel Treasure


Opening Hook

"Show me this one file" is more powerful than you'd think. With the @ symbol, you can give Claude instant context about specific files or folders—without copying-pasting code. It's the fastest way to focus Claude's attention.


Key Talking Points

  1. @ Syntax: Three Flavors
  2. @filename - reference by fuzzy match (fastest for simple cases)
  3. @path/to/file - explicit path reference
  4. @directory/ - show entire folder structure and file list

  5. Fuzzy Matching Magic

  6. Type @auth → matches auth.js, AuthService.ts, authenticate.py
  7. No need for full path; Claude shows what it matched
  8. Case-sensitive on first character: @Auth won't match auth.js

  9. Line Range References (VS Code & JetBrains IDEs)

  10. @app.ts#5-10 - specific lines only
  11. Use Alt+K (Option+K on Mac) shortcut to auto-insert with selected lines
  12. Reduces context bloat when only one function matters
  13. Example: Instead of referencing 500-line file, pull just lines 150-175

  14. Directory Context

  15. @src/components/ - show Claude the full folder structure
  16. Use cases: understand patterns, spot inconsistencies, refactor groups of files
  17. Be careful with large directories (saves context; respect .gitignore by default)

  18. MCP Resources (Advanced - requires MCP setup)

  19. @server:protocol://resource/path - pull from external systems
  20. Real example: @github:issue://456 fetches live GitHub issue
  21. Real example: @postgres:schema://users queries database schema
  22. Real example: @docs:file://api/authentication pulls doc server content

Demo Plan

Live Session Walkthrough (2-3 minutes):

  1. Setup bash cd /path/to/sample-project claude

  2. Demo @ File Reference (30 seconds)

  3. Type: @app.js (or similar file in project)
  4. Say: "Claude, what does this function do?"
  5. Point out: Claude has full file context instantly
  6. Call out the fuzzy match working

  7. Demo @ Directory Reference (30 seconds)

  8. Type: @src/utils/ (or appropriate folder)
  9. Say: "What patterns do you see in this folder?"
  10. Show Claude responding with insights across all files in directory

  11. Demo Line Range (30 seconds, if in VS Code)

  12. Show file with multiple functions
  13. Demo Alt+K shortcut to select lines 10-25
  14. Result: @file.ts#10-25
  15. Ask Claude to refactor just that function

  16. Demo File + File (Optional, 30 seconds)

  17. Reference two related files: @auth.js @user.ts
  18. Ask: "how do these work together?"
  19. Show Claude explaining the interaction between files

Code Examples & Commands

Basic @ References

# Fuzzy match by filename
@auth explain how login works

# Explicit path
@src/models/User.ts show me the User schema

# Directory
@config/ what configuration options are available?

# Line range (VS Code/JetBrains)
@middleware.ts#15-35 refactor this to use async/await

# PDF files (with page ranges)
@docs/api.pdf#1 summarize this API documentation
@docs/spec.pdf#5-10 explain pages 5-10

Real-World Workflows

# Ask about a specific module
@Logger is this thread-safe?

# Find issues across files
@services/ there's a memory leak; find it

# Review naming patterns
@components/ these React components have inconsistent styles

# MCP integration (with GitHub configured)
Can you implement this? @github:issue://456
# Claude pulls live issue data and implements solution

# MCP integration (with database)
@postgres:schema://users design a query to find inactive accounts

Gotchas & Tips

  1. Gotcha: Fuzzy matching is case-sensitive for first char
  2. @Auth will not match auth.js
  3. Use lowercase @auth or full path @src/auth.js

  4. Gotcha: @ on large directories loads all files

  5. @src/ on a monorepo = huge context
  6. Better: @src/components/buttons/ for specific subset
  7. Respects .gitignore by default (unless you configure otherwise)

  8. Tip: @ at the start of your message

  9. Good: @auth.js what does this do?
  10. Less clean: What does @auth.js do?
  11. Claude reads @ first, loads context, then processes question

  12. Tip: Line ranges save massive context

  13. 1000-line file = 1000 lines of context
  14. @file.ts#200-220 = 20 lines (and focused)
  15. Use this constantly for large files

  16. Tip: Use multiple files in one message

  17. @auth.js @middleware.ts @user.ts how do these interact?
  18. Claude sees all three and explains relationships
  19. More efficient than asking separately

  20. Tip: Use @ in CLAUDE.md and skills

  21. In .claude/CLAUDE.md: See @README for project overview and @package.json for scripts
  22. In skills: @.claude/rules/security.md to auto-load rules
  23. Keeps context modular and reusable

  24. Gotcha: MCP resources require setup

  25. @github: syntax only works if GitHub MCP server configured
  26. Run /mcp in session to check what's available
  27. New users won't have MCP servers by default (advanced feature)

  28. Gotcha: .gitignore respected by default

  29. .env, node_modules/, build artifacts ignored by default
  30. If you need to reference ignored files: use absolute path or check respectGitignore setting
  31. This is a good security default (don't leak secrets)

Lead-out

Now you can point Claude at specific files with laser focus. Next up: slash commands. These are shortcuts that trigger actions without full prompts—like /help, /clear, and custom commands you can create. They're the glue that ties everything together into a faster workflow.


Reference URLs

  • Official Docs - File References: https://code.claude.com/docs/en/vs-code (section: "Using @-Mentions")
  • Official Docs - MCP Resources: https://code.claude.com/docs/en/mcp (section: "Use MCP Resources")
  • Official Docs - Settings (respectGitignore): https://code.claude.com/docs/en/settings (search: "respectGitignore")

Prep Reading

  • Recent Articles: "10 Claude Code Productivity Tips" - emphasizes @ mentions as time-saver
  • Official: VS Code Integration docs, "Using @-Mentions" section
  • Official: MCP docs, "Use MCP Resources" section