@@ -185,7 +185,7 @@ func NewViewTool(
185185 }
186186
187187 // Read the file content
188− content, lineCount, err := readTextFile(filePath, params.Offset, params.Limit)
188+ content, hasMore, err := readTextFile(filePath, params.Offset, params.Limit)
189189 if err != nil {
190190 return fantasy.ToolResponse{}, fmt.Errorf("error reading file: %w", err)
191191 }
@@ -195,11 +195,9 @@ func NewViewTool(
195195
196196 notifyLSPs(ctx, lspManager, filePath)
197197 output := "<file>\n"
198− // Format the output with line numbers
199198 output += addLineNumbers(content, params.Offset+1)
200199
201− // Add a note if the content was truncated
202− if lineCount > params.Offset+len(strings.Split(content, "\n")) {
200+ if hasMore {
203201 output += fmt.Sprintf("\n\n(File has more lines. Use 'offset' parameter to read beyond line %d)",
204202 params.Offset+len(strings.Split(content, "\n")))
205203 }
@@ -251,38 +249,28 @@ func addLineNumbers(content string, startLine int) string {
251249 return strings.Join(result, "\n")
252250}
253251
254−func readTextFile(filePath string, offset, limit int) (string, int, error) {
252+func readTextFile(filePath string, offset, limit int) (string, bool, error) {
255253 file, err := os.Open(filePath)
256254 if err != nil {
257− return "", 0, err
255+ return "", false, err
258256 }
259257 defer file.Close()
260258
261− lineCount := 0
262−
263259 scanner := NewLineScanner(file)
264260 if offset > 0 {
265− for lineCount < offset && scanner.Scan() {
266− lineCount++
261+ skipped := 0
262+ for skipped < offset && scanner.Scan() {
263+ skipped++
267264 }
268265 if err = scanner.Err(); err != nil {
269− return "", 0, err
270− }
271− }
272−
273− if offset == 0 {
274− _, err = file.Seek(0, io.SeekStart)
275− if err != nil {
276− return "", 0, err
266+ return "", false, err
277267 }
278268 }
279269
280− // Pre-allocate slice with expected capacity
270+ // Pre-allocate slice with expected capacity.
281271 lines := make([]string, 0, limit)
282− lineCount = offset
283272
284273 for scanner.Scan() && len(lines) < limit {
285− lineCount++
286274 lineText := scanner.Text()
287275 if len(lineText) > MaxLineLength {
288276 lineText = lineText[:MaxLineLength] + "..."
@@ -290,16 +278,14 @@ func readTextFile(filePath string, offset, limit int) (string, int, error) {
290278 lines = append(lines, lineText)
291279 }
292280
293− // Continue scanning to get total line count
294− for scanner.Scan() {
295− lineCount++
296− }
281+ // Peek one more line to determine if the file has more content.
282+ hasMore := scanner.Scan()
297283
298284 if err := scanner.Err(); err != nil {
299− return "", 0, err
285+ return "", false, err
300286 }
301287
302− return strings.Join(lines, "\n"), lineCount, nil
288+ return strings.Join(lines, "\n"), hasMore, nil
303289}
304290
305291func getImageMimeType(filePath string) (bool, string) {