Guide · Claude Code

How to give Claude Code context about your project

Claude Code reads CLAUDE.md, remembers notes you mark with #, and calls any MCP server you add. Each one carries a different kind of context and breaks in a different place. Here are the four ways to give Claude Code project context, from a markdown file to a knowledge base it can query for the spec, the data model, and the tests.

Updated 9 minute readApplies to Claude Code CLI, desktop app, and IDE extensions

Why Claude Code builds the wrong thing

The failure looks like this. You ask Claude Code to add a plan gate to the billing page. It reads the code, finds a customer object, and writes a check on customer.tier. There is no tier. The entity has plan_id. The spec that says so is in Notion, or in a Slack thread, or in your head. Claude never had it.

Claude Code builds from what is in its context window: the files it opened, the instructions it loaded, whatever you typed or pasted. Everything else is inference. Giving Claude Code context about your project means deciding where the truth about the product lives and how Claude reaches it on every session, not only the one where you remembered to paste.

There are four ways to do that. The first three hold instructions and access. Only the fourth holds the spec itself.

  1. 01

    CLAUDE.md

    Standing instructions: commands, conventions, what not to touch.

  2. 02

    Memory

    Facts Claude learns as you work, saved with # or automatically.

  3. 03

    MCP server

    A live source Claude queries mid-task instead of reading up front.

  4. 04

    ContextsBase over MCP

    The spec, data model, and test cases themselves, published.

Method 1

CLAUDE.md at the repo root and in nested folders

CLAUDE.md is the file Claude Code reads before it does anything else. Put one at the repository root and it loads at the start of every session in that project. Claude Code also checks parent directories, and ~/.claude/CLAUDE.md for instructions you want in every project. Run /init inside Claude Code to scaffold a first version from your codebase.

CLAUDE.md
# Project
Next.js 14 app router, TypeScript, Tailwind. Package manager is pnpm.

# Commands
- pnpm dev        starts the app on :3000
- pnpm test       unit tests
- pnpm e2e        Playwright, run before every PR

# Conventions
- Server components by default. Add "use client" only for event handlers.
- Never edit src/generated. Regenerate with pnpm codegen.

# Where things live
- Auth: src/lib/auth.ts   Billing: src/lib/stripe.ts
- Product specs: pulled from the contextsbase MCP server, not this file.

@docs/architecture.md
Commands, conventions, and pointers. The last line is an @path import, which pulls another file into context. Note the spec line: it points at a server, not at prose.

Nested CLAUDE.md files

A CLAUDE.md inside src/billing/ or packages/api/ is loaded when Claude starts reading or editing files in that folder. Use nested files for rules that only apply there. Keep the root file about the whole repo. For personal notes that should not be committed, use CLAUDE.local.md, which Claude Code reads alongside the shared file.

src/billing/CLAUDE.md
# src/billing
- Plans are free and premium. The column is users.plan_id.
  There is no tier field. Do not add one.
- Never call Stripe from a component. Go through lib/billing.
- Money is integer cents. Never a float.
Scoped rules load only when Claude works in this folder. This is the right size: a few lines that would otherwise be guessed.

Works for

  • Build, test, and run commands Claude should use instead of guessing.
  • Conventions and hard rules: never touch this folder, always run that check.
  • Pointers to the files that matter, so Claude does not search for them.

Where it breaks

  • It is prose. A data model described in a paragraph is something Claude paraphrases, not something it can check a field against.
  • Every line is loaded every session. Long files get trimmed, and trimmed files go stale.
  • Nested files load only when Claude touches that folder. Rules about a feature that spans folders fall through.
  • Nothing records what Claude built against it. When the file changes, nobody knows which code is now out of date.

Method 2

The # shortcut and auto-memory

Start any message with # and Claude Code treats it as something to remember rather than an instruction for the current task. It asks which memory file the note belongs in, so a repo convention lands in the shared CLAUDE.md and a personal preference lands in your own notes.

claude
you › # We use pnpm, never npm. Playwright tests live in e2e/, not tests/.

  Where should this be saved?
  › Project memory (./CLAUDE.md)         shared with the team
    Local project memory (./CLAUDE.local.md)   just you, gitignored
    User memory (~/.claude/CLAUDE.md)     every project on this machine

✓ Saved to ./CLAUDE.md
The # shortcut is the fastest way to grow CLAUDE.md without leaving the session. Pick the project file for anything a teammate should also know.

Claude Code also keeps an auto-memory directory per project under ~/.claude/projects/. As you work, it writes down facts it learns, one file per fact, with a MEMORY.md index that loads at the start of each session. You can read and edit these files directly. They are plain markdown.

Works for

  • Corrections you would otherwise repeat: package manager, test location, branch naming.
  • Decisions made in conversation that should survive the session.
  • Preferences about how you like work reported or reviewed.

Where it breaks

  • Auto-memory is per user and per machine. Your teammate's Claude Code has never seen your notes.
  • It captures what Claude noticed, not what the product owner decided. The spec is still elsewhere.
  • Facts accumulate with no structure. There is no entity, no field list, no test case, just lines of text.

Method 3

claude mcp add with an HTTP MCP server

Model Context Protocol (MCP) is how Claude Code talks to outside systems. An MCP server exposes tools Claude can call mid-task. Instead of reading a description of your project up front, Claude asks a question at the moment it needs the answer. Adding a remote server over HTTP is one command:

terminal
claude mcp add --transport http contextsbase https://app.contextsbase.com/api/v1/mcp \
  --header "Authorization: Bearer mcp_live_••••••••••••••••••••••••"
The token is redacted. Tokens start with mcp_live_. Run /mcp inside a session to confirm the server connected and to list its tools.

By default the server is saved for you in this project only. Add --scope project to write it into a shared .mcp.json at the repository root, which is what you want for a team. Claude Code expands environment variables in that file, so the token never touches git:

.mcp.json
{
  "mcpServers": {
    "contextsbase": {
      "type": "http",
      "url": "https://app.contextsbase.com/api/v1/mcp",
      "headers": { "Authorization": "Bearer ${CONTEXTSBASE_TOKEN}" }
    }
  }
}
Commit this file. Each teammate sets CONTEXTSBASE_TOKEN in their shell, and Claude Code asks once before trusting a project-scoped server.

What a generic MCP server gives you

Most MCP servers are adapters: a Postgres server, a Notion server, a GitHub server, a filesystem server. They give Claude access to a system it could not otherwise reach. That is real progress over pasting, but access is not structure. Claude can now search your Notion. It still has to work out which of the four pages called “Password reset” is the current one.

Works for

  • Live data Claude should query rather than memorise: schema, tickets, documents.
  • Anything too large or too changeable for CLAUDE.md.
  • Sharing one connection with the whole team through .mcp.json.

Where it breaks

  • A document server returns documents. Nothing marks one as the published spec and another as a draft.
  • A database server returns tables, not the business rules that decide what goes in them.
  • Nothing records what Claude built from what it read, so a later edit to the source changes nothing downstream.

Method 4

A structured knowledge base over MCP with ContextsBase

Method 4 is method 3 with the right thing on the other end. ContextsBase is an MCP server whose contents are the spec itself: features with business rules, entities with fields and foreign keys, flows, and test cases written as Given / When / Then, ordered into iterations. You publish them once. Claude Code pulls exactly the one it is working on, builds it, runs the tests, and records what it did against which version of the spec. It connects with the same claude mcp add command from method 3.

  • Publish a feature, its entities, and its tests. Functionality, business rules, edge cases. The entities it touches with their fields. Test cases as Given / When / Then. Claude only ever reads published features, so drafts stay invisible. F-3 ResetToken T-7, T-8
  • Queue it in an iteration. An ordered list of features. Claude claims them one at a time, so two agents never take the same item. I-1
  • Create an MCP token and add the server. Tokens carry scopes for read, write, and records. Run the command above, or commit the .mcp.json with the token in an environment variable.
  • Give Claude one instruction. Implement iteration I-1. It calls the tools in order and reports each record back.
claude · your terminal
  1. you ›Implement iteration I-1
  2. contextsbase · next_iteration_item
  3. ·claimed F-3 Password reset · step 3 of 5
  4. contextsbase · get_feature_spec F-3
  5. ·2 rules · entities User, Session, ResetToken · tests T-7, T-8
  6. ·T-7 link expires in 15 minutes · T-8 link works once
  7. src/app/reset/… written · e2e/reset.spec.ts · 2 passed
  8. contextsbase · record_test_automation T-7, T-8
  9. contextsbase · record_feature_implementation F-3
  10. F-3 Implemented · fingerprint v1:sha256 stored

One instruction. Claude claims F-3, pulls the spec and tests, builds, and records the result over MCP.

Five tools do the work: list_iterations, next_iteration_item, get_feature_spec, record_test_automation, and record_feature_implementation. Each implementation record carries a fingerprint of the spec it was built from. Edit the feature later and the record turns Outdated, so the drift a markdown file hides is visible in one place. Keep your CLAUDE.md for conventions. Delete the spec you pasted into it.

Works for

  • The same spec is needed in more than one session, by more than one person or agent.
  • You want tests that assert business rules, not just that a button rendered a toast.
  • You need a record of what was built from which version of the spec.
  • Ordered work: Claude pulls the next step with an atomic claim instead of you pasting the next ticket.

Where it breaks

  • Nobody writes the spec. If features stay in Draft, there is nothing for Claude to pull.
  • You only need conventions. CLAUDE.md is simpler for that and you should keep it.
  • You want Claude to read raw production data. That is a job for method 3, alongside this one.

Why a markdown file isn't a spec

CLAUDE.md is the right place for how to work in a repo. Teams get into trouble when they also use it as the product spec. The same three failures show up every time, and none of them is fixed by writing a longer file.

if (customer.tier === 'enterprise')

tier does not exist

It invents data model fields

CLAUDE.md says customers have plans. Claude writes customer.tier, and nothing in a paragraph can tell it the field does not exist. An entity with a field list can, and a query against it is exact.

expect(toast).toBeVisible()

link expires in 15 min?

Its tests check buttons

Ask for tests and Claude verifies the click and the toast. The rule that a reset link expires in fifteen minutes is never asserted, because it was never written as a test case. In ContextsBase it is T-7, and Claude turns it into a Playwright test.

NotionSlackJiraYour head

you › “Here’s the spec again…”

The spec lives somewhere else

The real spec is split across Notion, a Slack thread, and a ticket. CLAUDE.md can point at them, but Claude cannot read what it cannot reach, so you paste. A published feature over MCP is the copy Claude reads, every session, without you.

A spec has shape. Entities have fields. Rules have test cases. Features have a status that says whether they are ready to build. Markdown flattens all of that into paragraphs, and Claude does what any reader does with paragraphs: it interprets them. A knowledge base over MCP hands Claude the shape, one feature at a time.

Claude Code context methods compared

“Loaded” is when the context enters the conversation. “Knows what was built” means the method records the outcome, not only the instructions.

Four ways to give Claude Code project context, compared on loading, sharing, data model, tests, and records
MethodLoadedShared with the teamData modelTestsKnows what was built
CLAUDE.mdEvery session, in fullYes, if committedDescribed in proseCommands to run themNo
Memory (# and auto-memory)Index every sessionNo, per user and machineNoNoPartly, as notes
Generic MCP serverOn demand, per callYes, via .mcp.jsonWhatever the source exposesNoNo
ContextsBase over MCPOn demand, one feature at a timeYes, .mcp.json and scoped tokensEntities with fields and foreign keysGiven / When / Then, run and recordedRecords with a spec fingerprint

Keep them layered. CLAUDE.md for how you code. Memory for what you keep correcting. ContextsBase for what you are building. A raw MCP server for data only the database knows. The same four methods exist for Cursor, with .cursor/rules in place of CLAUDE.md and .cursor/mcp.json in place of .mcp.json. That guide is How to give Cursor context about your project.

Give Claude Code the spec, not a summary of it.

One feature, one iteration, one claude mcp add. Free for one project.

  • Free for one project
  • Bring your own agent

Frequently asked questions

Does Claude Code read CLAUDE.md automatically?

Yes. When a session starts, Claude Code loads CLAUDE.md from the current directory and its parent directories, plus ~/.claude/CLAUDE.md for instructions that apply to every project. A CLAUDE.md inside a subfolder is pulled in when Claude starts working with files in that folder.

How long should a CLAUDE.md file be?

Short. Every line is loaded into every session, so keep it to build and test commands, conventions, and pointers to important files. Product specs, data models, and acceptance tests belong somewhere Claude can query on demand, such as an MCP server, not in a file it has to read in full each time.

What is the difference between CLAUDE.md and an MCP server?

CLAUDE.md is static text Claude reads at the start of a session. An MCP server is a live source Claude can call mid-task with a specific question, such as the spec for one feature or the fields of one entity. Use CLAUDE.md for how to work in the repo and MCP for what to build.

Does claude mcp add support HTTP servers?

Yes. Run claude mcp add --transport http with a name and the server URL, and pass authentication with --header. Add --scope project to write the server into a shared .mcp.json in the repository, or --scope user to make it available in every project on your machine. Run /mcp inside a session to confirm it connected.

Where does Claude Code store memory?

Notes saved with the # shortcut go into a CLAUDE.md file you choose: the project's, a gitignored CLAUDE.local.md, or ~/.claude/CLAUDE.md. Auto-memory lives in a per-project folder under ~/.claude/projects, with a MEMORY.md index that is loaded at the start of each session. All of it is plain markdown you can edit.

Does ContextsBase replace CLAUDE.md?

No. Keep CLAUDE.md for repo conventions and commands. ContextsBase holds the published features, entities, flows, and test cases, and Claude Code pulls them over MCP when it claims work. The two answer different questions: how to work here, and what to build.

Is there a version of this guide for Cursor?

Yes. How to give Cursor context about your project covers .cursorrules, .cursor/rules, @Docs, and .cursor/mcp.json with the same four methods, and connects to the same ContextsBase project.