Skip to content

URLs in tree-sitter markdown rendering have no OSC 8 hyperlink support (links break at line wrap) #14966

@mugnimaestra

Description

@mugnimaestra

Bug Description

When using opencode's default markdown rendering path (<code filetype="markdown">), URLs in AI responses are never emitted as proper OSC 8 hyperlinks. The terminal relies on its own URL auto-detection, which breaks when a long URL wraps across multiple terminal lines — Cmd/Ctrl+Click opens only a truncated URL.

Root Cause

The default rendering pipeline uses tree-sitter to highlight markdown content:

  1. TextPart component renders <code filetype="markdown"> (see session/index.tsx)
  2. CodeRenderable uses tree-sitter → produces SimpleHighlight[] tuples
  3. treeSitterToTextChunks() converts highlights to TextChunk[], copying only visual styles (fg, bg, bold, italic, underline, dim) — never sets the link property
  4. Theme scopes (markup.link, markup.link.url, string.special.url) in theme.tsx only define foreground color + underline
  5. Without chunk.link, textBufferSetStyledText never calls linkAlloc(), no link_id is assigned, no OSC 8 sequences are emitted

In contrast, the experimental markdown renderer (OPENCODE_EXPERIMENTAL_MARKDOWN=true) correctly sets link: { url } on chunks, enabling proper OSC 8 hyperlinks.

Steps to Reproduce

  1. Run opencode in a terminal that supports OSC 8 (e.g., iTerm2, Windows Terminal, Ghostty)
  2. Ask the AI a question that produces a long URL in the response (e.g., a GitHub PR URL with comment anchor)
  3. Let the URL wrap across terminal lines
  4. Try to Cmd/Ctrl+Click the URL
  5. Expected: Browser opens the full URL
  6. Actual: Browser opens a truncated URL (only the portion on the clicked line)

Video Demonstration

opencode-issues.mov

Fix

The fix is in opentui (the rendering framework), not in opencode itself. A PR has been submitted to opentui that modifies treeSitterToTextChunks() to detect URL-bearing tree-sitter scopes (markup.link.url, string.special.url) and set the link property on those chunks, as well as on associated markup.link.label chunks.

Related opentui issues/PRs:

Environment

  • opencode version: latest dev build
  • Terminal: iTerm2, Ghostty (any OSC 8-capable terminal)
  • OS: macOS (also affects Linux terminals with OSC 8 support)

Metadata

Metadata

Assignees

Labels

opentuiThis relates to changes in v1.0, now that opencode uses opentui

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions