anomalyco / anomalyco/opencode

read tool's directory pagination hint is off by one entry

Open
#45,187 0 comments 0 reactions 1 assignee View on GitHub

@neriousy is already working on this.

Since Aug 26, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

When read is pointed at a directory with more entries than fit in one page, the continuation hint it gives the model names the wrong entry, so following it literally skips one.

packages/opencode/src/tool/read.ts:280:

truncated
  ? `\n(Showing ${sliced.length} of ${items.length} entries. Use 'offset' parameter to read beyond entry ${offset + sliced.length})`
  : `\n(${items.length} entries)`,

offset is 1-indexed and start = offset - 1, so with offset = 1 and 100 entries shown, entries 1–100 were returned and offset + sliced.length is 101 — the first entry not yet shown. The sentence tells the model to read beyond entry 101, i.e. to start at 102, which drops entry 101.

The file branch of the same tool gets this right and is unambiguous:

output += `\n\n(Showing lines ${file.offset}-${last} of ${file.count}. Use offset=${next} to continue.)`

It states the inclusive range that was shown and the exact offset value to pass next, rather than asking the model to do the arithmetic. The directory branch should match that.

Since this text is consumed by a model rather than a person, the ambiguity turns into a silently missing directory entry rather than a visible error.

Steps to reproduce
  1. read a directory containing more than 2000 entries (or pass an explicit small limit).
  2. Read the continuation hint at the end of the output.
  3. Following it as written starts one entry past the first unread one.
Operating System

Windows 11 (platform independent)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.