Claude Code Context Limits: How Developers Overcome Them
Part of the Claude Code guide. Start with Claude Code Doesn't Understand Your Codebase? How to Fix It
If Claude starts proposing a fix you've already rejected, check the session before adding another explanation. Run this inside Claude Code:
/context
The answer might be a crowded window, but it could be a caller Claude never read, an assumption carried over from another task, or a requirement that only exists in chat. I wouldn't diagnose all of those as a context limit.
The useful first step is to separate what fits in the session from what the task actually needs.
Check the window your session has
Claude Code's context includes instructions, conversation history, file contents it has read, and tool responses. Your latest prompt is only part of it. Anthropic's context-window guide documents /context as the way to inspect the live breakdown and find suggestions for reducing its size.
Don't assume every session has the same ceiling.
The current model configuration docs describe both 200K and 1M configurations, depending on your model and account, with provider differences too, so run /model to check the selection, then /context to inspect the session itself.
| Command | What to check or change |
|---|---|
/context |
Inspect what's using the current window. |
/model |
Check or change the selected model. |
/compact |
Summarize the current conversation to make room. |
/clear |
Clear the conversation when starting fresh. |
/mcp |
Inspect and manage connected MCP servers. |
A 1M window gives you more room to work. It doesn't tell you which files to load.
Also, Anthropic's Claude Code limits guide calls a full context window "different from a usage limit", with /clear and /compact freeing session space, while usage is metered separately, depending on how you signed in.
Use compaction while the task still makes sense
Claude Code can compact automatically as the window fills. That replaces the conversation with a summary, which makes room for more work, but it can lose a detail you wanted to preserve, so re-check important task constraints before trusting the next edit. Anthropic describes this behavior in its context management guidance.
Anthropic documents different default compaction thresholds for different configurations. Use the session's readout.
If the task is still coherent, you can compact deliberately and supply a focus:
/compact Preserve the goal, changed files, test results, rejected approaches, and next step.
Anthropic's cost-management docs show a focused form of /compact, where the text after the command guides the summary, so name the constraint that matters to this task, then check that constraint against its source afterward, even if the conversation still seems coherent.
A practical sequence for a context-heavy change is:
- Run
/contextand note whether the session still contains the files, tool results, and instructions the next step needs. - If the task remains coherent, run
/compactwith the files to preserve, the failing test, the required behavior, and the next action. - After compaction, ask Claude to restate the goal and constraint before it edits.
- Re-open the relevant contract, test, or implementation and compare it with that restatement.
- If the summary is missing a required detail, stop and use
/clearwith a checked handoff instead of continuing on an assumption.
For example, while changing an authentication helper, preserve the helper's path, its compatibility requirement, the test command and observed result, and any rejected approach. A compacted summary that says only “update authentication” is not enough to resume safely; point Claude back to the source files and test before accepting an edit.
If backward compatibility matters, point Claude back to the contract or test, rather than assuming a sentence in the summary carries everything you agreed earlier, especially when the task has changed direction since that agreement.
When to clear instead
Use /clear between unrelated tasks, or when restarting is easier than correcting the thread, knowing that it clears chat while project files remain, along with CLAUDE.md, as described in the limits guide.
Before clearing ongoing work, save a handoff you can check. Include the goal and exact files, record what failed, name the test command you actually ran, and distinguish a passing result from a test you haven't attempted. Keep the next step small enough that a fresh session can start there.
Handoff template:
Goal:
Files changed:
Constraint that must survive:
Rejected approach and why:
Command run and observed result:
Next action:
Inspect what MCP loads
MCP definitions can take context before a tool runs, though Anthropic's MCP documentation says tool search is enabled by default, deferring full definitions until discovery, while tool names and server instructions still load at startup, so check how your session is configured.
Use /mcp to inspect connected servers, disable the ones this task doesn't need, and compare /context afterward, so you're looking at the effect in your own session. Tool results also occupy space once returned. Deferred definitions don't make a long response free.
If you've seen a 10% threshold mentioned, it belongs to the explicit ENABLE_TOOL_SEARCH=auto mode in those docs. It isn't the current default behavior for all sessions.
Keep durable instructions short, then retrieve the code
Project-root CLAUDE.md gets re-read after compaction, while nested files reload on demand, so keep durable project rules at the root, and reserve the handoff for task progress, as Anthropic's memory docs explain.
Those instructions still use context. They aren't enforced configuration.
For the code itself, start with a named symbol or path, ask for the smallest useful read, and widen the search when a caller leads outside the starting module, rather than asking Claude to absorb the whole repository before you've identified the change.
On the public repository Pharaoh-so/cal.diy, revision 54343aa6, try these ripgrep searches, starting inside auth, then widening to apps and packages.
rg -n 'checkAdminOrOwner' packages/features/auth
rg -l 'checkAdminOrOwner' apps packages
ripgrep's -n includes line numbers in matching results. Start there when you need the definition and nearby code.
ripgrep's -l returns matching file names, which gives you a list to inspect, without loading every file body, and keeps a first pass through a cross-package symbol manageable. These are text matches, so inspect whether each match is a call or something else.
ripgrep can find a name in an import or comment too. Treat the results as leads.
ripgrep also respects ignore rules by default. Remember that when an expected file doesn't appear.
For more, read why Claude Code loses track of your codebase.
What the long-context research actually supports
LongCodeBench tested code comprehension and repair using real GitHub issues. On its LongSWE-Bench bug-fixing task, Claude 3.5 Sonnet's accuracy fell from 29% to 3%, with context increasing from 32K to 256K tokens, and long context was a weakness for every model evaluated. That's an older model on a benchmark, not a measurement of today's Claude Code service.
The recency-bias paper trained GPT-2 small (about 124 million parameters) and GPT-2 medium models. The authors measured attention scores and outputs using cognitive-science methods, which revealed primacy and recency effects across attention heads, so the result concerns those models, rather than modern Claude Code on repositories. It doesn't establish a rule that Claude discards whatever sits in the middle of your session.
And the retrieval study found that document ranking and the documents a generator uses can disagree, across its retrieval-augmented generation experiments, which covered question-answering and conversational search, rather than code repositories, leaving the comparison between tools on your own task untested.
My takeaway is narrower. Check the answer against the code, even when the session has room left.
Use repository structure for a relationship question
If you're asking which endpoints depend on a function, I would ask for that relationship directly, then read the implementation and callers it identifies, rather than starting with a bulk file dump, because those are the files you'll need to verify before editing.
I build Pharaoh. It maps TypeScript, JavaScript, Python, C and C++ repositories into a graph and answers questions over MCP.
Use get_module_context for a module's exports and dependencies. For affected production callers and endpoints, use get_blast_radius.
You can also give get_unused_code a function name to check its path from an entry point.
This is an excerpt of captured get_unused_code output from cal.diy at revision 54343aa6:
# Reachability in cal.diy
- checkAdminOrOwner (packages/features/auth/lib/checkAdminOrOwner.ts): reachable: getAtomEventTypeApp → getEventTypesAppIntegration → checkAdminOrOwner
Read the functions along that path before editing.
Pharaoh's graph covers the default branch of a live repository, updates on every push to that branch, and doesn't include uncommitted edits or other branches, so compare the result with your working copy before changing code. Every repository is live during the trial and on Pro. Tool responses still take context. There is no fixed token cost to promise here.
For more on that structure, see how a code knowledge graph represents relationships.
Keep dead-code classification separate from change blast radius.
Finding no path and finding affected callers answer different questions.
The repository-context case study covers a measured run.
For the spending side, read the Claude Code cost measurements.
Set up Pharaoh for Claude Code.
Start with /context on the task you already have open.
Then pick one answer to verify against the code. If a required caller is missing, find it before you add another file dump.
Article Record
ReferencesPrimary sources used for this article
- Explore the context window
- Models, usage, and limits in Claude Code
- Model configuration
- How Claude remembers your project - Claude Code Docs
- Connect Claude Code to tools via MCP - Claude Code Docs
- Manage costs effectively
- How do usage and length limits work?
- LongCodeBench: Evaluating Coding LLMs at 1M Context Windows
- ripgrep/GUIDE.md at master · BurntSushi/ripgrep
Update HistoryMeaningful revisions to this article
- Added a practical example showing how to use compaction while a task still makes sense.
- Made the guidance easier to apply when working on complex Claude Code tasks.