How Do I Give Claude Code Better Context on a Large Repo?

repowise teamUpdated 8 min read
On this page

To give Claude Code better context on a large repo, do three things: keep a short CLAUDE.md of stable rules, clear or compact sessions before they sprawl, and add an MCP server that answers each question from an index. The first two are habits you can start today. The third replaces "read files until you understand" with a query, which is where most of the tokens go. Claude Code stays accurate on a big repo when all three hold.

Part of the guide to giving AI coding agents real codebase context.

Why does Claude Code struggle on large repos?

Every Claude Code session begins with a fresh context window, and everything the agent reads, runs and says has to fit in it. Anthropic's documentation notes that Claude Code sends the full conversation with every request, so a long session pays for its history again on each turn (manage costs, as of November 2026). On a large repo that history fills with file contents the task never needed.

Four sources compete for the window:

SourceWhat it holdsWhy it grows on a large repo
CLAUDE.md and memoryStanding instructions, loaded every sessionEasy to overstuff
File readsSource, tests, generated outputOne broad question reads dozens of files
ConversationPlans, partial fixes, dead endsGrows every turn
Tool outputSearch results, diffs, logsLarge results swamp the useful lines

Scroll the table sideways to see every column.

Three failure patterns follow. A broad prompt ("understand this service") makes the agent open files in bulk. A constraint buried in a long context gets less attention than the most recent file. And people paste READMEs, logs and traces because they do not trust the agent to find them. All three come from unrelated text sitting next to the relevant text.

What belongs in CLAUDE.md?

CLAUDE.md should hold only facts that stay true across tasks: build and test commands, repo layout, conventions and architectural boundaries. Anthropic recommends keeping it under 200 lines, and moving workflow-specific instructions into skills that load on demand (manage costs). The memory documentation covers the scopes (organization, project, user, local) and imports for splitting a large file.

md
# Project memory

## Commands
- uv run pytest tests/unit/ -n 8
- uv run ruff check .

## Layout
- app/core/ owns domain rules
- app/adapters/ talks to external systems
- app/jobs/ holds async work

## Compact instructions
When compacting, keep failing test output and the list of changed files.

The last section is a Claude Code feature: compaction instructions in CLAUDE.md tell /compact what to preserve. Anything that changes per task (who owns a module, what depends on a function, which files are risky) does not belong here. It goes stale, and it belongs in a query.

Which Claude Code habits keep a session small?

Clear between unrelated tasks, compact with a focus, and delegate noisy work to subagents. These are the controls Anthropic documents for managing context:

HabitCommandUse it when
Start fresh/clear (after /rename to find it later)Switching to unrelated work
Summarize with a focus/compact Focus on the failing tests and API changesA long session still has live work
See what is using space/contextThe session feels slow or forgetful
Plan before editingShift+Tab to plan modeA change spans several modules
Isolate verbose outputSubagents for tests, logs, docsA command prints thousands of lines
Name the target"add validation to login in auth.ts"Always: vague prompts trigger broad scans

Scroll the table sideways to see every column.

Source: Claude Code, manage costs, as of November 2026. Claude Code also compacts automatically when the conversation nears the auto-compact window, so /compact is how you choose what survives instead of leaving it to the default. Compaction itself reads the whole conversation, so run it before the session is enormous, not after.

How do MCP tools reduce context on a large codebase?

An MCP tool returns what you asked for, not what the repo contains. The Model Context Protocol lets Claude Code call servers that answer structured questions. A server backed by an index can reply to "what depends on this function?" in a few hundred tokens, where the file-reading route opens every candidate to find out.

Two Claude Code behaviors make this practical. MCP tool definitions are deferred by default (tool search), so only tool names and server instructions enter context until a tool is used. And Claude Code warns when a single tool result passes 10,000 tokens and caps output at 25,000 by default (MAX_MCP_OUTPUT_TOKENS raises it) (MCP docs). A warning is a signal the question was too broad.

repowise indexes the repository once (code graph, git history, generated docs, decisions, health) and serves it through ten MCP tools. Connect it with:

bash
pip install repowise
repowise init

repowise init registers the server with Claude Code and installs its hooks. To wire it by hand, the server runs on stdio:

bash
claude mcp add repowise --transport stdio -- repowise mcp

Each tool maps to a question you would otherwise answer by reading files:

QuestionTool
How is this area structured, and where do I start?get_overview, get_answer
What does this file or symbol do, who calls it, who owns it?get_context, get_symbol
Where is this identifier or concept?search_codebase
How risky is it to edit this file?get_risk
How risky is this diff before I commit?get_change_risk
Why is the code shaped this way?get_why
Which files need refactoring, and which code is dead?get_health, get_dead_code

Scroll the table sideways to see every column.

The full argument reference is in the MCP tools documentation. For a small context window, repowise mcp --tools get_answer,get_context,get_risk serves just the tools you name.

A repowise file page for spec.py in the repowise repository, showing code health, 59 importing files, dependencies, history, decisions and tests
A repowise file page for spec.py in the repowise repository, showing code health, 59 importing files, dependencies, history, decisions and tests

The capture above shows the kind of data get_context returns for a file: health, dependents, history, decisions and test reach, in one response instead of a dozen reads.

How much context does that save?

We measured it on pallets/flask: loading the context for one commit with get_context took 393 tokens, 35.6x fewer than reading every changed file and 3.6x fewer than git diff alone. The sample is the 30 most recent non-merge commits, tokens counted with tiktoken (measured August 2026).

That is one payload, not a whole session: it shows the representation is smaller than the raw source, not that an agent finishes faster. The method, the agent-loop results and the reproduction steps are on the benchmarks page.

A playbook for repos over 100k lines

  1. State one narrow task. "Trace where auth tokens are refreshed" beats "fix auth."
  2. Keep CLAUDE.md short, with commands, layout and compaction instructions only.
  3. Ask for structure first. get_overview or get_answer to find entry points before any file is opened.
  4. Fetch one slice at a time. One module or symbol per get_context call, not "everything about auth."
  5. Check risk before editing. get_risk on a widely imported file surfaces churn, bug history and dependents.
  6. Use plan mode for changes that touch several packages.
  7. Clear or compact at task boundaries. Do not carry a finished task into the next one.
  8. Review before you commit. get_change_risk scores the diff.

For a concrete example of the data behind these calls, browse the FastAPI architecture view and the FastAPI code health page. For other clients, see setting up the repowise MCP server for Claude Code, Cursor and Cline.

Where memory ends and MCP begins

CLAUDE.md carries durable instructions; MCP carries queryable facts. Memory answers "how do we work here": test commands, layout, conventions. MCP answers "what is true of this code right now": what depends on what, who owns a file, where past bugs landed, which code is unreachable. Keep them separate and both stay small.

repowise is open source under AGPL-3.0. The index builds locally, and repowise init needs no API key.

FAQ

My Claude Code agent keeps missing context in our big repo. What should I do?
Narrow the task, shrink CLAUDE.md to stable rules under about 200 lines, and run /clear between unrelated tasks. Then connect an MCP server such as repowise, so the agent asks for one file's dependents, owners and risk instead of opening files until it guesses.
How do I reduce token usage when Claude Code works on a large repository?
Name the target in the prompt, compact with a focus instruction, and delegate noisy output to subagents. An index-backed MCP server cuts file reads: on pallets/flask, one commit's context was 35.6x smaller than reading every changed file.
How does Claude Code handle large codebases?
Claude Code reads files on demand and works inside a finite context window, so large repos need narrow prompts, short standing instructions and regular clearing or compaction. Adding an MCP server that answers from an index lets it fetch one slice per question instead of opening many files.
What is the best way to manage Claude Code context on a monorepo?
Put stable rules in a CLAUDE.md under about 200 lines, use /clear between unrelated tasks, and run /compact with a focus instruction before a session grows. For per-task facts such as dependents, ownership and risk, use MCP tools instead of reading files.
Does Claude Code remember across sessions?
Each session starts with a fresh context window. CLAUDE.md files and auto memory carry knowledge between sessions and are loaded at the start of every conversation (memory docs).
When should I use /compact in Claude Code?
Use it when a session is long but still has live work: the agent repeats itself, forgets constraints or rereads files. Add a focus, for example /compact Focus on the failing tests. If the next task is unrelated, /clear is cheaper.
Do MCP servers use up Claude Code's context?
Claude Code defers MCP tool definitions by default, so only tool names and server instructions enter context until a tool is used. Results over 10,000 tokens trigger a warning, and /mcp lets you disable servers you are not using.
Is CLAUDE.md enough on its own for a large repository?
No. It handles rules and orientation, but not dynamic questions such as ownership, hotspots, dependency paths or dead code. Those are better answered by a tool that queries an index of the repo.