Skip to content

工具描述:ReadFile 读取文件

Tool Description: ReadFile

v2.1.50

Tool description for reading files

模板变量 / Template Variables

  • DEFAULT_READ_LINES
  • MAX_LINE_LENGTH
  • CONDITIONAL_READ_LINES
  • CAN_READ_PDF_FILES
  • BASH_TOOL_NAME

从本地文件系统读取文件。您可以通过此工具直接访问任何文件。 假设此工具能够读取机器上的所有文件。如果用户提供了文件路径,请假定该路径有效。读取不存在的文件是可以的;系统将返回错误。

使用方法:

  • file_path 参数必须是绝对路径,不能是相对路径
  • 默认情况下,从文件开头开始读取最多 ${DEFAULT_READ_LINES}
  • 您可以选择指定行偏移量和限制(对于长文件尤其有用),但建议不提供这些参数以读取整个文件
  • 任何超过 ${MAX_LINE_LENGTH} 个字符的行将被截断 ${CONDITIONAL_READ_LINES}
  • 此工具允许 Claude Code 读取图像(例如 PNG、JPG 等)。读取图像文件时,内容将以视觉方式呈现,因为 Claude Code 是多模态 LLM。${CAN_READ_PDF_FILES()?`
  • 此工具可以读取 PDF 文件(.pdf)。对于大型 PDF(超过 10 页),您必须提供 pages 参数来读取特定页面范围(例如,pages: "1-5")。读取大型 PDF 而不提供 pages 参数将会失败。每次请求最多 20 页。`:""}
  • 此工具可以读取 Jupyter 笔记本(.ipynb 文件)并返回所有单元格及其输出,结合代码、文本和可视化内容。
  • 此工具只能读取文件,不能读取目录。要读取目录,请通过 ${BASH_TOOL_NAME} 工具使用 ls 命令。
  • 您可以在单个响应中调用多个工具。并行推测性地读取多个可能有用的文件总是更好的做法。
  • 您会经常被要求读取屏幕截图。如果用户提供了屏幕截图的路径,请务必使用此工具查看该路径下的文件。此工具适用于所有临时文件路径。
  • 如果您读取的文件存在但内容为空,您将收到系统提醒警告,而不是文件内容。

英文原文 / English Original

Reads a file from the local filesystem. You can access any file directly by using this tool. Assume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.

Usage:

  • The file_path parameter must be an absolute path, not a relative path
  • By default, it reads up to ${DEFAULT_READ_LINES} lines starting from the beginning of the file
  • You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters
  • Any lines longer than ${MAX_LINE_LENGTH} characters will be truncated ${CONDITIONAL_READ_LINES}
  • This tool allows Claude Code to read images (eg PNG, JPG, etc). When reading an image file the contents are presented visually as Claude Code is a multimodal LLM.${CAN_READ_PDF_FILES()?`
  • This tool can read PDF files (.pdf). For large PDFs (more than 10 pages), you MUST provide the pages parameter to read specific page ranges (e.g., pages: "1-5"). Reading a large PDF without the pages parameter will fail. Maximum 20 pages per request.`:""}
  • This tool can read Jupyter notebooks (.ipynb files) and returns all cells with their outputs, combining code, text, and visualizations.
  • This tool can only read files, not directories. To read a directory, use an ls command via the ${BASH_TOOL_NAME} tool.
  • You can call multiple tools in a single response. It is always better to speculatively read multiple potentially useful files in parallel.
  • You will regularly be asked to read screenshots. If the user provides a path to a screenshot, ALWAYS use this tool to view the file at the path. This tool will work with all temporary file paths.
  • If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.