-
Notifications
You must be signed in to change notification settings - Fork 14.5k
URLs in tree-sitter markdown rendering have no OSC 8 hyperlink support (links break at line wrap) #14966
Description
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:
TextPartcomponent renders<code filetype="markdown">(seesession/index.tsx)CodeRenderableuses tree-sitter → producesSimpleHighlight[]tuplestreeSitterToTextChunks()converts highlights toTextChunk[], copying only visual styles (fg,bg,bold,italic,underline,dim) — never sets thelinkproperty- Theme scopes (
markup.link,markup.link.url,string.special.url) intheme.tsxonly define foreground color + underline - Without
chunk.link,textBufferSetStyledTextnever callslinkAlloc(), 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
- Run opencode in a terminal that supports OSC 8 (e.g., iTerm2, Windows Terminal, Ghostty)
- Ask the AI a question that produces a long URL in the response (e.g., a GitHub PR URL with comment anchor)
- Let the URL wrap across terminal lines
- Try to Cmd/Ctrl+Click the URL
- Expected: Browser opens the full URL
- 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:
- Hyperlinks spanning wrapped lines are not grouped (missing 'id' parameter in OSC 8) opentui#735 — OSC 8 id parameter fix (experimental path)
- fix(renderer): add OSC 8 hyperlink id parameter and onChunks hook for link detection opentui#736 — PR for the id parameter fix
- anomalyco/opentui#(pending) — PR for tree-sitter link detection (this fix)
Environment
- opencode version: latest dev build
- Terminal: iTerm2, Ghostty (any OSC 8-capable terminal)
- OS: macOS (also affects Linux terminals with OSC 8 support)