packages/kilo-docs/pages/automate/tools/read-file.md
The read_file tool examines the contents of files in a project. It allows Kilo Code to understand code, configuration files, and documentation to provide better assistance.
The tool accepts these parameters:
path (required): The path of the file to read relative to the current working directorystart_line (optional): The starting line number to read from (1-based indexing)end_line (optional): The ending line number to read to (1-based, inclusive)auto_truncate (optional): Whether to automatically truncate large files when line range isn't specified (true/false)This tool reads the content of a specified file and returns it with line numbers for easy reference. It can read entire files or specific sections, and even extract text from PDFs and Word documents.
When the read_file tool is invoked, it follows this process:
path parameter and optional parameters1 | is the line number.The tool uses a clear decision hierarchy to determine how to read a file:
First Priority: Explicit Line Range
start_line or end_line is provided, the tool always performs a range readSecond Priority: Auto-Truncation for Large Files
start_line nor end_line is specifiedauto_truncate parameter is set to trueDefault Behavior: Read Entire File
Here are several scenarios demonstrating how the read_file tool is used and the typical output you might receive.
To read the complete content of a file:
Input:
<read_file>
<path>src/app.js</path>
</read_file>
Simulated Output (for a small file like example_small.txt):
1 | This is the first line.
2 | This is the second line.
3 | This is the third line.
(Output will vary based on the actual file content)
To read only a specific range of lines (e.g., 46-68):
Input:
<read_file>
<path>src/app.js</path>
<start_line>46</start_line>
<end_line>68</end_line>
</read_file>
Simulated Output (for lines 2-3 of example_five_lines.txt):
2 | Content of line two.
3 | Content of line three.
(Output shows only the requested lines with their original line numbers)
When reading a large file without specifying lines and auto_truncate is enabled (or defaults to true based on settings):
Input:
<read_file>
<path>src/large-module.js</path>
<auto_truncate>true</auto_truncate> <!-- Optional if default is true -->
</read_file>
Simulated Output (for large_file.log with 1500 lines, limit 1000):
1 | Log entry 1...
2 | Log entry 2...
...
1000 | Log entry 1000...
[... truncated 500 lines ...]
(Output is limited to the configured maximum lines, with a truncation notice)
If the specified file does not exist:
Input:
<read_file>
<path>non_existent_file.txt</path>
</read_file>
Simulated Output (Error):
Error: File not found at path 'non_existent_file.txt'.
If the file is excluded by rules in a .kilocodeignore file:
Input:
<read_file>
<path>.env</path>
</read_file>
Simulated Output (Error):
Error: Access denied to file '.env' due to .kilocodeignore rules.