Fixing Roo Code's read_file Tool That Silently Truncates Large Files and Misses Content Past the Cutoff
Asked whether a particular function or setting exists in a large file, Roo Code confidently reports that it doesn't — but it's actually sitting a few hundred lines past where the read_file tool's output quietly stopped. The tool has a line-count ceiling per call, and a file that exceeds it gets read only up to that point, with the missing tail easy to overlook in the returned content itself.
The Problem
A task asks Roo Code to check whether a particular function, configuration key, or import exists somewhere in a large file — a generated file, a long configuration, or a big data module. Roo Code reads the file with its read_file tool and reports back confidently that the item isn't present. It's actually there, sitting a few hundred lines further down than where the tool's returned content stopped — the file was large enough that only its first portion was ever actually read, and nothing about the way the output was presented made that limitation obvious enough to catch before concluding the search was complete.
Why It Happens
read_file has a maximum amount of content it returns per call, and a file larger than that limit is read only up to the cutoff point
Roo Code's read_file tool, like most file-reading tools built for use by an LLM, caps how much content a single call returns — typically by line count — to keep individual tool results within a manageable size. A file that exceeds this cap doesn't produce an error or a refusal; it produces a successful-looking result containing exactly the first portion of the file, up to the limit, with everything past that point simply absent from what comes back.
The truncation point is based purely on size, with no awareness of where logically meaningful content in the file actually sits
The cutoff is a raw line-count or size boundary, not something that understands the file's structure — a function definition, a configuration section, or an import block that happens to start just past that line count is cut off mid-content or omitted entirely, with no special handling that tries to stop at a more meaningful boundary. Whether the thing being searched for falls before or after the cutoff is effectively arbitrary from the tool's point of view.
A truncation indicator is easy to miss when skimming a long tool result, especially when the task is framed as a yes/no question
Depending on the exact version and how the result is presented, there may be some indication that the content was cut off — a line count summary, a note about remaining lines — but when the task at hand is phrased as a simple presence check ("does X exist in this file?"), it's easy to read the returned content, not find X, and conclude the answer is no without specifically checking whether the read actually covered the entire file or stopped partway through.
The Fix
1. Check the read result's line-count metadata before treating the content as complete
After calling read_file, compare the number of lines actually returned
against the file's real total line count (e.g. from a prior ls -la or
wc -l on the file) — don't assume the returned content is the whole file
just because the call succeeded without an error.
A successful tool call and a complete read of the file are two different things, and the only reliable way to tell them apart is to explicitly compare how much was returned against how much the file actually contains — treating "no error" as equivalent to "I saw everything" is exactly the assumption that causes this problem.
2. For a file known or suspected to be large, read it in explicit line-range chunks rather than one open-ended call
read_file(path, start_line=1, end_line=500)
read_file(path, start_line=501, end_line=1000)
# ...continuing until the file's actual end is reached, rather than
# assuming one call covered everything.
Reading a large file in deliberate, bounded chunks that explicitly cover its full known length — rather than one call and hoping it was enough — guarantees the entire file is actually seen, turning an implicit assumption about coverage into something that was explicitly verified chunk by chunk.
3. For a targeted search rather than a full review, use search_files or codebase_search first to locate the relevant section, then read_file around that specific location
search_files(path, regex="functionName") -> returns the matching line number
-> read_file(path, start_line=, end_line=)
When the actual goal is finding one specific thing rather than reading an entire file, searching first for its exact location and then reading a targeted window around that line sidesteps the truncation question entirely — there's no risk of missing content past a cutoff when the read is centered directly on where the thing actually is.
4. For a correctness-critical "does this NOT exist" claim, explicitly confirm full file coverage before accepting a negative result
Before concluding something is absent from a file, explicitly state and
verify: "the file is N lines total, and lines 1 through N were all read" —
treat an unverified negative result on a large file as inconclusive
rather than a confirmed answer.
A negative result — "this doesn't exist in the file" — carries real risk if it's wrong, so for anything where that conclusion actually matters, explicitly confirming the read covered the file's full known length before accepting the negative turns an assumption into a checked fact, catching exactly the case where a truncated read would otherwise be mistaken for a complete one.
Why This Works
A missed function or setting past a truncation cutoff isn't a sign read_file is unreliable — it's doing exactly what a size-capped tool is supposed to do, returning a successful, complete-looking result for exactly the portion of the file it actually read, with no awareness of whether that portion happened to contain everything relevant to the task. Checking the actual line counts, reading large files in explicit covering chunks, searching for a specific target before reading around it, and verifying full coverage before trusting a negative result all replace an assumption about completeness with something that was actually confirmed.
Conclusion
A conclusion based on a large file read that quietly stopped partway through is a truncated read mistaken for a complete one, not an unreliable search. Checking the returned line count against the file's actual size, reading large files in explicit range-bounded chunks, searching for a specific target before reading around its location, and verifying full coverage before accepting a negative result together turn a silent, easy-to-miss truncation into content that's either fully covered or known to be incomplete.
