> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cowagent.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# read - 文件读取

> read 工具读取文件内容，支持文本、PDF、Word / Excel / PPT 等 Office 文档和图片元数据，输出带行号，单次最多读取 2000 行或 50KB，可通过 offset 分段读取，并保护凭证文件。

读取文件内容。支持文本文件、PDF、Office 文档（Word / Excel / PPT）、图片（返回元数据）等格式。

## 依赖

无额外依赖，默认可用。

## 参数

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `path` | string | 是 | 文件路径，相对路径基于工作空间目录 |
| `offset` | integer | 否 | 起始行号（从 1 开始），负值表示从末尾倒数，如 `-50` 读最后 50 行 |
| `limit` | integer | 否 | 读取行数 |
| `pages` | string | 否 | 仅 PDF 有效，指定页码范围，如 `3`、`1-5`、`10-`。默认前 20 页，单次最多 20 页 |

## 输出格式

每行前面会带上行号和一个竖线，便于 Agent 定位位置、并与 `search_files` 的输出保持一致：

```
1|from config import conf
2|
3|def main():
4|    print(conf())
```

> [!NOTE]
>
> 行号是显示用的，不是文件内容。用 `edit` 修改文件时，`oldText` / `newText` 里不要带 `1|` 这样的前缀，否则会被拒绝。

单次读取上限为 2000 行或 50KB，超出会截断，并在末尾提示如何用 `offset` 继续读取下一段。

## 凭证保护

存放 API Key 的 `~/.cow/.env` 不允许通过本工具读取，请使用 `env_config` 工具管理。

## 使用场景

* 查看配置文件、日志文件
* 读取代码文件进行分析
* 提取 PDF、Word、Excel 中的文本
* 检查图片/视频的文件信息


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.