You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced-usage/available-tools/read-file.md
+83-63Lines changed: 83 additions & 63 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ image: /img/social-share.jpg
20
20
The `read_file` tool examines the contents of files in a project. It allows Roo to understand code, configuration files, documentation, and now images to provide better assistance.
21
21
22
22
:::info Multi-File Support
23
-
The `read_file` tool can read multiple files simultaneously when the `maxConcurrentFileReads` setting is greater than 1. This significantly improves efficiency for tasks requiring analysis of multiple related files.
23
+
The `read_file` tool accepts multiple files via the `args` format. Concurrency and per‑request limits are configured in the UI; the backend tool doesn’t hard‑enforce a file count cap. Some models may use a simplified single‑file variant.
24
24
25
25
**Note:** When reading files (even single files), the LLM will see a message encouraging multi-file reads: "Reading multiple files at once is more efficient for the LLM. If other files are relevant to your current task, please read them simultaneously."
26
26
:::
@@ -43,7 +43,7 @@ While the single-file parameters (`path`, `start_line`, `end_line`) are still su
43
43
44
44
### Enhanced Format (Multi-File)
45
45
46
-
When `maxConcurrentFileReads` is set to a value greater than 1 (found in Settings > Context > "Concurrent file reads limit"), the tool accepts an `args` parameter containing multiple file entries:
46
+
The tool also accepts an `args` parameter containing multiple file entries. Concurrency is UI‑configured; the backend accepts multiple files regardless of that setting. Some models may use a simple single‑file tool.
47
47
48
48
-`args` (required): Container for multiple file specifications
49
49
-`file` (required): Individual file specification
@@ -72,22 +72,22 @@ This tool reads the content of a specified file and returns it with line numbers
72
72
73
73
- Displays file content with line numbers for easy reference
74
74
- Can read specific portions of files by specifying line ranges
-**Multi-file support**: Read multiple files simultaneously with batch approval
85
85
86
86
---
87
87
88
88
## Multi-File Capabilities
89
89
90
-
When the `maxConcurrentFileReads` setting is greater than 1, the `read_file` tool gains enhanced capabilities:
90
+
Multi-file reads are supported. Concurrency and per‑request limits are configured in Settings; the backend tool doesn’t hard‑enforce a file count cap and behavior may be constrained by model/tool selection:
@@ -96,7 +96,7 @@ When the `maxConcurrentFileReads` setting is greater than 1, the `read_file` too
96
96
-**Default**: 5
97
97
98
98
### Batch Processing
99
-
-Read up to 100 files in a single request (configurable, default 5)
99
+
-UI‑configurable limit up to 100 files per request (default 5). Backend doesn’t hard‑enforce a cap; actual behavior may be constrained by model/tool.
100
100
- Parallel processing for improved performance
101
101
- Batch approval interface for user consent
102
102
@@ -116,13 +116,14 @@ When the `maxConcurrentFileReads` setting is greater than 1, the `read_file` too
116
116
117
117
## Limitations
118
118
119
-
-**Large files**: For extremely large files, the tool provides a preview and guides you to use line_range for targeted reading
120
-
-For binary files (except PDF, DOCX, and supported image formats), may return content that isn't human-readable
121
-
-**Multi-file mode**: Requires `maxConcurrentFileReads` > 1 in settings
122
-
-**Image files**: Returns base64-encoded data URLs which may be large for high-resolution images
123
-
- Default max single image size: 20MB
119
+
-**Large files**: For extremely large files, the tool may return a preview and will guide you to use `line_range` for targeted reading.
120
+
-**Binary files**: Except for PDF, DOCX, XLSX, IPYNB, and supported image formats, content may not be human‑readable.
121
+
-**UI/model constraints**: Concurrency limits and per‑request file counts are configured in the UI; the backend tool doesn’t hard‑enforce a cap.
122
+
-**Image files**: Images are provided as base64 data URLs. High‑resolution images can be large.
123
+
- Default max single image size: 5MB
124
124
- Default max total image size: 20MB
125
-
-**Token budget**: Automatically truncates content to fit remaining token budget to prevent context overruns
125
+
-**Unsupported binary formats**: Returns a `<binary_file format="ext">Binary file - content not displayed</binary_file>` placeholder.
126
+
-**Token budget**: Content may be truncated to fit remaining token budget; notices indicate how to proceed.
126
127
127
128
---
128
129
@@ -138,8 +139,8 @@ When the `read_file` tool is invoked, it follows this process:
138
139
4.**Content Processing**:
139
140
- Adds line numbers to the content (e.g., "1 | const x = 13") where `1 |` is the line number.
140
141
- For truncated files, adds truncation notice and method definitions
141
-
- For special formats (PDF, DOCX), extracts readable text
142
-
- For image formats, returns base64-encoded data URLs with MIME type
142
+
- For special formats (PDF, DOCX, XLSX, IPYNB), extracts readable text
143
+
- For image formats, the XML includes a `<notice>` with size; the actual image is attached to the tool result as a base64 data URL (no dimensions returned; MIME type is implied by the data URL)
143
144
144
145
---
145
146
@@ -148,9 +149,9 @@ When the `read_file` tool is invoked, it follows this process:
148
149
The tool uses a clear decision hierarchy to determine how to read a file:
149
150
150
151
1.**First Priority: Explicit Line Range**
151
-
-If either `start_line`or`end_line`is provided, the tool always performs a range read
152
-
-The implementation efficiently streams only the requested lines, making it suitable for processing large files
153
-
-This takes precedence over all other options
152
+
-Legacy single‑file format: both `start_line`and`end_line`must be provided for a range read; otherwise it reads normally.
153
+
-Multi‑file `args` format: specify one or more `line_range` entries per file.
154
+
-Range reads stream only the requested lines and bypass `maxReadFileLine`, taking precedence over other options.
154
155
155
156
2.**Second Priority: Token Budget Management**
156
157
- The tool respects the remaining token budget to prevent context overruns
@@ -160,15 +161,15 @@ The tool uses a clear decision hierarchy to determine how to read a file:
160
161
- Recovers gracefully from stream errors and suggests alternative approaches
161
162
162
163
3.**Third Priority: Automatic Truncation for Large Text Files**
163
-
-This applies only when **all** of the following conditions are met:
164
+
-Applies only when all of the following are true:
164
165
- Neither `start_line` nor `end_line` is specified.
165
-
- The file is identified as a text-based file (not binary like PDF/DOCX).
166
-
- The file's total line count exceeds the `maxReadFileLine` setting (default: 500 lines).
166
+
- The file is identified as a text‑based file (not binary like PDF/DOCX/XLSX/IPYNB).
167
+
- The file’s total line count exceeds the `maxReadFileLine` setting (configurable; UI default may be 500; backend uses `-1`—no line limit—when unset).
167
168
- When automatic truncation occurs:
168
-
- The tool reads only the *first*`maxReadFileLine` lines.
169
-
- It appends a notice indicating truncation (e.g., `[Showing only 500 of 1200 total lines...]`).
170
-
- For code files, it may also append a summary of source code definitions found within the truncated portion.
171
-
-**Special Case - DefinitionsOnly Mode**: When `maxReadFileLine` is set to `0`, the tool returns only source code definitions without any file content.
169
+
- The tool reads only the first `maxReadFileLine` lines.
170
+
- It appends a notice like: `Showing only X of Y total lines. Use line_range if you need to read more lines.`
171
+
- For code files, it appends `list_code_definition_names` for a structure overview.
172
+
-**Special Case – Definitions‑Only Mode**: When `maxReadFileLine` is `0`, the tool returns only code definitions without file content (plus a notice).
172
173
173
174
4.**Default Behavior: Read Entire File**
174
175
- If neither an explicit range is given nor automatic truncation applies (e.g., the file is within the line limit, or it's a supported binary type), the tool reads the entire content.
@@ -246,7 +247,7 @@ When reading a large text file without specifying a line range, the tool automat
246
247
...
247
248
500 | Log entry 500...
248
249
249
-
[Showing only 500 of 1500 total lines. Use start_line and end_line to read specific ranges.]
250
+
Showing only 500 of 1500 total lines. Use line_range to read specific sections.
250
251
// Optional: Source code definitions summary might appear here for code files
251
252
```
252
253
*(Output shows the beginning lines up to the `maxReadFileLine` limit, plus a truncation notice. Use line ranges for full access.)*
@@ -302,9 +303,21 @@ If the file is excluded by rules in a `.rooignore` file:
302
303
<read_file>
303
304
<path>.env</path>
304
305
</read_file>
306
+
```
307
+
308
+
**Simulated Output (Error):**
309
+
```xml
310
+
<file>
311
+
<path>.env</path>
312
+
<error>Access denied by .rooignore rules</error>
313
+
</file>
314
+
```
315
+
316
+
---
317
+
305
318
### Intelligent Reading with Token Budget Management
306
319
307
-
When reading large files, the tool automatically manages token budgets to prevent context overruns:
320
+
When reading large files, the tool automatically manages token budgets to prevent context overruns.
308
321
309
322
**Scenario:** Reading a very large file without specifying a line range.
310
323
@@ -317,17 +330,20 @@ When reading large files, the tool automatically manages token budgets to preven
317
330
318
331
**Simulated Output (for a file exceeding token budget):**
319
332
```
320
-
[First 100KB of file content shown as preview...]
333
+
Preview: Showing first …MB of …MB file. Use line_range to read specific sections.
334
+
```
321
335
322
-
[File exceeds remaining token budget. Showing 100KB preview. Use line_range to read specific sections.]
336
+
Alternative truncation notice:
337
+
```
338
+
File truncated to N of M characters due to context limitations. Use line_range to read specific sections.
323
339
```
324
340
325
-
This intelligent behavior ensures that:
341
+
This behavior ensures that:
326
342
- Small files read completely with zero overhead
327
-
- Large files auto-truncate to fit remaining token budget
343
+
- Large files auto‑truncate to fit remaining token budget
328
344
- Very large files provide a quick preview
329
345
- You receive guidance to use `line_range` for targeted reads
330
-
- Stream errors are recovered gracefully
346
+
- Stream errors are handled gracefully
331
347
332
348
**Example with line_range for targeted reading:**
333
349
```xml
@@ -338,20 +354,6 @@ This intelligent behavior ensures that:
338
354
</read_file>
339
355
```
340
356
341
-
---
342
-
343
-
```
344
-
345
-
**Simulated Output (Error):**
346
-
```xml
347
-
<file>
348
-
<path>.env</path>
349
-
<error>Access denied by .rooignore rules</error>
350
-
</file>
351
-
```
352
-
353
-
---
354
-
355
357
## Image Reading Examples
356
358
357
359
The `read_file` tool now supports reading and displaying images directly in the chat interface. This enables powerful visual analysis workflows.
@@ -367,15 +369,13 @@ The `read_file` tool now supports reading and displaying images directly in the
The image will be displayed directly in the chat interface, allowing Roo to analyze visual content.
378
+
The image is displayed inline in the chat (base64 data URL attached to the tool result). No dimensions are returned; MIME type is implied by the data URL.
379
379
380
380
### OCR Workflow Example
381
381
@@ -436,14 +436,15 @@ Compare these design mockups and provide feedback on:
436
436
### Supported Image Formats
437
437
438
438
The tool supports the following image formats:
439
-
-**PNG** - With dimension extraction
440
-
-**JPG/JPEG** - Standard and progressive
441
-
-**GIF** - Static and animated
442
-
-**WebP** - Modern web format
443
-
-**SVG** - Scalable vector graphics
444
-
-**BMP** - Bitmap images
445
-
-**ICO** - Icon files
446
-
-**TIFF** - Tagged image format
439
+
- PNG
440
+
- JPG/JPEG
441
+
- GIF
442
+
- WebP
443
+
- SVG
444
+
- BMP
445
+
- ICO
446
+
- TIFF/TIF
447
+
- AVIF
447
448
448
449
### Image Analysis Use Cases
449
450
@@ -458,7 +459,7 @@ The tool supports the following image formats:
458
459
459
460
## Multi-File Examples
460
461
461
-
When `maxConcurrentFileReads` is set to a value greater than 1, you can read multiple files simultaneously using the enhanced XML format.
462
+
You can read multiple files simultaneously using the enhanced XML format.
462
463
463
464
### Reading Multiple Complete Files
464
465
@@ -641,3 +642,22 @@ You can read different types of files in a single request:
641
642
642
643
This allows Roo to analyze documentation, visual diagrams, configuration, and specifications all in one context.
643
644
645
+
---
646
+
647
+
## Troubleshooting
648
+
649
+
- Range read returns error
650
+
- Cause: `start_line`/`end_line` invalid or `start_line > end_line`
651
+
- Fix: Provide both `start_line` and `end_line` as positive integers with `start_line ≤ end_line`; or use `args` with one or more `line_range` entries.
652
+
- Prevention: Prefer `line_range` in the multi‑file format for targeted reads.
653
+
654
+
- Large file returned a preview
655
+
- Cause: File exceeded token budget or the large‑file tokenization threshold; a preview was returned.
656
+
- Fix: Use `line_range` to request only the section you need; reduce requested ranges.
657
+
- Prevention: Adjust `maxReadFileLine` in Settings, or prefer targeted ranges on large files.
658
+
659
+
- Image not displayed
660
+
- Cause: Model may not support images, or image limits exceeded (5MB per image; 20MB total per request).
661
+
- Fix: Switch to a vision‑capable model; reduce image size; request fewer/smaller images.
662
+
- Prevention: Keep images within limits and use supported formats (PNG, JPG/JPEG, GIF, WebP, SVG, BMP, ICO, TIFF/TIF, AVIF).
0 commit comments