Skip to content

Conversation

@remorses
Copy link
Contributor

@remorses remorses commented Dec 13, 2025

Line number prefixes (e.g. 00001| ) are only useful when paginating through a file with offset/limit or when referencing a specific line. For small files that fit within the default 2000 line limit, they waste context.

This change adds line numbers only when:

  • User explicitly passes offset or limit (pagination use case)
  • File is truncated (exceeds limit, so user needs line references to continue reading)

The prefix is 7 characters per line. For a typical file with ~40 char average line length, this saves ~15% tokens per file read. Most files read by the tool are under 2000 lines and don't need pagination, so this reduces context usage for the majority of reads.

Also updated the tool description to reflect this behavior.

Related to #1556 (context window management)

Copilot AI review requested due to automatic review settings December 13, 2025 17:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes token usage in the read tool by conditionally adding line numbers only when they're needed for pagination or navigation. Line numbers are now included only when: (1) the user explicitly passes offset or limit parameters, or (2) the file exceeds the default 2000-line limit and is truncated. This saves approximately 15% of tokens (7 characters per line) for the common case of reading complete files under 2000 lines.

Key Changes:

  • Modified line number logic to be conditional based on pagination needs
  • Reordered variable declarations for better logical flow
  • Updated tool description to document the new behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/opencode/src/tool/read.ts Implements conditional line numbering logic by calculating truncation status early and only adding line numbers when paginating or when file is truncated
packages/opencode/src/tool/read.txt Updates documentation to explain when line numbers are added to output

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant