Claude Code Doesn't Understand Your Codebase? How to Fix It
A plan to add a helper is hard to trust when Claude hasn't looked for an existing one. Before giving it more files, ask it to show where it searched, which implementation it found, and why that implementation doesn't fit.
That's where I'd start. If an instruction didn't load, check that first, then separate unanswered questions about callers from the revision problem, because an answer about the wrong checkout is a different thing to review.
Check what Claude actually loaded
Claude Code has native tools for finding and reading code, so ask it to investigate, show what it found, explain where it stopped, and let you review the evidence before adding another service.
Check instructions too. Anthropic documents that CLAUDE.md files in the working directory and its ancestors load at launch, nested files in subdirectories load once Claude reads, writes or edits a file there, project instructions guide the model, and they don't enforce rules mechanically. See how Claude Code loads project instructions.
In an active session, run:
/context
Look under Memory files to confirm which instruction files loaded at launch. A CLAUDE.md in a subdirectory doesn't appear there, because it loads on demand; when it loads, the terminal shows a Loaded line with its path. Although /memory helps you find and edit instruction locations, its list can include files that don't exist yet, so check the launch list in /context, even when the path you expected appears in /memory.
Keep CLAUDE.md useful to the next task. Put the test command there, explain which package owns a shared concern, name the conventions that are easy to miss, and remove instructions that contradict each other.
I wouldn't maintain a full function catalogue in it.
Ask for evidence before an edit
Try this in the repository you're working on:
Investigate before editing. Find an existing implementation of the behavior
I asked for and show its file and line range. Read the instructions that
apply to that directory.
If an existing function needs changing, identify its production callers
and check test references separately. Explain what you searched and where
you stopped. Then propose the smallest change for me to review.
For example, if the task is to rename checkAdminOrOwner to canManageAccount, don't start by asking Claude to replace every matching string. Ask it to locate the implementation, show the production callers, search test references and string-based uses separately, and identify the instruction files governing each directory. Before approving an edit, check this list:
- the implementation and line range are real;
- the callers named are production callers, not only tests;
- test mocks, fixtures and string references were considered separately;
- the search scope and stopping point are stated; and
- the proposed change is no broader than the evidence requires.
Don't accept a path as proof by itself. Replace "the behavior I asked for" with the actual task. If the reply names a helper, open it, check the proposed use against its implementation, and follow the callers that would be affected.
For a rename, I'd also ask for names stored in strings and test mocks, because the practical review question is which references need updating, including ones outside a production call chain, rather than whether the agent found an impressive number of files. This is a review procedure, not a promise that the prompt catches everything. For changes that cross package boundaries, the guide to Claude Code on a large codebase goes further into scoping the investigation.
Use repository packs when you need a source snapshot
For a document workflow, Repomix combines repository content into one file for an AI tool, Gitingest produces a text digest from a repository URL or directory, and RepoPrep documents a browser workflow that turns a folder or ZIP into a Markdown context file you can carry into the next review.
The selection still needs review. If you pack one directory, check whether the question needs callers outside it, record the revision represented by the pack, and include those files deliberately instead of assuming the directory boundary answers the question.
For the tradeoffs, see native search, repository packs and structural MCP context, which discusses packing workflows, measures native search against structural MCP context, and keeps those measurements separate from pack performance.
Add a codebase map for relationship questions
I build Pharaoh. It's a hosted MCP service for TypeScript, JavaScript, Python, C and C++ repositories, mapping functions and modules into a graph, recording dependencies and entry points, and making that structure available to the connected agent.
Ask which production paths reach the helper you're about to change.
For Claude Code, install the GitHub App on the account or organization that owns the repository, connect the client from your terminal, and sign in with GitHub. npx @pharaoh-so/mcp is the command in the Claude Code connection instructions:
npx @pharaoh-so/mcp
These are the current tools to ask the connected agent to use:
| Question | Tool |
|---|---|
| Which module owns this area? | get_codebase_map returns modules with file counts and LOC, dependencies with two-way relationships flagged, files changed most over 90 days, and endpoints with handler files. |
| What does this module expose and depend on? | get_module_context returns exported signatures, imports, database access, endpoints, cron jobs, environment-variable names and callers from other modules. |
| Is there an implementation I can reuse? | search_functions returns matching functions with paths, line ranges, signatures and complexity. |
| Which production callers would a change affect? | get_blast_radius follows up to five hops, three by default, and reports affected endpoints, cron jobs and database operations. Test-file callers are excluded. |
| Is this function connected to an entry point? | get_unused_code can report a function's status and the entry-point path reaching it. |
| Can I gather several structural answers together? | pharaoh_recon batches module profiles, function searches, blast-radius targets and dependency paths. |
| Which repository is live, and can I refresh it? | pharaoh_account reports account status and supports refresh requests. |
This is captured get_unused_code output for functions: ["checkAdminOrOwner"], from Pharaoh-so/cal.diy (revision 54343aa6):
# Reachability in cal.diy
- checkAdminOrOwner (packages/features/auth/lib/checkAdminOrOwner.ts): reachable: getAtomEventTypeApp → getEventTypesAppIntegration → checkAdminOrOwner
That gives you a path to inspect. Open the named implementation, compare it with the change you're planning, check the relevant callers, read the change-impact walkthrough, and trace the effects further where the edit needs it.
get_unused_code classifies functions. Dead requires agreement across every signal: no entry point reaches the function, no other file names it, and no production file imports its file.
Possibly unused means the function is unreached but named elsewhere or its file is imported.
Used only by tests identifies exported functions referenced only by test files. Those distinctions matter when deciding what to inspect before deleting code.
Keep the map revision separate from your checkout
pharaoh_account can request a refresh before the next push, and the interactive graph, which excludes other branches and uncommitted edits, is re-mapped on a push to a live repository's default branch.
So check the checkout too. Use the map to choose a path worth reading, inspect that path in your working files, account for any differences since the mapped revision, and run the checks appropriate to the change. A report about the default branch can't establish what your unfinished edit does.
Pharaoh stores no source code. Mapping processes a temporary clone and deletes it when the job ends, including failures, while the stored graph contains metadata such as names, paths, relationships and signatures. Its GitHub App reads the repositories you authorize, and its only write is publishing check results: it can't push commits, edit files, create branches or open pull requests.
If you're also checking pull requests, PR Guard is available on Pro, reports new dead code and breaking signature changes with callers, checks exact function duplicates and blast radius, and is advisory by default through a neutral check.
For other integrations, see MCP servers worth adding to Claude Code.
Measure the task you need help with
The repository-context experiment and its limits are more useful than a general claim that maps make agents faster. On cal.diy at 54343aa6, the saved October 16, 2026 dataset used three sessions for each task in each condition, compared native tools with Pharaoh available, and recorded a different result for different questions.
In the permission-check impact task, the mean was 32.03 seconds natively and 16.93 seconds with Pharaoh, while rename planning averaged 16.01 and 16.95 seconds respectively, and both rename conditions listed the fifteen expected files.
Pharaoh wasn't faster on every question. Those are timings, not accuracy scores. The study discloses a name-matching grader bug, includes no Repomix or Gitingest condition, and doesn't preserve every historical plugin flag or cache condition, so it can't support a ranking of all these approaches.
The separate Claude Code cost experiment covers spending on code-connection questions. For your own comparison, use a fixed revision, prepare an answer key from source, keep the model and question consistent, and count context-preparation time alongside answering time.
When the session has become hard to follow
More context isn't always the next thing to add. If you need to keep working in the same session, Claude Code can compact automatically near its limit, and /compact lets you request a summary with optional instructions about what to preserve, so name the agreed scope and unfinished checks, then review what the agent is doing as you continue.
For example:
/compact Preserve the agreed scope and the tests we still need to run.
The current command reference documents that syntax.
For ongoing tasks, read Claude Code context limits and compaction.
I'd finish with one concrete check. Pick the function your next edit touches, ask Claude to identify its callers before proposing changes, open the evidence it returns, and compare the map revision if you use one.
If relationship discovery is the part taking the time, connect one repository to Pharaoh, repeat the task you scoped above, check the returned paths in source, and decide whether that saves work on your repository.
Article Record
ReferencesPrimary sources used for this article
- Common workflows
- Explore the context window
- How Claude remembers your project - Claude Code Docs
- How Claude Code works
- Commands
- Getting Started with Repomix
- GitHub - coderamp-labs/gitingest: Replace 'hub' with 'ingest' in any GitHub URL to get a prompt-friendly extract of a codebase
- Understanding Large Codebases via CLI
- CLI Debugging Workflow
- Context Engineering with Claude Code: Stop Rewriting AI-Generated Code
Update HistoryMeaningful revisions to this article
- Added a practical example showing how to ask for evidence before making an edit.
- Updated the description to highlight checking instructions, tracing callers, and reviewing plans.