Large File Read Memory Spike — Fix (2026)
The Error
Error: File read exceeded memory threshold. File 'database-dump.sql' (248MB)
caused memory allocation failure. Process killed by OOM killer.
This occurs when Claude Code attempts to read a very large file into memory, causing the Node.js process to spike in memory usage and get killed by the operating system.
The Fix
claude "Read only lines 1-100 of database-dump.sql"
- Never ask Claude Code to read entire large files. Specify line ranges instead.
- For files over 1,000 lines, use targeted reads:
"Read lines 500-600 of src/generated/schema.ts". - Use grep-based search to find relevant sections first:
"Search for 'createUser' in database-dump.sql and show surrounding 10 lines".
Why This Happens
Claude Code’s Read tool loads the entire file content into a string, which then gets serialized into the conversation context as a tool result. A 10MB file becomes roughly 10 million characters of context, consuming tens of thousands of tokens and gigabytes of memory during JSON serialization. The Node.js process cannot handle this and gets terminated.
If That Doesn’t Work
Split large files before working with them:
split -l 1000 large-file.sql chunks/chunk_
claude "Read chunks/chunk_aa"
Use the Bash tool to extract only what you need:
claude "Run: head -50 database-dump.sql"
Add the file to Claude Code’s ignore list:
echo "database-dump.sql" >> .claudeignore
Prevention
# CLAUDE.md rule
Never read files larger than 500 lines in full. Use grep or head/tail to extract relevant sections. Add generated files, SQL dumps, and binary files to .claudeignore.
See Also
- Large File Committed Exceeds GitHub Limit Fix
- Claude Code and large package.json — unnecessary context loading
Related Error Messages
This fix also applies if you see these related error messages:
fatal: not a git repositoryerror: failed to push some refsfatal: refusing to merge unrelated historiesTokenLimitExceeded: max tokens reachedError: output truncated at max_tokens
Frequently Asked Questions
Why does Claude Code require git?
Claude Code uses git for several core operations: tracking file changes, creating commits, reading blame information, searching history with git log, and managing branches. Without git, these operations fail and Claude Code falls back to less efficient alternatives.
Can Claude Code work in a non-git directory?
Yes, but with reduced functionality. File search and editing work normally, but version control operations (commit, diff, blame) are unavailable. Claude Code displays a warning when opened in a directory without git initialization.
How do I prevent Claude Code from making unwanted git operations?
Add rules to your CLAUDE.md: Do not create commits automatically. Do not run git push. Always ask before any git operation that modifies history. Claude Code respects these constraints and asks for confirmation before proceeding.
What causes token count mismatches?
Token counts are estimated before sending a request and precisely calculated on the server. The estimation uses a fast local tokenizer that may differ slightly from the server’s tokenizer. Small discrepancies (1-3%) are normal and do not affect functionality.
Estimate usage → Calculate your token consumption with our Token Estimator.
Related Guides
Try it: Paste your error into our Error Diagnostic for an instant fix.