Skip to content

Read tool 50 KB byte cap undocumented in tool description - AI may edit based on incomplete content #30773

Closed

Description

Description

The Read tool at packages/opencode/src/tool/read.ts has a 50 KB byte cap (MAX_BYTES = 50 * 1024 at line 17) on total output, in addition to the documented 2000-line limit. However, the tool description in packages/opencode/src/tool/read.txt only mentions the line limit:

By default, this tool returns up to 2000 lines from the start of the file.

The 50 KB byte limit is NOT mentioned. This means an AI told "up to 2000 lines" may believe it has the full file content when lines 166-175 actually cut off output early due to the byte cap. For example, a TypeScript file with approximately 400 lines of 130-byte width (typical for long function signatures, template literals, etc.) would hit 50 KB before reaching 2000 lines.

The AI gets a truncated: true flag in metadata (line 376) and a text note:

(Output capped at 50 KB. Showing lines X-Y. Use offset=Z to continue.)

But there is no mechanism forcing the AI to continue reading. The AI can proceed to edit based on partial content.

Affected code in packages/opencode/src/tool/read.ts lines 14-18:

const DEFAULT_READ_LIMIT = 2000
const MAX_LINE_LENGTH = 2000
const MAX_BYTES = 50 * 1024
const MAX_BYTES_LABEL = `${MAX_BYTES / 1024} KB`

Plugins

N/A (source code analysis)

OpenCode version

main

Steps to reproduce

  1. Read source code at packages/opencode/src/tool/read.ts
  2. Note MAX_BYTES = 50 * 1024 at line 17
  3. Read read.txt tool description — no mention of byte cap
  4. AI reading a file of ~400 lines with typical line width may hit 50 KB cap before reaching 2000-line limit

Screenshot and/or share link

N/A (we read the source code)

Operating System

N/A (code analysis, not environment-specific)

Terminal

N/A

Activity

  1. github-actions commented on Jun 4, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. rekram1-node commented on Jun 4, 2026

    @rekram1-node
    Contributor

    send a session where the agent didnt properly understand this and we can tweak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions