OSC8 hyperlink span incorrectly includes trailing ) from markdown image syntax
Description
When Claude Code renders tool output containing a markdown image reference, it emits an OSC8 hyperlink whose span includes the closing ) of the  syntax. This causes the ) to be part of the clickable URL in terminals that support OSC8, resulting in a broken link when ctrl+clicking.
Steps to reproduce
In a terminal with OSC8 support (e.g. Ghostty, Kitty, WezTerm), run a tool that produces markdown image output — for example the gh image extension:
gh image screenshot.png --repo owner/repo
Claude Code renders the output as:

Ctrl+hover over the URL — the clickable region includes the trailing ).
Expected
OSC8 span covers only the URL:
https://github.com/user-attachments/assets/4aa7c5c3-58ab-4d15-b6fa-e962c6d072e3
Actual
OSC8 span covers the URL plus the closing parenthesis:
https://github.com/user-attachments/assets/4aa7c5c3-58ab-4d15-b6fa-e962c6d072e3)
The status bar at the bottom of the terminal confirms the ) is inside the OSC8 span:
Root cause
The issue is confirmed to be in Claude Code's OSC8 emission, not in the terminal's regex-based URL detection. Verified by running the same string via plain echo in a separate terminal window — Ghostty's regex correctly strips the trailing ). The bug only manifests inside Claude Code's output, where OSC8 takes priority over the terminal's regex fallback.
OSC8 gives the emitting application full authority over the hyperlink span. When the span is wrong, the terminal has no mechanism to correct it — the fix belongs in the emitter.
Environment
- Claude Code 2.1.162
- Terminal: Ghostty 1.3.0 (Linux, GTK)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗