Skip to content

修正: tmux の中で URL がクリックできない (OSC 8 が外側の端末へ届かない) - #150

Merged
takemi-ohama merged 3 commits into
mainfrom
fix/tmux-osc8-hyperlinks
Sep 17, 2026
Merged

takemi-ohama merged 3 commits into
mainfrom
fix/tmux-osc8-hyperlinks

Conversation

@takemi-ohama

Copy link
Copy Markdown
Contributor

Pull Request

概要

tmux の中で Claude Code などが出す URL がクリックできなくなっていたのを直します。

tmux は端末が Hls 能力を持つときだけハイパーリンク (OSC 8) を書き出し、持たない端末では
リンクを捨てて文字列だけを描きます。tmux が xterm* へ既定で与える機能は
clipboard/ccolour/cstyle/focus/title の 5 つで hyperlinks を含みません。
そのため v3.1.0 で /etc/tmux.conf を焼き込んで以降、コンテナ内の作業が tmux 経由に
なった時点でリンクが落ちていました。

terminal-features へ ,xterm-256color:hyperlinks を追記します。

実測

疑似端末に tmux クライアントを繋ぎ、tmux が外側の端末へ実際に書いたバイト列を採取して
比較しました。外側は VS Code 統合ターミナル 1.135.0 (TERM=xterm-256color) です。

条件 クライアントの Hls 外側へ届いた OSC 8
修正前 [missing] 0 回
修正後 \033]8;%?%p1%l%tid=%p1%s%;;%p2%s\033\\ 2 回

利用者環境でも、~/.tmux.conf へ同じ 1 行を置いてクライアントを繋ぎ直した状態で、
表示文字と飛び先が異なるリンク (OSC 8 でしか成立しない) がすべて開けることを確認済みです。

関連 Issue

  • なし

変更点

  • containers/base/tmux.conf に set -ga terminal-features ",xterm-256color:hyperlinks" を追記
  • tests/containers/test_tmux_conf.py に検査を追加。tmux は綴りの違う機能名を黙って
    受け取る
    ため、show-options の文字列一致では守れない。pty.openpty でクライアントを
    接続し、show-messages -JT の Hls が定義されることを見る
  • docs/user/container-operations.md の既定設定表に 1 行追加
  • CHANGELOG.md の Unreleased に Fixed として記載

動作確認

  • uv run pytest tests/containers -q が 122 件通る
  • 追加した検査が修正前の設定で落ちる (Hls が定義されていない: 47: Hls: [missing])
  • 疑似端末での実測で、修正後に OSC 8 が外側の端末へ届く
  • 利用者環境で、繋ぎ直した後にリンクがすべて開ける
  • CI が green である

補足

反映にはイメージの再ビルドとコンテナの作り直しが要ります (devbase build base)。
動作中のコンテナで先に戻すには、~/.tmux.conf へ同じ 1 行を書いて
tmux source-file ~/.tmux.conf した後、クライアントを繋ぎ直してください。
端末の能力は接続時に決まるため、実行中のクライアントには反映されません。

tmux は端末が Hls 能力を持つときだけ OSC 8 を書き出し、持たない端末ではリンクを
捨てて文字列だけを描く。tmux が xterm* へ既定で与える機能は clipboard/ccolour/
cstyle/focus/title で hyperlinks を含まないため、/etc/tmux.conf を焼き込んで以降、
Claude Code などが出す URL がクリックできない見た目だけのリンクになっていた。

terminal-features へ ",xterm-256color:hyperlinks" を追記する。tmux は綴りの違う
機能名を黙って受け取るため、show-options の文字列ではなく pty でクライアントを
繋いで Hls が定義されることを検査する。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UtHB25awYxRd5kKJr6vc8b

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 1 | codex | APPROVE

修正が必要な指摘はありません。

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 1 | gemini | APPROVE

テスト例外時に tmux プロセスが残らないよう、確実なリソース解放について 1 点のみ軽微な提案を行っています。

Comment thread tests/containers/test_tmux_conf.py Outdated
_client_capabilities の finally で client.wait(timeout=5) が TimeoutExpired を
投げると、以降の kill-server まで到達せず `sleep 30` を抱えた tmux サーバーが
残る。kill-server を先に実行してクライアントを自発的に終わらせ、なお待ち切れ
なかった場合も TimeoutExpired を握り潰して後始末を続けるようにする。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GRDMb2WUxD8aenYmZfKzj
# Conflicts:
#	CHANGELOG.md
#	tests/containers/test_tmux_conf.py
@takemi-ohama
takemi-ohama merged commit 87f5978 into main Sep 17, 2026
5 checks passed
@takemi-ohama
takemi-ohama deleted the fix/tmux-osc8-hyperlinks branch September 17, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant