opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Quotes in code getting stripped in model output

Open jdanbrown opened this issue 2 weeks ago • 8 comments

Description

This one is bizzare: I asked openrouter/anthropic/claude-sonnet-4.5 to generate some vscode keybindings.json stuff for me, and the json in its response had no quotes. I asked it to fix it, and it gave me json with no quotes again. Then I used mitmproxy to snoop on the wire traffic, and the model responses actually include the quotes, but opencode is somehow failing to show them in its code blocks in the model output.

Here's mitmproxy on the left showing the model response with quotes, and opencode on the right showing the model response without quotes:

  • mitmproxy on the left: ...\"key\": \"ctrl+m\"...
  • opencode on the right: key: ctrl+m
Image

OpenCode version

1.0.159

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

macOS 15.5

Terminal

VS Code terminal

jdanbrown avatar Dec 15 '25 22:12 jdanbrown

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

  • #5584: LLM Output cut off / stops midway in UI but appears fine in transcript - Relates to content not displaying correctly in the UI while appearing fine in logs/transcripts
  • #5561: TextNodeRenderable only accepts strings, TextNodeRenderable instances, or StyledText instances - Related rendering error in opentui that causes crashes when displaying certain content
  • #5206: [object Object] error output when running opencode over SSH - Related output rendering issues with escape sequences and garbled text
  • #5288: Application crashes when LLM outputs Zalgo text - Related to issues with special characters and content causing rendering problems

The core issue appears to be related to how model output content is being rendered/escaped in the TUI display layer. Feel free to ignore if none of these address your specific case.

github-actions[bot] avatar Dec 15 '25 22:12 github-actions[bot]

Looks like the [ and ] chars are getting stripped too, but interestingly only in some parts of the output but not others:

Image

jdanbrown avatar Dec 15 '25 23:12 jdanbrown

The square brackets not being rendered is due to markdown? Try toggling the code conceal options (defaults to leader h)

justfortheloveof avatar Dec 15 '25 23:12 justfortheloveof

@jdanbrown Try opening the command_list and selecting 'Toggle code concealment`, that'll usually unhide the quotation marks in e.g, JSON output.

ariane-emory avatar Dec 15 '25 23:12 ariane-emory

Oh yep, Toggle code concealment does reveal the missing chars.

Please tell me this is a bug? As a user, I definitely don't want stuff like quotes to be hidden in json provided to me by a model (e.g. it breaks copy/paste, because I asked the model for json, not yaml). It makes sense to me to conceal special characters for markdown formatting, but not for ~anything else, right?

Default: Image

Toggle code concealment → off: Image

Default: Image

Toggle code concealment → off: Image

jdanbrown avatar Dec 15 '25 23:12 jdanbrown

The quotes one is definitely a bug I think? it's missing a parser for .json or something

rekram1-node avatar Dec 15 '25 23:12 rekram1-node

And I assume the [ ] one is a bug too?

[edit] Oh or is that a confusion with [foo](bar) markdown syntax for hyperlinks? Is [foo] without a trailing (bar) valid markdown syntax on its own and opencode is parsing it incorrectly, or is the model emitting invalid markdown because it should escape those brackets when it isn't trying to show a [foo](bar) link?

jdanbrown avatar Dec 15 '25 23:12 jdanbrown

The [ ] is a bug in the markdown parsing, it thinks its a link apparently. We just use the official tree-sitter markdown parser here. As for the quotes in inline json: the parser works as expected. Currently conceal is boolean, so either all concealed or nothing concealed. It does not distinguish between outer and inner/injected blocks.

kommander avatar Dec 16 '25 11:12 kommander