Skip to content

search_file_contents wastes tokens on multi-line result formatting #766

Closed

Description

@will-lamerton

Problem

source/tools/search-file-contents.tsx:83-88 formats each match across three lines:

for (const match of matches) {
    output += `${match.file}:${match.line}\n`;
    output += `  ${match.content}\n\n`;
}

Producing:

Found 12 matches:

source/foo.ts:42
  const x = 1

source/bar.ts:11
  const y = 2

The extra newline, the 2-space indent, and the blank line between matches are all formatting the model does not need.

Fix

Standard grep format, one line per match:

source/foo.ts:42:const x = 1
source/bar.ts:11:const y = 2

Shorter, equally parseable, and it matches what models have seen most in training. Saves roughly 3-4 tokens per match, so about 100 tokens on a default 30-result search (DEFAULT_SEARCH_RESULTS, source/constants.ts:48).

Small on its own, but it is free and completely lossless.

Note contextLines is supported (source/tools/search-file-contents.tsx:75), so whatever format is chosen needs to still read clearly when context lines are present. Standard grep uses - as the separator for context lines rather than :, which would work here too.

Notes for a first-time contributor

Single function, one loop. Tests in source/tools/search-file-contents.spec.tsx will need their expected output updated. Run with pnpm run test:ava source/tools/search-file-contents.spec.tsx.

Activity

  1. will-lamerton commented on Aug 3, 2026

    @will-lamerton
    MemberAuthor

    Part of #772.

  2. added a commit that references this issue on Aug 7, 2026
    881eb51
  3. added
    area:providers
    on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providersclean upgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions