Claude Code Context Engineering: How to Give Claude the Right Information Every Time

David IyaDavid Iya September 7, 2026 10 min read
A tidy wooden desk at morning with an open notebook filled with handwritten diagrams and arrows, a mechanical pencil, a ceramic coffee cup with steam, and a single glowing monitor, warm golden editorial light
Original image, Claude Code Club

What Context Engineering Actually Means in Claude Code

Context engineering for Claude Code is the practice of deliberately deciding what the model reads before it starts any piece of work. Claude Code does not have persistent memory between sessions. It has a context window - a fixed amount of information it can hold at once - and every response it gives is based entirely on what is currently inside that window. Context engineering is the skill of making sure the right things are in that window at the right time.

That sounds simple, but in practice most people using Claude Code are doing the opposite. They open a session, type a request, and hope the model figures out where the relevant code lives. Sometimes it does. Often it makes an educated guess, touches the wrong file, and produces output that technically answers the question but breaks something else. Context engineering is the fix.

The Three Levers of Context in Claude Code

There are three things you actually control when it comes to Claude Code's context: what is in your CLAUDE.md file, which files you explicitly reference in your message, and how long you let a conversation run before starting fresh. Each one has a different time horizon - CLAUDE.md is permanent, file references are per-message, and conversation hygiene is per-session.

The three context levers and when each one matters

LeverWhat it doesWhen to use it
CLAUDE.mdLoads project-wide rules, constraints, and conventions at the start of every session automaticallySet it up once per project; update it when a rule changes
File referencesPoints Claude at the exact file or code block it needs instead of making it search or guessEvery time you ask Claude to edit, review, or extend specific code
Conversation hygieneControls how much prior conversation history is in the window - stale context causes driftStart a new session when a task is done or when Claude starts contradicting itself

These three levers cover almost every consistency problem people blame on the model. Claude Code is not being random when it touches the wrong file or forgets a constraint you mentioned six messages ago. It is working with the context it has. Engineering that context is your job.

Your CLAUDE.md File Is Your Most Important Context Investment

The CLAUDE.md file in your project root is the single most impactful thing you can add to any Claude Code project. It loads automatically at the start of every session and tells Claude Code the things that are always true about this project: the tech stack, the naming conventions, the folders it should never touch, the style rules you care about, and the constraints that must hold across every file it generates.

Without it, you are re-explaining your project from scratch every session. With it, Claude Code starts each session already knowing that your project uses TypeScript strict mode, that all components live in src/components, that you never want inline styles, and that the database schema lives in a specific migration folder. You stop correcting the same mistakes repeatedly.

  • List the tech stack and major dependencies so Claude Code never suggests an import from a library you are not using.
  • Name the folders that are off-limits or that have special rules - e.g. never edit migrations directly, always run them through the migration tool.
  • State the code style rules that matter to you: casing, file naming, how you handle errors, what the testing pattern is.
  • Include a short project description (one or two sentences) so Claude Code knows what the product is supposed to do when it makes architectural decisions.
  • Add a section for things Claude should always confirm before doing - dropping a table, making a schema change, touching a production config.

How to Reference Files Without Making Claude Hunt

When you type "update the auth handler" and Claude Code has 400 files to search through, it is doing pattern matching on filenames and directory names to find a candidate. Sometimes that is fine. But in a mature codebase with multiple files that touch authentication - middleware, a helper module, a routes file, a types file - it may pick the wrong one, make a change there, and not touch the one you needed.

The fix is to be specific about what you are pointing at. In the Claude Code desktop app, you can drag a file into the conversation or reference it by path. In a terminal session, you can paste the relevant code block. Either way, you are making the target unambiguous. Claude Code works best when the context contains the actual thing to be changed, not a description of where it might be found.

  • Reference the file path explicitly in your message when asking about a specific file - for example: "in src/lib/auth.ts, update the token refresh logic to..."
  • For a change that spans multiple files, name all of them in your message so Claude Code knows the full scope before it starts.
  • Paste the relevant function or block inline for small, targeted changes. This is faster than file search and keeps the context tight.
  • If you want Claude to understand the existing pattern before changing it, paste both the thing you are changing and a working example of the pattern to follow.

When to Start a Fresh Session

Every message you send and every response Claude Code gives adds to the conversation history in the context window. Early in a session that history is useful - Claude can refer back to decisions you made two messages ago. Late in a long session, that same history starts to crowd out the code it actually needs to work with, and the model starts reflecting earlier context more than recent instructions.

The signal that it is time to start a new session is when Claude Code starts contradicting a constraint you set, generating code in a style you moved away from three tasks ago, or asking you to clarify something it got right earlier. That is not the model regressing. That is a full context window redistributing attention. The fix is a fresh session with your CLAUDE.md already loaded, a clean slate, and your current focus in the first message.

Context Engineering for Agents and Subagents

If you are running Claude Code in agent mode or dispatching subagents with the /agents command, context engineering becomes even more important because each subagent starts with its own context window and cannot share memory with the others mid-run. The information a subagent needs to do its job has to be passed to it explicitly in its task description.

This means your CLAUDE.md becomes the shared foundation - every subagent reads it at startup. Beyond that, each subagent task should include the specific files it will touch, the constraints that apply to its scope, and a clear deliverable. A subagent told "improve the checkout flow" will do something. A subagent told "in src/pages/checkout.tsx, update the payment form to show a loading state during submission, matching the pattern in src/components/Button.tsx" will do the right thing.

The Most Common Context Mistakes and How to Fix Them

Most inconsistency problems in Claude Code trace back to one of a small number of context mistakes. They are not hard to fix once you know what you are looking for.

Common context mistakes and their fixes

MistakeWhat it causesFix
No CLAUDE.mdClaude forgets your conventions between sessions and re-invents themAdd a CLAUDE.md with your stack, file structure, and key rules before the first session
Vague file referencesClaude picks the wrong file and makes changes that break something adjacentName the exact file path and function in your message
Sessions that run too longClaude starts reflecting early-session decisions over recent onesStart a new session when a major task is done; open with a summary
Giving Claude too many things at onceIt does all of them at a low quality instead of one wellOne clear task per message with explicit scope
No constraints on what NOT to touchClaude edits adjacent files it thinks are relatedSpecify in CLAUDE.md and per-message what is out of scope
Free Claude Code drops, straight to your inbox

Short, practical drops on skills, MCP, agents, prompts, and more. No spam, unsubscribe anytime.

Frequently asked questions

What is context engineering in Claude Code?

Context engineering is the practice of deliberately shaping what Claude Code reads before it acts - primarily through your CLAUDE.md file, explicit file references in each message, and conversation hygiene (knowing when to start a fresh session). The model can only work with what is in its context window, so controlling that input controls the quality of the output.

What should I put in my CLAUDE.md file for context engineering?

A short project description, the tech stack and major dependencies, the folder structure and any folders Claude should never touch, your code style rules, and a list of things Claude must confirm before doing. Keep it under 500 words - a long CLAUDE.md eats context budget that could go toward the actual code.

How do I reference specific files in Claude Code?

In the Claude Code desktop app you can drag a file into the conversation. In any session you can reference the file by its path in your message - for example, "in src/lib/auth.ts, update the refresh logic to..." For small changes, pasting the relevant code block directly into the message is faster and keeps the context tight.

When should I start a new Claude Code session?

Start a new session when a major task is complete, when Claude Code starts contradicting constraints you set earlier, or when its output style starts drifting. A full context window will redistribute attention across everything it holds - starting fresh with a summary of decisions made is more reliable than trying to correct drift mid-session.

Does context engineering matter for Claude Code subagents?

Yes, and it matters more than in a single session because each subagent starts with its own context window and cannot share memory with other subagents mid-run. Each task you give a subagent should include the specific files it will touch, the constraints on its scope, and a clear deliverable - not just a vague goal.

Last reviewed by David Iya on September 7, 2026

David Iya

Written by

David Iya

Forbes 30 Under 30 · Y Combinator

Keep reading

Claude CodeBuilding

How to Ship a Side Project With Claude Code in a Weekend

Most side projects die in the planning phase. You know the pattern: a good idea, a few evenings of half-started code, then nothing. Claude Code changes the math on this - not because it writes perfect code but because it removes the specific blockers that stop you shipping. Here is the exact sequence to go from idea to live URL in a weekend.

Duncan Rogoff 9 min
Read article
Claude CodeMCP

How to Connect Claude Code to Supabase With the Official MCP Server

Supabase runs its own hosted MCP server, so Claude Code can read your schema, write migrations, and run SQL against a real project without you copying anything between tabs. Here is the exact setup, the three settings that keep it from touching production it should not, and what actually broke the first time I wired it up.

David Iya 9 min
Read article

Ready to build it yourself?

Join Claude Code Club, the #1 community for learning claude code, for $9/month.

← Back to the blog