Claude Code re-reading entire codebase (2026)
The Problem
Claude Code is reading the same files over and over, re-executing the same grep searches, and re-discovering project structure on every message. Each redundant file read costs 150 tokens overhead plus the file content (500-5,000+ tokens). Five redundant reads per message across a 20-message session wastes 50,000-200,000 tokens. At Opus 4.6 rates, that is $0.75-$15.00 in pure waste per session.
Quick Fix (2 Minutes)
- Add a CLAUDE.md rule: “Do not re-read files that are already in the conversation context.”
- Run
/compactwith a focus directive that explicitly tells the summarizer to preserve file content summaries. - Restate the task with file paths included so the agent does not need to rediscover them.
# Add to CLAUDE.md immediately:
## File Reading Rules
- Before reading any file, check if its contents are already in the conversation
- Never run the same grep or glob search twice in a session
- If a file was read in the last 10 turns and has not been modified, do not re-read it
- Reference file contents from memory, not by re-reading
Why This Happens
Three causes drive redundant file reading:
-
Post-compaction amnesia – after
/compact, the agent loses detailed file content from the summary. It re-reads files to recover information that was compacted away. This is the most common cause, accounting for an estimated 60% of redundant reads. -
Lack of context awareness – the agent does not always track which files are already in its context window. Without an explicit reminder, it defaults to reading files “to be sure,” especially for long sessions with many exchanges.
-
Prompt-triggered re-exploration – when the user provides a new prompt that references a module or feature, the agent interprets this as a signal to re-explore the relevant code, even if it already has the content in context.
The cost mechanism: each file re-read adds the full file content to the context again. If a 200-line file (approximately 1,500 tokens) is re-read 5 times, that is 7,500 tokens of duplicated content, plus 750 tokens of Read tool overhead, totaling 8,250 wasted tokens.
The Full Fix
Step 1: Diagnose
# Check for redundant reads in the conversation:
# Look for patterns like:
# - Same file path appearing in multiple Read tool calls
# - Same grep pattern being run multiple times
# - Directory listing (ls, glob) of the same directory
# Check the token cost
/cost
# If input tokens are growing faster than expected (>5K per exchange
# with no new information), redundant reads are likely the cause
Step 2: Fix
Add explicit file-tracking rules to CLAUDE.md:
# CLAUDE.md -- redundant read prevention
## File Context Tracking
- Maintain a mental list of files already read in this session
- Before calling Read: check if the file content is already in the conversation
- Before calling Grep: check if the same search was already performed
- After /compact: the following files may need re-reading (but check the summary first):
[List key files for the current task]
## Read Efficiency Rules
- Use offset and limit to read only the specific section needed
- For files over 200 lines: read structure (first 30 lines) then target sections
- Never re-read a file just to "refresh" -- the content has not changed unless explicitly modified
Step 3: Prevent
Structure prompts to include file references so the agent does not need to rediscover:
# Anti-pattern prompt (triggers re-exploration):
"Fix the auth bug"
# Optimized prompt (eliminates re-reads):
"Fix the JWT expiration bug in src/auth/middleware.ts line 47.
The file uses jsonwebtoken v9.0.2, already read earlier in this session.
The issue: token.exp is in seconds but Date.now() returns milliseconds."
Use focused compaction to preserve file content awareness:
/compact Keep: contents of src/auth/middleware.ts (especially lines 40-60), contents of src/auth/token.ts, test results from auth.test.ts, current task description. Discard: initial exploration, package.json contents, directory listings.
Cost Recovery
After identifying redundant reads:
Typical waste: 10K-30K tokens per session in redundant reads
Remaining session (10 turns): 100K-300K tokens of re-sent duplicates
Fix: Add CLAUDE.md rules + compact with focus directive
Expected reduction: 70-90% fewer redundant reads
Token savings: 7K-27K per session * 20 sessions/month = 140K-540K tokens/month
Cost savings at Opus: $2.10-$40.50/month
Cost savings at Sonnet: $0.42-$8.10/month
Prevention Rules for CLAUDE.md
# CLAUDE.md -- copy-paste this section
## No Redundant Reads
- NEVER re-read a file that was read in the last 15 exchanges (unless it was modified)
- NEVER re-run the same grep/glob search in a session
- After /compact: check the compacted summary before re-reading any file
- When referencing file contents: cite from memory ("As seen earlier in middleware.ts line 47...")
- If unsure whether a file is in context: ask the user rather than re-reading
- Maximum file reads per session: 20 (forces efficient reading)
Which model? → Take the 5-question quiz in our Model Selector.
Related Guides
Estimate tokens → Calculate your usage with our Token Estimator.
Try it: Paste your error into our Error Diagnostic for an instant fix.
- The Compaction Strategy: When to /compact and When Not To – preventing post-compaction re-reads
- Structured Metadata vs Discovery Queries – pre-loading context to eliminate discovery reads
- Claude Code Context Window Management – managing what stays in and what gets evicted
Frequently Asked Questions
Does this error affect all operating systems?
This error can occur on macOS, Linux, and Windows (WSL). The exact error message may differ slightly between platforms, but the root cause and fix are the same. macOS users may see additional Gatekeeper or notarization prompts. Linux users should check that the relevant system packages are installed. Windows users should ensure they are running inside WSL2, not native Windows.
Will this error come back after updating Claude Code?
Updates can occasionally reintroduce this error if the update changes default configurations or dependency requirements. After updating Claude Code, verify your project still builds and runs correctly. If the error returns, reapply the fix and check the changelog for breaking changes.
Can this error cause data loss?
No, this error occurs before or during an operation and does not corrupt existing files. Claude Code’s edit operations are atomic — they either complete fully or not at all. However, if the error occurs during a multi-step operation, you may have partial changes that need to be reviewed with git diff before continuing.
How do I report this error to Anthropic if the fix does not work?
Open an issue at github.com/anthropics/claude-code with: (1) the full error message including stack trace, (2) your Node.js version (node --version), (3) your Claude Code version (claude --version), (4) your operating system and version, and (5) the command or operation that triggered the error.