Skip to content

fix(cli): reduce read context overhead from line prefixes#10610

Open
marius-kilocode wants to merge 2 commits into
mainfrom
fix-read-prefix-context-overhead
Open

fix(cli): reduce read context overhead from line prefixes#10610
marius-kilocode wants to merge 2 commits into
mainfrom
fix-read-prefix-context-overhead

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Why this change

Ordinary text reads currently add a line-number prefix to every returned source line, even though Kilo edits match source text or patch context rather than displayed line positions. This adds repeated context overhead on a high-frequency tool path without providing input required by the editing tools.

Current model-visible output:

<path>/repo/src/a.ts</path>
<type>file</type>
<content>
41: const a = 1
42: export { a }

(End of file - total 42 lines)
</content>

This PR returns the ordinary source text instead:

<path>/repo/src/a.ts</path>
<type>file</type>
<content>
const a = 1
export { a }

(End of file - total 42 lines)
</content>

Partial reads still report their original line range in the continuation notice, so bounded navigation remains available without repeating positional prefixes on every content line.

Measured motivation

This change is based on an aggregate internal measurement of completed Kilo read tool outputs, not only on an implementation hypothesis. We measured the model-visible text attributable to the repeated line-number prefixes and found that they account for about 10% of stored read output payload in the analyzed sample.

That percentage describes removable context text, not exact billed tokens or cost. Tool outputs can be retained, cached, or replayed in later model steps, so paired before/after session accounting is still needed to quantify the billing impact. Absolute usage, token, and cost figures are intentionally not included here.

Why line prefixes are removable

  • Kilo edit uses exact or flexible textual oldString replacement; displayed line-number prefixes are not consumed by the tool.
  • Kilo apply_patch locates contextual source chunks rather than applying changes at displayed line positions.
  • Removing prefixes makes read text directly reusable for exact-text edits and reduces model-visible output growth after raw source lines have already been budgeted.
  • The tradeoff is less immediate line-by-line citation from a single read. Range notices and line-located search results remain available, and citation usability can be evaluated after rollout.

Preserved behavior

This PR intentionally changes only the repeated line prefixes for ordinary text file contents.

Behavior Decision
<path>, <type>, and <content> envelope Preserved
Partial-read range and end-of-file notices Preserved
Nested <system-reminder> delivery for scoped instructions Preserved
Directory and binary/image handling Preserved
Read/edit prompting Updated to match raw source-text output

Upstream origin and intent

The numbered format is inherited upstream behavior, originally chosen for navigation clarity rather than edit correctness.

Upstream history Relevance to this PR
Initial traceable numbered view commit Described displaying file contents with line numbers for easy reference; GitHub does not associate this commit with a PR.
PR #10678 Added dynamic nested AGENTS.md resolution as an agent explores directories. That separate correctness behavior is retained here.
PR #13090 Added the structured <path>, <type>, and <content> read output and adjusted editing guidance. The structural envelope is retained here.
PR #13198 Made read offsets 1-based to align with displayed line numbers. This PR keeps range accounting and notices 1-based.
PR #21070 Added newline separation after <content> to make the structured result unambiguous. That clarity behavior is retained here.

Comparable harness behavior

Other agent harnesses show that text editing and scoped navigation do not require mandatory prefixes on every source line.

Harness Relevant behavior
pi v0.75.5 Returns ordinary read content as source text and edits by textual replacement.
Gemini CLI Supports ranged reads without prefixing every returned source line; its replacement tool consumes source text, and its read path also supports just-in-time scoped context.
Codex CLI Its core editing flow is contextual apply_patch, without relying on a mandatory dedicated numbered file-read output.
Claude Code v2.1.86 Retains numbered reads, but specifically reduced their token usage through compact numbering and unchanged-read deduplication.

Follow-up measurement

The intended outcome is lower read-related prompt context without a meaningful regression in editing or navigation. Evaluation should compare model-visible read output, prompt-side usage, edit retries, and file-location reporting quality before making a quantitative savings claim about billed usage or cost.

@marius-kilocode marius-kilocode enabled auto-merge May 27, 2026 11:54
@kilo-code-bot

kilo-code-bot Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The change is a clean, well-scoped one-liner in read.ts with correct kilocode_change annotation, updated prompt/tool descriptions, and matching test coverage. The test updates properly flip the positive prefix assertions to negative guards and add a regression check for the bounded-read range notice.

Files Reviewed (6 files)
  • .changeset/trim-read-prefixes.md
  • packages/opencode/src/session/prompt/ling.txt
  • packages/opencode/src/tool/edit.txt
  • packages/opencode/src/tool/read.ts
  • packages/opencode/src/tool/read.txt
  • packages/opencode/test/tool/read.test.ts

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-4.6 · 489,383 tokens

Review guidance: REVIEW.md from base branch main

@marius-kilocode marius-kilocode disabled auto-merge May 27, 2026 13:58
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