Claude Code on a Large Codebase Without Guesswork

Dan Greer · · 10 min read

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

Claude Code for large codebases without guesswork

The auth module in the recorded cal.diy session below contains 43 files. Its callers reach into the API and the web app, so starting Claude inside auth, while useful for focus, wouldn't tell you how far a change could travel.

That's the tension I want the setup to handle. Keep the initial search small, let the task expand when the evidence requires it, even if that means revisiting your scope, and make the agent name the files outside its starting directory before you accept its plan.

Start in the package you're changing

For a task confined to one package, launch there. Substitute your own package path in this example.

cd packages/api
claude

claude starts an interactive session in that directory.

Use the CLI's --add-dir flag when you need access to a sibling directory.

claude --add-dir ../shared

claude --add-dir grants file access, so use it when the task reaches a sibling package, check the paths you're adding, and keep the edit scope explicit in your prompt. It doesn't import that package's full configuration. Additional-directory access and configuration are separate.

Starting below the root is a useful default for local work. A change spanning several packages may belong at the root from the outset, with named targets, a bounded question, and permission to inspect the consumers it actually needs. Anthropic's large-codebase guide describes that choice in terms of file access, startup instructions and project settings.

Put local instructions beside local code

Keep the root CLAUDE.md for rules that apply across the repository. Package instructions should explain the exceptions close to the code, especially when a monorepo mixes stacks, when one package has its own validation process, or when a generated directory looks like ordinary source.

A directory layout might look like this. These are illustrative paths, not a description of cal.diy:

CLAUDE.md
packages/
  api/
    CLAUDE.md
    .claude/settings.json
    src/
  shared/
    CLAUDE.md
    src/

Claude loads CLAUDE.md files along the path from its working directory through its ancestors, and it loads descendant instructions when it accesses files there, so a package file adds guidance to the root rules, rather than replacing them. That's the behavior documented in how instruction files load.

Use /init if you need a starting file. Then read what Claude wrote, check each inferred command against the package's actual scripts, cut anything Claude could learn by reading the code, and add the conventions Claude wouldn't discover on its own. Anthropic calls it a starter to refine.

For example, a local instruction could say that a client directory is generated and name the schema to edit instead. Supply your real paths and generator command.

Keep the broader operating manual and refactor procedure in project context for safe refactors.

Exclude generated output with permission rules

A sentence in CLAUDE.md expresses intent. Configure permissions as well when you want generated output excluded from Claude's built-in file tools.

settings.json needs particular care in a package-launched session. Project .claude/settings.json files aren't inherited from parent directories like CLAUDE.md, so put the configuration in the directory you start from, verify the active sources, and avoid assuming a root file reached the package session. See settings files and precedence.

For the illustrative packages/api session above, merge these entries into packages/api/.claude/settings.json.

Adapt Anthropic's generated-file Read exclusions and matching Edit rules to your paths.

{
  "permissions": {
    "deny": [
      "Read(./**/dist/**/*)",
      "Read(./**/build/**/*)",
      "Read(./**/*.generated.*)",
      "Read(./**/vendor/**/*)",
      "Edit(./**/dist/**/*)",
      "Edit(./**/build/**/*)",
      "Edit(./**/*.generated.*)",
      "Edit(./**/vendor/**/*)"
    ]
  }
}

Use /status to inspect the active settings sources and /permissions to inspect the rules. Adapt the paths to the package you launched from.

These rules have a narrower reach than a sandbox. They cover built-in file tools and recognized explicit paths in shell commands, but recursive searches from a parent directory can still include denied files, and arbitrary subprocesses can access them indirectly, so don't describe the JSON above as an operating-system barrier. Anthropic documents what Read and Edit rules cover.

Also check what you're excluding. If a generated interface is necessary to understand a caller, decide how to expose the relevant contract without inviting hand edits to the generated implementation.

A recorded session that crosses the package boundary

I build Pharaoh, which maps repository structure and answers questions about it over MCP. It supports TypeScript, JavaScript, Python, C and C++, though a repository with more than 20 MB of C and C++ maps its other languages only.

The Claude Code connection guide covers setup.

The tool overview explains the available queries.

Here is a read-only investigation captured on the public Pharaoh-so/cal.diy repository at revision 54343aa6.

Start with the auth module. Ask Claude to use get_module_context for features/auth and identify callers outside it.

get_module_context returns the module profile, including exports and outside callers. This excerpt is trimmed by removing whole lines from the captured result:

# Module: features/auth

## Structure
43 files, 5,342 LOC, 99 functions

## External Callers

### api/v2
- apps/api/v2/src/modules/atoms/services/event-types-atom.service.ts: getEventTypesAppIntegration() → checkAdminOrOwner()
### app-store/_utils
- packages/app-store/_utils/getConnectedApps.ts: getConnectedApps() → checkAdminOrOwner()
### trpc/server
- packages/trpc/server/routers/viewer/ooo/outOfOfficeEntriesList.handler.ts: outOfOfficeEntriesList() → checkAdminOrOwner()
### web/modules
- apps/web/modules/data-table/components/segment/DuplicateSegmentDialog.tsx: DuplicateSegmentDialog() → checkAdminOrOwner()

The useful result is already outside auth. The API service calls checkAdminOrOwner, an app-store utility calls it too, and there are consumers in the web app, so the next question should follow that function rather than expanding into an indiscriminate repository tour.

Ask for get_blast_radius on checkAdminOrOwner at depth 3. This second excerpt, from the same repository and revision, removes whole lines without changing the remaining output.

# Blast Radius: checkAdminOrOwner (function, 3 hops)

## Affected Callers (14)

### api/v2
- apps/api/v2/src/modules/atoms/controllers/atoms.conferencing-apps.controller.ts: AtomsConferencingAppsController.listUserInstalledConferencingApps (3 hops)
- apps/api/v2/src/modules/atoms/controllers/atoms.event-types.controller.ts: AtomsEventTypesController.getAtomEventTypeApp (2 hops)
- apps/api/v2/src/modules/atoms/services/conferencing-atom.service.ts: ConferencingAtomsService.getUserConferencingApps (2 hops)
- apps/api/v2/src/modules/atoms/services/event-types-atom.service.ts: EventTypesAtomService.getEventTypesAppIntegration

get_blast_radius excludes test-file callers. Use those production paths to choose the next files to inspect, then find the relevant tests locally, check the current implementation, and ask whether the proposed change affects the behavior each consumer depends on. For the full method, see finding the callers and tests a change reaches and the docs case study on tracing a code change.

There is a revision limit here. Pharaoh's graph covers the default branch, so inspect branch changes locally, check any uncommitted edits, and use the graph as a record of the mapped revision. A live repository re-maps after a push to its default branch; pharaoh_account can request a refresh.

pharaoh_recon can combine module profiles with searches and impact queries in one call. Use it when you already have several related questions.

Watch context while exploration grows

Run /context after the first round of discovery. It shows the current context usage, and its Memory files list confirms which CLAUDE.md files loaded for the package you started in.

Use /compact to summarize the conversation and free space, optionally specifying what to retain. See the command reference.

Before compacting, ask Claude to preserve the target revision and the unresolved caller questions, keep the agreed edit boundaries, and retain the validation commands you checked. For the detailed window-management workflow, use context limits on long sessions.

Subagents help when exploration would otherwise dominate the main conversation. Each runs in its own context, returns its findings to the parent, and has its own tools and permissions, with Write and Edit denied for the built-in Explore agent.

The subagent documentation also says Explore starts without your CLAUDE.md files.

Give it the constraints it needs. For the recorded auth example, a request could be:

Use an Explore subagent to inspect the API callers of checkAdminOrOwner.
Read only. Report file paths and the behavior each caller relies on.
Include any unresolved references.
Return a short summary to this conversation.

That is an example prompt, not another captured result. Review its findings against the actual files before deciding that the investigation is complete.

Use the boundary as a starting point

For the next package task, choose the starting directory deliberately, check which settings loaded, and ask for outside callers before editing. If the result names another package, expand the investigation there and keep the implementation scope explicit.

A practical decision rule is:

  1. Start in the package that owns the code you expect to change.
  2. Ask Claude to identify callers outside that package before proposing edits.
  3. If a caller belongs to a sibling package, add only that directory or restart from the repository root if the change clearly spans several packages.
  4. Before editing, record the target files, the callers to verify, and the package-specific validation command.
  5. After the edit, inspect the diff and run the recorded validation commands.

For example, for a change in packages/api that may affect packages/shared, begin in packages/api, inspect its loaded instructions with /context or settings with /status, and ask for the external callers of the target function. If the investigation reaches packages/shared, use --add-dir ../shared and keep the prompt explicit about whether shared code may be edited. If the task instead requires coordinated changes in both packages, move the session to the repository root and name both packages in the scope.

For choosing context sources, see how much repository context Claude needs.

If you work in both tools, see the same workflow in Cursor.

Connect Pharaoh.

Start with one module whose callers you want to check.

Article Record

ReferencesPrimary sources used for this article
  1. Set up Claude Code in a monorepo or large codebase
  2. Best practices for Claude Code
  3. How Claude remembers your project - Claude Code Docs
  4. Configure permissions
  5. Settings files and precedence
  6. Create custom subagents - Claude Code Docs
  7. Commands
  8. CLI reference
  9. How Claude Code works in large codebases: Best practices and where to start | Claude
  10. How to Make Claude Code Work Reliably in Large Codebases | André Bremer
Update HistoryMeaningful revisions to this article
Practical Example Added
  • Added a practical example to show how to use a code boundary as a starting point.
Initial publication.

More in Claude Code

← Back to blog