When Claude Code performs poorly, the cause is almost never “the model isn’t smart enough.” It’s that the agent doesn’t have your project’s context. Without that, it does what looks productive but is mostly guessing. Seven ways to feed it the context it needs, in ROI order.
What “no project context” looks like
- Edits files but never opens the actual main logic file
- Creates a function / component that already exists (reinvents the wheel)
- Asks “where is X defined?” when it’s in your README
- Auto-applies a bunch of style changes that break your existing conventions
- Debugs by patching symptoms instead of going to the root cause
The real reason
Claude Code doesn’t auto-read your entire repo. It only sees:
- Files you mention explicitly in the prompt
- Whatever is in
CLAUDE.mdat the project root - Files it actively discovers via tools during the task
If all three are sparse, it falls back to “guess common patterns.” Next.js? Guess app/page.tsx. Astro? Guess src/pages. If your project is a monorepo or non-standard, every guess is wrong.
7 ways to give Claude Code real project context
In ROI order:
1. Write a good CLAUDE.md (most important)
Create CLAUDE.md at the project root. It’s the “project handbook” Claude Code reads every session.
Must contain:
- Tech stack: frameworks, language, version, package manager
- Directory layout: what each top-level folder is
- Key conventions: file naming, state management, routing, CSS approach
- Run / build / test commands:
npm run dev,npm test - Local pitfalls: which directories to avoid, which files not to touch
- How to add a new feature / page / component: actual steps
Style: write in second person, like onboarding a new colleague.
Anti-example: a
CLAUDE.mdfull of “project vision / design philosophy.” Claude doesn’t need that. It needs “the 4 steps to add a new page.”
2. Name files in the prompt directly
Don’t write “fix the login bug.” Write:
Fix the bug in src/auth/login.ts. Relevant logic is also in src/auth/session.ts and src/lib/cookies.ts. Read these three files first, then propose a fix.
Spelling out 3–5 files lets the agent skip the “find files” phase.
3. Have it ls / tree first
The first time the agent enters a project, ask it to do a structure scan:
Run
ls -lafor the root andtree -L 3 -I 'node_modules|.next|dist'for the structure. Tell me what kind of project this is, then begin.
This is the agent’s “boot scan.”
4. Use README + ARCHITECTURE to do the lifting
If your repo has a README and an architecture doc, drop them at the root and add to CLAUDE.md:
Always read README.md and docs/ARCHITECTURE.md before suggesting code changes.
Many projects lack these; AI then guesses.
5. Forbid the agent from touching certain directories
Either via .claudeignore or in CLAUDE.md directly:
Do NOT edit anything inside:
- node_modules/
- .next/, dist/, build/
- generated/ (auto-generated)
- legacy/ (deprecated, do not touch)
This stops random searches inside irrelevant directories and keeps responses focused.
6. Give “how to add an X” copy-paste checklists
In CLAUDE.md:
## How to add a new page
1. Create `src/content/articles/[lang]/[category]/[slug].mdx`
2. Use the schema in src/content/config.ts
3. Add the slug to internal links from the related category landing
4. Run `npm run audit:content` before commit
Checklist-style guidance lets the agent follow steps verbatim rather than invent new conventions.
7. Add navigation comments to key files
5–10 line “what does this file do” comments at the top of important files:
// auth/session.ts
// Owns session lifecycle: create, refresh, destroy.
// Reads cookies via lib/cookies.ts. Writes audit logs via lib/log.ts.
// IMPORTANT: do not call this from middleware — use auth/edge-session.ts there.
Written for AI but useful for human readers too — no downside.
Shortest path
In effort order:
- Add a CLAUDE.md (even just 30 lines)
- Always list files in each prompt
- Forbid agent from touching certain dirs
- Add navigation comments to key files
- For complex repos, write ARCHITECTURE.md
Steps 1 and 2 alone give immediate, large improvement.
When it isn’t the model’s fault
- Your project is genuinely messy — even a new human can’t follow it → refactor first
- Same prompt works fine in a small project but fails in your large monorepo → context volume is overrunning
- Agent keeps re-trying the same file → it didn’t get the real path
- Repo lacks any documentation → AI is stuck guessing
Easy misjudgments
- “Claude got dumber” → your project just got bigger; Claude Code can’t read a million lines at once
- “It ignores CLAUDE.md” → check filename casing, path at root, no typos
- “It hallucinates code” → usually it didn’t see the real code and was forced to invent
- “It can’t use tools” → your prompt didn’t grant
tree / grepuse; it had to guess
Prevention
- Day-one for any project: create
CLAUDE.md - Update
CLAUDE.mdwhen modules change - For monorepos, drop a
CLAUDE.mdin every sub-package - Explicitly write the “do not do” red lines for refactoring / naming
- Before any big task, have the agent state its understanding of the project structure first
FAQ
Q: How long should CLAUDE.md be? A: 50–200 lines is the sweet spot. Too short → no info. Too long → buries the priorities. Order: tech stack → directories → key commands → “do not” → “how to add new things.”
Q: CLAUDE.md vs. README — which? A: CLAUDE.md is for the agent; README is for humans. Content can overlap, but CLAUDE.md emphasizes “what the agent should do.”
Q: Do .cursorignore, .claudeignore, .gitignore overlap?
A: Not fully. Each tool reads its own. Add separate ignores for each tool you use.
Q: Can I make Claude Code read the entire project at once? A: Only for small projects. For medium-large repos, let it “read on demand”; don’t dump everything into the context window.
Q: How do I know it has the right context? A: Have it write a 1–2 sentence summary of the project structure before doing real work. If it’s wrong, stop and correct it.
Decision checklist
- If the error started right after a change, roll back or isolate that change before trying unrelated fixes.
- If the error happens only in production, compare environment variables, build output, cache, permissions, and platform settings.
- If the error happens only for one account or browser, test permissions, cookies, extensions, quota, and regional availability.
- If two fixes seem possible, choose the one that is easiest to verify and easiest to undo first.
When to stop debugging
Stop and escalate when you cannot reproduce the issue, when logs contradict the UI, when billing or account security is involved, or when every fix requires production access you do not control. At that point, package the exact error, timestamp, project ID, reproduction steps, screenshots, and recent changes before asking support or another engineer. Good escalation notes often solve the problem faster than another hour of guessing.
Diagnostic flow
- Reproduce the issue once and write down the exact path. If you cannot reproduce it, collect more evidence before changing settings.
- Check scope: one user or everyone, one browser or all browsers, local only or production only, new content only or old content too.
- Check the last change first. Most troubleshooting work is not about finding a mysterious root cause; it is about identifying which recent change created the mismatch.
- Split the system in two: input vs output, local vs hosted, account vs project, source file vs generated file, prompt vs model. Test which side still fails.
- Apply the smallest reversible fix. Avoid changes that touch DNS, permissions, billing, deployment, and code at the same time.
- Verify the original reproduction path and one nearby path, then write down what fixed it.
Minimal reproduction template
Issue:
- [exact error or broken behavior]
Where it happens:
- URL / tool / project:
- Account:
- Environment: local / preview / production
- Browser / device:
Steps to reproduce:
1.
2.
3.
Expected:
-
Actual:
-
Recent changes:
- Code:
- Config:
- DNS / permissions / billing:
- Prompt / model / uploaded files:
Evidence:
- Screenshot:
- Console error:
- Server or platform log:
False fixes to avoid
- Clearing cache without checking whether the underlying file, permission, route, or setting is correct.
- Reinstalling packages when the error is actually caused by environment variables, credentials, quota, or platform config.
- Changing several unrelated settings at once, then not knowing which one mattered.
- Copying a fix from another framework or platform without checking whether the routing, build output, or auth model is the same.
- Treating a temporary platform outage as your own bug before checking status pages and recent reports.
Related articles
- How to Fix Cursor Stuck on Indexing
- What to Do When Claude Usage Limit Is Reached
- Why Longer Prompts Sometimes Produce Worse Results
- AI pre-commit review workflow
- Claude Code SEO audit
- AI dependency upgrade workflow
Tags: #Claude #Claude Code #AI coding #Debug