Add offset and size parameters to read_file tool#19
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017kEbY4DcgDd5sKMSauxyWf
There was a problem hiding this comment.
Code Review
This pull request updates the read_file tool to support partial reads by introducing optional offset and size parameters, along with corresponding unit tests. The feedback highlights potential issues with byte-level slicing of multi-byte UTF-8 characters, which could lead to decoding errors, and suggests handling this gracefully. Additionally, the reviewer recommends validating that offset and size are non-negative to prevent unexpected behavior, and adding tests to cover these edge cases.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 891aa7f93f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if offset: | ||
| f.seek(offset) | ||
| data = f.read(size) if size is not None else f.read() | ||
| return data.decode("utf-8") |
There was a problem hiding this comment.
Handle UTF-8 chunks split at byte boundaries
When the requested byte window cuts through a multi-byte UTF-8 character, this decode raises UnicodeDecodeError and the tool returns an error even though the file is valid UTF-8; for example size=1 on a file starting with é, or an offset into that character, fails. Since the new API exposes arbitrary byte offsets and sizes, partial reads of non-ASCII text only work when callers happen to choose character-aligned ranges, so the tool should tolerate or adjust boundary splits instead of treating them as read failures.
Useful? React with 👍 / 👎.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary
Extends the
read_filetool to support partial file reads via optionaloffsetandsizeparameters, enabling efficient reading of specific byte ranges from files.Key Changes
offset(int, default 0) andsize(int | None, default None) parameters toread_file.call()"rb") to support byte-level offset/size operations, then decode the result to UTF-8f.seek(offset)to position the file pointer before readingsizeparameter when provided; reads to EOF ifsizeis NoneImplementation Details
"rb") allows precise byte-level control viaseek()andread(size)https://claude.ai/code/session_017kEbY4DcgDd5sKMSauxyWf