Claude Code Context References
What are Context References?
Context references are special symbols you use in your prompts to tell Claude Code exactly what files, folders, or information to pay attention to. Think of them as pointing Claude to specific parts of your project.
Why use them? When you reference specific files or folders, Claude Code can:
- Read and understand the exact content you're referring to
- Generate code that follows your existing patterns
- Make changes that are consistent with your project structure
- Avoid making assumptions about your requirements
The "@" Symbol - File and Folder References
What does "@" do?
The @ symbol lets you attach files or folders to your prompt. When you use @, Claude Code reads the content and uses it as context for understanding your request.
Basic Usage
Reference a single file:
@LOGIN_FLOW.md Create a test based on this login flowReference multiple files:
@auth.fixture.ts @login.spec.ts Update the fixture to match the test requirementsReference a folder:
@tests/ Review all test files and identify duplicate codeReference specific code files:
@src/components/LoginForm.tsx Create a test for this componentCommon Use Cases
1. Using Documentation Files
Scenario: You have a markdown file documenting a process, and you want Claude to follow it.
Example:
@API_DOCS.md Generate integration tests for all the endpoints described in this documentationWhat happens:
- Claude reads the API_DOCS.md file
- Understands the endpoint specifications
- Generates tests that match the documented behavior
2. Analyzing Existing Code
Scenario: You want Claude to understand your existing code before making changes.
Example:
@src/utils/auth.ts This utility has a bug when handling expired tokens. Can you fix it?What happens:
- Claude reads the auth.ts file
- Analyzes the code structure
- Identifies and fixes the token expiration logic
3. Maintaining Consistency
Scenario: You want new code to follow the same patterns as existing code.
Example:
@tests/user.spec.ts Create a similar test file for the product feature, following the same structure and naming conventionsWhat happens:
- Claude reads your existing test file
- Understands the patterns, structure, and style
- Creates a new test file that matches your conventions
4. Working with Multiple Files
Scenario: You need to update several related files at once.
Example:
@src/Login.tsx @tests/Login.spec.ts @fixtures/auth.fixture.ts
Add a "Remember Me" checkbox to the login form and update the tests and fixture accordinglyWhat happens:
- Claude reads all three files
- Understands how they work together
- Makes coordinated changes across all files
5. Exploring Folders
Scenario: You want Claude to understand an entire section of your codebase.
Example:
@src/components/ Analyze all components and create a component testing strategy documentWhat happens:
- Claude scans all files in the components folder
- Understands the component architecture
- Creates a comprehensive testing strategy
Best Practices
Be Specific
Less effective:
Create a login testMore effective:
@LOGIN_FLOW.md @tests/fixtures/auth.fixture.ts
Create a login test that follows the documented flow and uses the existing fixtureWhy? The specific references give Claude exact context, reducing ambiguity and improving results.
Reference Related Files
When making changes, reference all files that might be affected:
@src/api/users.ts @tests/api/users.spec.ts @types/User.ts
Add a new field 'phoneNumber' to the User type and update the API and testsWhy? This helps Claude understand dependencies and make consistent changes.
Use Documentation Files
If you have design docs, flow diagrams, or requirement documents:
@docs/REQUIREMENTS.md @docs/USER_FLOW.md
Implement the user registration feature following these requirements and flowWhy? Documentation files provide Claude with business context and requirements.
Reference Configuration Files
When setting up or modifying project configuration:
@playwright.config.ts @package.json
Add a new test script that runs only the smoke tests in headless modeWhy? Configuration files show Claude your project setup and available options.
Combining "@" with Other Features
With Slash Commands
You can use context references alongside slash commands:
/mcp
@tests/fixtures/auth.fixture.ts
Now that MCP is verified, help me debug why this fixture isn't workingWith Natural Language
Context references work naturally in sentences:
Based on @LOGIN_FLOW.md, I need to update @tests/login.spec.ts to handle the new 2FA requirementTips for Success
Start Broad, Then Narrow:
- First, reference high-level documentation
- Then reference specific implementation files
- Finally, ask for precise changes
Example progression:
Step 1: @README.md Tell me about this project
Step 2: @src/ Show me the main components
Step 3: @src/Login.tsx Help me add validation to this formReference Before Requesting:
Always reference files before asking Claude to modify them:
@src/utils/validation.ts Add email format validation to this utilityInstead of:
Add email validation to validation.ts ❌ (Claude might not have the file context)Use Tab Completion:
In most IDEs, typing @ will show you a list of files you can reference. Use arrow keys and Enter to select.
Quick Reference Table
| Symbol | Purpose | Example |
|---|---|---|
@filename.ext | Reference a single file | @auth.ts |
@folder/ | Reference a folder | @tests/ |
@path/to/file.ext | Reference with path | @src/utils/auth.ts |
Multiple @ | Reference multiple items | @file1.ts @file2.ts |
Common Patterns
Pattern 1: Documentation-Driven Development
@REQUIREMENTS.md @DESIGN.md Implement the feature described in these documentsPattern 2: Test-Driven Development
@tests/feature.spec.ts Implement the code to make these tests passPattern 3: Refactoring
@src/old-feature.ts @docs/new-architecture.md
Refactor this code to match the new architecturePattern 4: Bug Fixing
@src/buggy-component.ts @tests/bug-reproduction.spec.ts
Fix the bug demonstrated by this testPattern 5: Code Review
@src/pull-request-changes.ts Review this code and suggest improvementsNext Steps
Now that you understand context references:
- Practice using
@in your prompts throughout the workshop - Experiment with referencing different types of files
- Observe how Claude's responses improve with better context
- Combine context references with slash commands for powerful workflows
Pro Tip
The more specific context you provide with @, the better Claude Code can understand and assist with your exact needs. When in doubt, reference the file!