Connecting Claude Code to a Project
Independent educational resource, not an official Anthropic course. Facts about the API, prices and limits were checked against Anthropic's documentation on 15 November 2026 and the code was run against a local mock of the API, not the live service. Check the linked official pages before relying on a number, and test with your own key.
Starting Claude Code in a folder is easy. Getting it to understand your project, safely, is the part worth doing carefully. This lesson covers what happens when you launch it in a repository, the trust prompt, generating a first CLAUDE.md, giving Claude the files and tools it needs, and connecting external services with MCP. It also shows a few messages from the real tool that explain behaviour people find confusing.
What you'll learn
- What happens when you run
claude in a project, and what the trust prompt does.
- How to generate a starter
CLAUDE.md with /init and confirm it loaded.
- How to point Claude at files, images, extra folders and command output.
- How to add MCP servers with
claude mcp add and a shared .mcp.json.
Before you start
Launch it where the project is
Claude Code is tied to the directory you start it in. It can see that directory and below, plus other folders with your permission, and it reads CLAUDE.md files from there and from the folders above. So start it at the repository root:
cd /path/to/your/project
claude
The first time you open a folder, Claude Code asks whether you trust it. That prompt matters because a repository can carry its own settings, hooks and MCP servers, and those run on your machine. Don't accept it for a repository you haven't looked at.
The trust decision has a visible effect, which we saw in practice. We ran claude doctor in a project whose .claude/settings.json had six allow rules, before accepting the trust prompt, and it printed:
Ignoring 6 permissions.allow entries from .claude/settings.json: this workspace has not been trusted.
Run Claude Code interactively here once and accept the trust dialog, ...
That matches the documentation: allow rules and a few other keys committed to a repository only apply after each person has trusted the folder, while deny and ask rules apply straight away. It's a sensible default. A cloned repository can't quietly pre-approve commands on your machine.
Generate a first CLAUDE.md
Inside a session, /init analyses the codebase and writes a starting CLAUDE.md with the build commands, test instructions and conventions it finds. If one already exists, it suggests improvements rather than overwriting it. Treat the result as a draft. The documentation says the real work afterwards is mostly removing lines, so that what remains is what Claude couldn't work out from the code alone (lesson 5.4 has the details).
To confirm the file loaded, run /context all and look under "Memory files", or /memory to open and edit it. If a file isn't in that list, Claude can't see it.
Give Claude what it needs
You don't have to paste code. Claude reads files as needed. But you can save it effort, and avoid wrong guesses, by pointing:
- A file or folder: type
@src/Actions/CreateOrder.php in your message to include the file's contents (a folder reference lists its files). Referencing a file also brings in the CLAUDE.md from that file's folder and its parents.
- An image: paste or drag a screenshot of an error or a design.
- Command output: pipe it in with
cat error.log | claude -p "what's going on here".
- Another folder:
claude --add-dir ../shared-config lets Claude work outside the main directory. By default its CLAUDE.md files aren't loaded; set CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 for that.
Be specific about the task. Anthropic's best-practices page contrasts "fix the login bug" with "users report login fails after the session times out; look at token refresh in src/auth/, write a failing test that reproduces it, then fix it", and notes the second saves a round of corrections.
Connect external tools with MCP
The Model Context Protocol is the open standard Claude Code uses to reach outside services: issue trackers, databases, design tools, your own internal APIs. You add a server with one command. The documentation shows three transports:
# A remote server over HTTP (the recommended kind)
claude mcp add --transport http notion https://mcp.notion.com/mcp
# The same, with a bearer token
claude mcp add --transport http secure-api https://api.example.com/mcp \
--header "Authorization: Bearer your-token"
# A local program speaking over stdio; everything after -- launches the server
claude mcp add --env AIRTABLE_API_KEY=YOUR_KEY --transport stdio airtable \
-- npx -y airtable-mcp-server
Manage servers with claude mcp list, claude mcp get <name> and claude mcp remove <name>, and inside a session use /mcp to check status and sign in to servers that use OAuth. Servers have three scopes:
| Scope | Loads in | Shared with the team | Stored in |
| Local (default) | This project only | No | ~/.claude.json |
| Project | This project only | Yes, via version control | .mcp.json in the project root |
| User | All your projects | No | ~/.claude.json |
To share a server with your team, add it with --scope project, which writes a .mcp.json you commit. Keep secrets out of it by using environment variable expansion: ${VAR} becomes the variable's value, and ${VAR:-default} uses a default when it's unset. This is the example project's file:
{
"mcpServers": {
"orders-api": {
"type": "http",
"url": "${ORDERS_MCP_URL:-https://mcp.example.test}/mcp",
"headers": {
"Authorization": "Bearer ${ORDERS_MCP_TOKEN}"
}
}
}
}
For safety, Claude Code asks for approval before using project-scoped servers from .mcp.json in interactive sessions (claude mcp reset-project-choices resets those answers). Note that in non-interactive claude -p runs it can't ask, and it loads them without asking.
The real tool checks this file. Running claude doctor in the example project gave:
Invalid settings
- .mcp.json › mcpServers.orders-api: Missing environment variables: ORDERS_MCP_TOKEN
Suggested fix: Set the following environment variables: ORDERS_MCP_TOKEN
That is the safety net working: the token isn't in the file, so the file is safe to commit, and the tool tells you what's missing on your machine. Claude Code also deliberately reads certain credential variables, such as ANTHROPIC_API_KEY, as empty inside a remote server's url and headers, so a repository's .mcp.json can't forward your credentials to a server it names.
Real-world use case (illustrative scenario)
This scenario is an invented example to show how the ideas fit together. It is not a case study and its details are not measured results.
A freelancer joins a client's Laravel project on Monday. They clone it, run claude, accept the trust prompt after skimming the committed .claude/settings.json, and run /init. They then spend ten minutes deleting lines from the generated CLAUDE.md that merely describe what's obvious from the code, and adding two gotchas the client's team told them about. The client has committed a .mcp.json for their issue tracker; the freelancer sets the one environment variable it needs, and from then on can say "pick up ticket 482" without leaving the terminal.
Mistakes to avoid
- Accepting trust for a repository you haven't looked at.
- Keeping the full
/init output without pruning it.
- Putting tokens into
.mcp.json instead of ${VAR}.
- Connecting MCP servers you don't trust. Servers that fetch external content can expose you to prompt injection.
- Launching Claude Code in the wrong folder and wondering why it can't see your rules.
Security notes
A repository can bring its own hooks, MCP servers and settings. The trust prompt is your checkpoint, so read what a project asks to run. Anthropic warns to verify that you trust each MCP server before connecting it. Deny rules for secrets (such as Read(./.env)) belong in your project settings, and the best-practices page notes they apply in every permission mode (lesson 5.7).
Cost and speed
Every MCP server adds tool definitions. Claude Code defers MCP tool definitions by default and loads them on demand through tool search, so only tool names and server instructions use context until a tool is actually used. Use /context to see what's taking space.
Key takeaways
- Launch from the project root; accept the trust prompt only for repositories you've inspected.
- Committed
allow rules wait for trust; deny and ask rules apply immediately.
- Run
/init, then prune the result; verify it loaded with /context all or /memory.
- Use
@ references, images and piped output to give context; use claude mcp add and a committed .mcp.json with ${VAR} for tools.
Lesson recap: from first launch to a project with context and tools.
Quick quiz
- Why does Claude Code ask whether you trust a folder?
- Which kinds of permission rule apply to a repository before you've accepted trust?
- How do you confirm that
CLAUDE.md loaded?
- Where does a project-scoped MCP server definition live, and why use
${VAR} in it?
- What does
@src/file.php in a prompt do?
Answers and explanations
- A repository can carry settings, hooks and MCP servers that run on your machine, so you should only trust folders you've inspected.
deny and ask rules apply right away. allow rules wait for trust.
- Run
/context all and check the "Memory files" list, or use /memory.
- In
.mcp.json at the project root. ${VAR} keeps credentials out of the committed file.
- It includes that file's contents in the message, and brings in the
CLAUDE.md files for that file's directory and its parents.
Official references and further reading
Related tutorials