Support for line range with file tagging? #1413

Open
opened 2026-02-16 17:30:51 -05:00 by yindo · 6 comments
Owner

Originally created by @regb on GitHub (Aug 20, 2025).

Originally assigned to: @adamdotdevin on GitHub.

Hello, recently started to use opencode, I like it a lot, thanks for all that hard work!
I've been trying to figure out if there is a way to append line ranges to file tagging in TUI. I've been trying to explore the codebase a bit and it seems the backend supports the concept of file range with the message attachment and the Read tool can thus read specific file-range, and apparently there's a way to pass it with the API. But as far as I can tell, it's not possible to trigger it through the TUI.

The use-case I had in mind is something similar to Cursor, where you can navigate in your editor, select a few lines of code, and use a plugin to attach the file tag with the lines to the opencode input prompt via the TUI API. Not sure how much of a tiny optimization that is compared to sending the entire file, but in my experience that was useful to give precise context to the agent and guide it.

In my tests I've noticed that the agent will usually naturally make the tool call to read the file if you do something like @filepath:10:20, but that's not the same as it requires the agent to make the decision to invoke the Read tool, and it's both less reliable and more expensive than just having opencode pro-actively inline that information before sending to the LLM.

Originally created by @regb on GitHub (Aug 20, 2025). Originally assigned to: @adamdotdevin on GitHub. Hello, recently started to use opencode, I like it a lot, thanks for all that hard work! I've been trying to figure out if there is a way to append line ranges to file tagging in TUI. I've been trying to explore the codebase a bit and it seems the backend supports the concept of file range with the message attachment and the Read tool can thus read specific file-range, and apparently there's a way to pass it with the API. But as far as I can tell, it's not possible to trigger it through the TUI. The use-case I had in mind is something similar to Cursor, where you can navigate in your editor, select a few lines of code, and use a plugin to attach the file tag with the lines to the opencode input prompt via the TUI API. Not sure how much of a tiny optimization that is compared to sending the entire file, but in my experience that was useful to give precise context to the agent and guide it. In my tests I've noticed that the agent will usually naturally make the tool call to read the file if you do something like @filepath:10:20, but that's not the same as it requires the agent to make the decision to invoke the Read tool, and it's both less reliable and more expensive than just having opencode pro-actively inline that information before sending to the LLM.
Author
Owner

@github-actions[bot] commented on GitHub (Aug 20, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #216: Editor integrations - This issue discusses editor integrations that would "see what you have open and selected in neovim, and if it could display diffs in neovim." The use case of selecting lines of code in an editor and passing them to opencode is very similar to what you're requesting with line range support for file tagging.

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Aug 20, 2025): This issue might be a duplicate of existing issues. Please check: - #216: Editor integrations - This issue discusses editor integrations that would "see what you have open and selected in neovim, and if it could display diffs in neovim." The use case of selecting lines of code in an editor and passing them to opencode is very similar to what you're requesting with line range support for file tagging. Feel free to ignore if none of these address your specific case.
Author
Owner

@quantonganh commented on GitHub (Oct 18, 2025):

In my tests I've noticed that the agent will usually naturally make the tool call to read the file if you do something like @filepath:10:20

Have you tried something like this: @filepath:L10-20?

@quantonganh commented on GitHub (Oct 18, 2025): > In my tests I've noticed that the agent will usually naturally make the tool call to read the file if you do something like @filepath:10:20 Have you tried something like this: `@filepath:L10-20`?
Author
Owner

@regb commented on GitHub (Oct 25, 2025):

In my tests I've noticed that the agent will usually naturally make the tool call to read the file if you do something like @filepath:10:20

Have you tried something like this: @filepath:L10-20?

Thanks for the suggestion, unfortunately that doesn't work too. I tried multiple variations, but I don't think the TUI supports this syntax.

@regb commented on GitHub (Oct 25, 2025): > > In my tests I've noticed that the agent will usually naturally make the tool call to read the file if you do something like @filepath:10:20 > > Have you tried something like this: `@filepath:L10-20`? Thanks for the suggestion, unfortunately that doesn't work too. I tried multiple variations, but I don't think the TUI supports this syntax.
Author
Owner

@dennypenta commented on GitHub (Jan 15, 2026):

I found a problem.
warning: I'm reading the codebase the first time ever.

I found the code responsible for line range

apparently web/desktop and tui have different line range syntax.
to perform it in TUI do @filepath#12-42, where #12-42 is :L12-42 for web/desktop (I guess, never used them).
proof it works is here, you can see my prompt and how it calls the read tool with offset and limit: https://opncd.ai/share/H0jN92x0

there are 3 possible things to fix:

  1. documentation, perhaps worth explicitly mention the difference in the clients
  2. tui highlight, when you autocomplete the file to read, adding line range is not going into the highlighted file name. not sure its worth it, because with no triggered autocompletion nothing is highlighted anyway
  3. make line range syntax compatible with desktop, perhaps there are constrains Im not aware of, but from top of my head it's due to historical reasons.

@adamdotdevin wdyt?

@dennypenta commented on GitHub (Jan 15, 2026): I found a problem. warning: I'm reading the codebase the first time ever. I found the code responsible for line range apparently web/desktop and tui have different line range syntax. to perform it in TUI do `@filepath#12-42`, where #12-42 is :L12-42 for web/desktop (I guess, never used them). proof it works is here, you can see my prompt and how it calls the read tool with offset and limit: https://opncd.ai/share/H0jN92x0 there are 3 possible things to fix: 1. documentation, perhaps worth explicitly mention the difference in the clients 2. tui highlight, when you autocomplete the file to read, adding line range is not going into the highlighted file name. not sure its worth it, because with no triggered autocompletion nothing is highlighted anyway 3. make line range syntax compatible with desktop, perhaps there are constrains Im not aware of, but from top of my head it's due to historical reasons. @adamdotdevin wdyt?
Author
Owner

@rekram1-node commented on GitHub (Jan 15, 2026):

yes those are all great ideas that we just havent gotten around to!

@rekram1-node commented on GitHub (Jan 15, 2026): yes those are all great ideas that we just havent gotten around to!
Author
Owner

@ewired commented on GitHub (Jan 21, 2026):

@dennypenta Line range syntax in https://github.com/anomalyco/opencode/pull/4238 was originally @somefile:12-42 and changed to @somefile#12-42 as this was the VS code extension's syntax at the time. Possibly they all need to be unified and that should be a separate issue, as the PR mentioning this is not relevant to what this original issue is asking IMO. This issue is asking about handling mentions in the TUI API again which could be solved by https://github.com/anomalyco/opencode/pull/3996.

@ewired commented on GitHub (Jan 21, 2026): @dennypenta Line range syntax in https://github.com/anomalyco/opencode/pull/4238 was originally `@somefile:12-42` and changed to `@somefile#12-42` as this was the VS code extension's syntax at the time. Possibly they all need to be unified and that should be a separate issue, as the PR mentioning this is not relevant to what this original issue is asking IMO. This issue is asking about handling mentions in the TUI API again which could be solved by https://github.com/anomalyco/opencode/pull/3996.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1413