Skip to content

grep tool silently ignores n, so models that drop the dash from -n get no line numbers #5038

Description

@nefayran

Describe the bug

The built-in grep tool shows line numbers only when it gets "-n": true. An argument named n, without the dash, is accepted without an error and ignored, so the matches come back without line numbers.

Models do drop the dash. In 664 headless benchmark runs on 1.0.90, claude-haiku-4.5 passed "n": true in 920 of its 1,949 grep calls and "-n": true in 22. claude-sonnet-5 passed -n in 508 of 571 calls and claude-opus-5.5 in all 53. Without line numbers haiku counted lines in files it opened with view, which also returns no line numbers, and was off by a few: 78 of its 79 wrong answers to "which line…" questions were a wrong line number.

Affected version

1.0.91 (also 1.0.90)

Steps to reproduce the behavior

In a git repository with notes.txt containing alpha, beta, needle here, gamma on four lines:

copilot -p 'Call the grep tool twice and nothing else. First call: {"pattern": "needle", "paths": "notes.txt", "output_mode": "content", "n": true}. Second call: {"pattern": "needle", "paths": "notes.txt", "output_mode": "content", "-n": true}. Then reply with the two raw tool results.' --model claude-haiku-4.5 --allow-all-tools --available-tools grep --output-format json -s

With "n": true the tool returns notes.txt:needle here. With "-n": true it returns notes.txt:3:needle here.

Expected behavior

Either accept n as an alias for -n, or reject unknown arguments with an error the model can see and correct.

Additional context

The counts come from the session logs of a public benchmark: https://github.com/nefayran/code-graph-vs-grep

Activity

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:toolsBuilt-in tools: file editing, shell, search, LSP, git, and tool call behavior

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions