How to Give Claude Code Context — The Basics

You’ve probably noticed that Claude Code sometimes misses the mark — not because it’s bad at coding, but because it didn’t have enough information to make the right decisions. It’s like asking someone to write a speech for your best friend’s wedding without telling them anything about your friend. The result will be technically a speech. But it won’t be the right speech. Giving Claude Code good context is the single highest-leverage skill you can develop as a user.

This is part of our complete How Claude Code Works — A Beginner’s Deep Dive.


TL;DR

  • Context** is any information that helps Claude Code make better decisions for your specific project
  • There are four main types of context: project context, task context, constraint context, and example context
  • You can give context in your prompt, through a CLAUDE.md file, or using @-mentions
  • Better context = fewer back-and-forth corrections = faster results
  • You don’t need to give all context every time — learn what to include when

What Is “Context” and Why Does It Matter?

Context is the background information Claude Code needs to do its job well. Without it, Claude Code has to make guesses. Some of those guesses are good. Some are wrong. And wrong guesses mean extra rounds of correction.

Here’s a concrete example. Without context:


# Prompt with no context
Add a loading spinner to the form

Claude Code might add a spinner using CSS animations. But maybe your project uses a component that already exists. Or maybe your team uses a specific pattern for loading states. Without context, Claude Code doesn’t know.

With context:


# Same request but with context
Add a loading spinner to the form. We have a reusable <Spinner> component at
src/components/ui/Spinner.tsx. Use that. Follow the same pattern used in
src/components/LoginForm.tsx where we handle loading states.

Now Claude Code has everything it needs. It’ll use your existing component, match your existing pattern, and the result will fit right in.


The Four Types of Context

1. Project Context

Project context is the big picture: what your app does, what tech stack you’re using, and what conventions your team follows.

This type of context doesn’t change much and is best put in a CLAUDE.md file so you don’t have to repeat it every session.


# Example project context in CLAUDE.md
## About This Project
This is a SaaS B2B invoicing tool built for small accounting firms.
Users are accountants, not developers — the UI must be simple and error-proof.

## Tech Stack
- Next.js 14, TypeScript, Tailwind CSS
- Supabase for database and auth
- Stripe for payments
- Resend for transactional email

## Key Conventions
- All monetary values stored in cents (integers), displayed with formatCurrency() from src/utils/
- Error handling follows the Result pattern — see src/types/Result.ts
- All API routes validated with Zod schemas before processing

2. Task Context

Task context is specific to the thing you’re asking Claude Code to do right now. What problem exists? What does the current behavior look like? What should the behavior be after the change?


# Example of good task context in a prompt
The invoice total on the summary page (src/pages/invoices/[id].tsx) is showing
incorrect amounts when the invoice has more than 10 line items.

Current behavior: The total cuts off after 10 items and only sums those.
Expected behavior: The total should sum ALL line items regardless of how many there are.

I think the issue is in the calculateTotal() function in src/utils/invoiceCalculations.ts
but I'm not sure — check both files.

This is gold for Claude Code. It knows exactly what’s wrong, where to look, and what the right outcome is.

3. Constraint Context

Constraint context tells Claude Code what it can’t do, or what it must do in a specific way.


# Constraint context examples
"Don't add any new dependencies — use only what's in package.json."
"Keep backward compatibility — the existing API response shape must not change."
"This function runs on the edge runtime — no Node.js-specific APIs."
"Match the existing error handling style — look at how LoginForm.tsx does it."

Constraint context prevents Claude Code from going rogue with technically correct but practically wrong solutions.

4. Example Context

Example context is showing Claude Code something that already works the way you want the new thing to work.


# Pointing Claude Code to an existing example
Implement the delete functionality for invoices. Follow the exact same pattern
used for the delete functionality in src/features/clients/ — same confirmation
modal, same optimistic update, same error handling.

This is one of the most effective context techniques. Claude Code is very good at matching patterns. When you point it at a working example in your own codebase, it will produce code that fits naturally.


Step 1: Set Up Permanent Context With CLAUDE.md

The most efficient thing you can do is put your project context somewhere Claude Code reads automatically — the CLAUDE.md file in your project root.


# Creating CLAUDE.md in your project root
touch CLAUDE.md

Then fill it out. Here’s a solid template:


# CLAUDE.md — permanent context for every Claude Code session

## Project Overview
[One paragraph describing what this app does and who uses it]

## Tech Stack
[List of key technologies, frameworks, libraries, and versions]

## Project Structure
[Brief description of where things live — key folders and their purpose]

## Code Conventions
[Naming conventions, patterns your team uses, things to do consistently]

## Constraints
[Things Claude Code should never do, libraries not to use, files not to touch]

## Key Files to Know About
[Any important utility files, types, or shared components Claude Code should be aware of]

Every time you start a Claude Code session, it reads this file first. Your context is always there without you having to repeat it.

💡 Pro Tip: Treat CLAUDE.md as a living document. Every time you give Claude Code a correction that starts with “No, we don’t do it that way — we do it like this,” add that information to CLAUDE.md so you never have to say it again.


Step 2: Use @-Mentions to Pull in Specific Files

When your task involves a specific file, the fastest way to give Claude Code that context is to use @-mentions. Type @ followed by a file name and Claude Code will read that file as part of your prompt.


# Using @-mention to reference a specific file
Look at @src/utils/invoiceCalculations.ts and add a calculateTax() function
that follows the same pattern as calculateTotal().

This is more reliable than describing a file — Claude Code reads the actual code, not your description of it. Full details at How to Use @-Mentions in Claude Code.


Step 3: Give Context Inline When It’s Task-Specific

For one-off tasks, the fastest method is just including the context directly in your prompt. There’s no need to add everything to CLAUDE.md — some context only matters for a single task.

Here’s a before/after showing the difference:

Before (no context):


# Prompt without context
Fix the date display bug

After (with context):


# Same prompt with useful context added
Fix the date display bug in the InvoiceDueDate component
(src/components/invoices/InvoiceDueDate.tsx).

The date is showing one day behind in timezones west of UTC. For example,
a due date of March 15 shows as March 14 for users in New York.

We're using date-fns for date handling. Don't switch to a different library.
The fix should be in the component itself, not in the database layer.

The second prompt will produce a correct fix. The first prompt might produce something that technically changes dates but doesn’t address the timezone issue at all.


Step 4: Give Context About Your Users, Not Just Your Code

This one’s easy to forget, but it matters. Claude Code makes decisions about code that will be experienced by real people. When it knows who those people are, it makes better decisions.


# User context that shapes Claude Code's decisions
Our users are non-technical accountants in their 50s and 60s.
Error messages need to be in plain English — no technical jargon.
Form validation errors should tell users exactly what to fix, not just that something is wrong.

Versus:


# More technical user context
Our users are developers integrating via API.
Error responses should follow RFC 7807 Problem Details format.
Include error codes that can be looked up in our documentation.

Same task, completely different right answer. User context makes the difference.


Step 5: Confirm Claude Code Has the Right Context

After Claude Code reads your prompt but before it writes code, it sometimes summarizes what it understood. Read that summary. If something is off, correct it immediately.


# Claude Code confirming its understanding — read this carefully
I understand you want me to:
1. Add a calculateTax() function to src/utils/invoiceCalculations.ts
2. It should handle US sales tax only (based on the existing code style)
3. Follow the same pattern as calculateTotal()

Is that right before I proceed?

If the summary is wrong:


# Correcting Claude Code's understanding before it writes code
Almost — a couple of corrections:
1. It needs to handle both US sales tax AND Canadian GST/HST
2. The tax rates come from the database, not hardcoded — look at how we fetch
   product categories in src/api/products.js for the pattern to follow

Catching misunderstandings before Claude Code writes code is much easier than fixing them after.


Common Mistakes and How to Fix Them

Mistake 1: Giving Too Little Context

Problem: Short, vague prompts that leave Claude Code guessing — and guessing wrong.

Fix: Before sending a prompt, ask yourself: “If I sent this to a new developer, would they know exactly what to do?” If not, add more context.

Mistake 2: Describing What You Want Instead of Showing It

Problem: You write a long description of the pattern you want, when you could just point to an existing example.

Fix: “Follow the same pattern as X” is often more effective than three paragraphs explaining the pattern. Use @-mentions to point at real code.

Mistake 3: Not Updating CLAUDE.md After Learning Something

Problem: You correct Claude Code about your project’s conventions repeatedly across different sessions.

Fix: Every correction you make more than once belongs in CLAUDE.md. Add it once, never repeat it.

Mistake 4: Assuming Claude Code Knows Your Business Logic

Problem: You ask Claude Code to “update the pricing logic” but your pricing logic depends on customer tiers, annual vs. monthly billing, and promotional codes — none of which are obvious from the code.

Fix: Spell out business rules explicitly. Code doesn’t always make business logic obvious. You have the context; Claude Code doesn’t.

Mistake 5: Context Overload

Problem: You paste 500 lines of context into every prompt, most of which isn’t relevant to the task at hand.

Fix: Give relevant context, not all context. If you’re fixing a date bug, the tax calculation code probably doesn’t need to be in the context. Focused context helps Claude Code focus.

⚠️ Warning: Every piece of context you include uses up tokens — part of Claude Code’s working memory. For very large tasks, pasting irrelevant context can push out context that actually matters. When in doubt, include context that’s directly related to the task.


Key Takeaways

  • Context is any information that helps Claude Code make better decisions for your specific project
  • There are four types: project, task, constraint, and example context
  • CLAUDE.md handles permanent context so you don’t repeat yourself every session
  • @-mentions are the fastest way to give Claude Code access to a specific file
  • Better context means fewer corrections, faster results, and code that actually fits your project

Next Steps

Return to How Claude Code Works — A Beginner’s Deep Dive for the full picture.