How to Give AI Full Codebase Context for Smarter Agents

Dan Greer · · 13 min read

Part of the Claude Code guide. Start with Claude Code Doesn't Understand Your Codebase? How to Fix It

Diagram illustrating how to give AI full codebase context for smarter code analysis and suggestions

Before changing an authorization helper, ask your agent to identify its production callers. If it can explain the function, describe its arguments, and suggest a replacement, but can't show which endpoint reaches it, hold the edit. You have enough context to discuss the implementation. You haven't yet checked the change against the rest of the repository.

Full context means enough evidence for this task and a way to find what you haven't read. Trying to hand over every file is a different job.

I build Pharaoh, so I have a preference for queryable code relationships. But I would still start with a small instruction file and the search tools already in your editor, because a new context service is a poor first answer to a missing test command, an unclear task, or a file you already know how to find.

Choose context by the question you need answered

Instruction files, repository packs, search results, and code graphs give an agent different kinds of evidence. Use this as a starting decision, then check the result on your own task.

Context method Start here when you need Check before trusting it
CLAUDE.md / AGENTS.md Repository instructions, commands, conventions Whether the instructions still match the checkout
Repository pack, such as Repomix A selected set of files in one input Which files were included and when the pack was made
Native search / flat retrieval A definition, a mention, or relevant code to read Whether the results answer the relationship question too
Graph MCP, such as Pharaoh (ours) Module dependencies, callers, or entry-point paths The mapped revision and the scope of the returned relationships

These aren't exclusive choices. Claude Code has file and content search tools, Repomix packages repository files, and Pharaoh returns structural metadata over MCP, so use the cheapest useful route for the question, read the source it points to, and expand only when something remains unresolved.

For measurements, read the comparison of native search, repository packs, and structural MCP context, which reports a particular evaluation, then try the same methods on a task you can check yourself.

Keep instructions small enough to maintain

Codex reads AGENTS.md before working, and Claude Code supports persistent instructions, including CLAUDE.md. Give that file the information a checkout won't explain by itself, especially a command someone has to run differently, a generated directory they must leave alone, or a dependency rule that isn't enforced by the compiler.

I wouldn't maintain a hand-written inventory of every function in it. The useful test is simpler: would this instruction change an agent's next action?

Here's an illustrative instruction-file section to adapt. Replace the command placeholder with a command you've actually run in this repository.

## Before editing
- Find an existing implementation before adding a helper.
- Read the target function's callers before changing its contract.
- Run <verified test command for this repository> after the edit.
- State which relevant paths remain unverified.

Keep the rules that prevent a recurring mistake, remove the ones that repeat the README, and verify the remaining commands against a fresh checkout, because an instruction that points at a retired script sends the agent in the wrong direction before it has opened any source. For review habits that catch what an instruction file can't, see how to reduce AI coding mistakes.

Pack files when you already know the scope

Repomix can combine a repository into one AI-friendly file. If the relevant directories in your project are src and tests, and you've checked that those include patterns match the files you need, use the documented options, name an output file, and run the following command.

npx repomix@latest --include "src/**,tests/**" --output context.xml

context.xml is the output file to open before passing it to an assistant.

I'd use a pack for a bounded review where I can name the files, inspect what went into the bundle, and regenerate it after changes, especially when the receiving tool doesn't have repository access. If I still don't know which packages call the function, I'd find that scope first rather than package more files and hope the answer is somewhere inside.

That distinction also matters for flat RAG. The original RAG paper describes generation conditioned on retrieved passages, and while a relevant implementation gives you text to inspect, it doesn't settle my next question, which is who calls it, so I'd still ask for that evidence before changing its contract.

Sometimes search is enough. Don't add a graph dependency to find a string you already know.

Search the checkout, then inspect the connections

Ask the agent to locate the existing implementation before proposing another one. Have it show the definition and the references it found, read the callers that matter to the task, and explain any boundary it couldn't trace, including a string-based dispatch or a generated client that needs a different check.

For Cursor, read the large-codebase context guide, try its workflow on your checkout, and keep the same acceptance rule across clients, since a file list alone doesn't establish which production path uses the code.

If you need dependencies across modules, try a graph query, read the code knowledge graph explainer if the representation is unfamiliar, and check whether the returned connections answer your question, including any limits the tool reports.

Pharaoh maps TypeScript, JavaScript, Python, C and C++ repositories into functions, files, modules, dependencies, endpoints, and cron jobs. get_codebase_map is for orientation, get_module_context for a module's exports and dependencies, and search_functions for finding an implementation before writing a new one. pharaoh_recon can combine several of these investigations in one call.

Here's a trimmed get_module_context result for the features/auth module of cal.diy, the public fork maintained by Pharaoh-so, at revision 54343aa6, captured on October 26, 2026. The full result lists callers from 19 modules; these lines come from two of them.

## External Callers

### app-store/zapier
- packages/app-store/zapier/lib/validateAccountOrApiKey.ts: validateAccountOrApiKey() → isAuthorized()
### trpc/server
- packages/trpc/server/routers/viewer/auth/changePassword.handler.ts: changePasswordHandler() → verifyPassword()
- packages/trpc/server/routers/viewer/ooo/outOfOfficeEntriesList.handler.ts: outOfOfficeEntriesList() → checkAdminOrOwner()

Now you have particular callers to open. For a proposed contract change, use get_blast_radius to inspect production callers and affected endpoints, remembering that its traversal defaults to three hops, supports up to five, and excludes callers in test files. The guide to checking a code change's blast radius covers that check in more detail.

get_unused_code can return an entry-point path for a wiring question. From the same cal.diy revision and capture:

# Reachability in cal.diy

- checkAdminOrOwner (packages/features/auth/lib/checkAdminOrOwner.ts): reachable: getAtomEventTypeApp → getEventTypesAppIntegration → checkAdminOrOwner

Those names give the next investigation a concrete starting point. Read the implementation and relevant tests before deciding what to change.

Check which version the context describes

Pharaoh maps a live repository's default branch and refreshes it on pushes to that branch. It doesn't cover your uncommitted changes or another branch, so if you're editing locally, compare the returned paths with your checkout, inspect any changed callers there, and use local checks for the patch you're about to submit.

This is where I'd stop promising “full” context. A returned dependency path answers a bounded question. It doesn't establish that an edit has the intended behavior.

For setup, install Pharaoh's GitHub App on the account or organization that owns the repository, then connect your client. In a Claude Code terminal, run:

npx @pharaoh-so/mcp

Other clients can add https://mcp.pharaoh.so/mcp as a remote MCP server and sign in with GitHub.

Pharaoh doesn't keep your source code: its graph keeps structural metadata such as names, paths and relationships, not source-file bodies.

The GitHub App reads the repositories you authorize, and its only write permission is publishing check results.

Read processing and repository permissions, check them for your organization, and choose the repositories to authorize.

The MCP servers that expose a code graph guide covers other options. Compare the relationships each server returns and the revision it describes.

What the research says

The papers support a narrower argument than “more context fixes agents.” They also measure different tasks, use different baselines, and report different outcomes, so none of these percentages belongs in a claim about Pharaoh's performance.

In Evaluating AGENTS.md, the researchers found no significant success improvement from context files in their Python issue-resolution evaluation, while generated files increased mean inference cost by 20% on SWE-bench Lite and 23% on CTXbench, a useful warning when choosing repository instructions, because adding a file isn't evidence that it helps.

CatCoder combined retrieved code with type context extracted through static analysis. Its maximum 17.35% relative gain was on Java pass@5 against RepoCoder, using CodeLlama-13B-Instruct, from 49.04% to 57.55%, so don't read that as a 17.35 percentage-point increase across languages or a result on production incidents.

On RepoExec, InlineCoder reported average relative improvements of 29.73% in Exact Match, 20.82% in Edit Similarity, and 49.34% in BLEU against the strongest baseline, averaged across three models. Edit Similarity measures resemblance to reference code, not execution success, so these results don't tell you how many regressions a context tool will prevent.

My takeaway is to test context against your own task.

For the window-size question, read why a bigger context window doesn't fix it.

Try one task with an answer you can check

Pick a change you understand well enough to review. Before the agent edits, ask it to identify the existing helper, list the production paths affected by the proposed change, name its evidence, and flag anything it couldn't verify.

Check that answer against the source. Then make the change and run the repository's relevant checks.

If you compare context methods, keep the task and starting revision the same, use a fresh session for each attempt, record the context-gathering time, and count the required evidence each answer actually found.

To try Pharaoh, connect your repository and client, choose a question you can verify, inspect the answer against your checkout, and only then let the agent edit.

Frequently asked questions about giving AI codebase context

What is the best way to give an AI coding agent codebase context?

Choose the least expensive method that answers the question: use instruction files for repository rules, a repository pack for a known set of files, search for definitions and mentions, and a code graph for callers, dependencies, and entry-point paths. Combine methods when one does not resolve the question.

What should an instruction file such as AGENTS.md or CLAUDE.md contain?

Include information that the checkout does not explain by itself, such as commands that must be run differently, generated directories to avoid, or dependency rules not enforced by the compiler. Keep rules that prevent recurring mistakes, and verify commands against a fresh checkout.

How can I check whether an AI agent has reliable codebase context?

Before editing, ask the agent to identify the existing implementation, show relevant references and production paths, name its evidence, and flag anything it could not verify. Check the answer against the source, then run the repository's relevant checks after the change.

Does a code graph provide complete context for an AI coding agent?

No. A graph can answer bounded questions about relationships such as callers, dependencies, and entry-point paths, but it does not establish that an edit has the intended behavior. Also check the mapped revision against your checkout because the graph may not include uncommitted changes or another branch.

Article Record

ReferencesPrimary sources used for this article
  1. How Claude Code works
  2. How Claude remembers your project - Claude Code Docs
  3. Custom instructions with AGENTS.md
  4. Enhancing Repository-Level Code Generation with Integrated Contextual Information
  5. Computer Science > Computation and Language
  6. Evaluating AGENTS.md: Are Repository-Level Context Files Helpful for Coding Agents?
  7. Getting Started with Repomix ​
  8. Command Line Options ​
  9. Search code, repositories, users, issues, pull requests...
  10. What is the MCP and how does it work?
  11. Prometheus: Unified Knowledge Graphs for Issue Resolution in Multilingual Codebases
Update HistoryMeaningful revisions to this article
Improved AI Codebase Context Guidance
  • Added four frequently asked questions to help readers understand how to give AI coding agents better codebase context.
  • Updated the article description to clearly summarize its guidance on instructions, search, repository packs, code graphs, and task-specific evidence.
Initial publication.

More in Claude Code

← Back to blog