Skip to content

Commit 7daa21c

Browse files
committed
fix: tmux -u 强制 UTF-8 + wrap 命令注入 locale,解决中文渲染问题
- buildTmuxRemoteCmd: tmux 加 -u 标志,wrapCmd 前置 LANG/LC_ALL - RunSessionsAttach: tmux attach-session 同样加 -u - 更新 session_test.go 适配新的命令模板
1 parent 06b4f9a commit 7daa21c

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

internal/cloudclaude/session.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,21 @@ func buildClaudeCmd(claudeArgs []string, hasProxy bool, remoteCwd string) string
185185
// buildTmuxRemoteCmd 构造 D-10 完整远程命令模板。所有参数已 shellescape。
186186
//
187187
// cd <cwd_q> && command -v tmux >/dev/null 2>&1 \
188-
// && exec tmux new-session -A -d -s <session_q> <wrap_q> \; attach-session -t <session_q> \
188+
// && exec tmux -u new-session -A -d -s <session_q> <wrap_q> \; attach-session -t <session_q> \
189189
// || exec <fallback>
190190
//
191-
// wrapCmd = "cd <cwd_q> && <claudeCmd>"(整体 shellescape 一次后塞给 tmux new-session)。
191+
// wrapCmd = "export LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 && cd <cwd_q> && <claudeCmd>"
192+
// (整体 shellescape 一次后塞给 tmux new-session)。
192193
// fallback = wrapCmd 字面值(不经过 tmux 直接 exec)。
194+
//
195+
// -u 强制 tmux 输出 UTF-8;wrapCmd 注入 locale 确保 Claude Code 渲染中文正常。
193196
func buildTmuxRemoteCmd(remoteCwd, sessionName, claudeCmd string) string {
194197
cwdQ := shellescape.Quote(remoteCwd)
195198
sessionQ := shellescape.Quote(sessionName)
196-
wrapCmd := fmt.Sprintf("cd %s && %s", cwdQ, claudeCmd)
199+
wrapCmd := fmt.Sprintf("export LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 && cd %s && %s", cwdQ, claudeCmd)
197200
wrapQ := shellescape.Quote(wrapCmd)
198201
return fmt.Sprintf(
199-
"cd %s && command -v tmux >/dev/null 2>&1 && exec tmux new-session -A -d -s %s %s \\; attach-session -t %s || exec %s",
202+
"cd %s && command -v tmux >/dev/null 2>&1 && exec tmux -u new-session -A -d -s %s %s \\; attach-session -t %s || exec %s",
200203
cwdQ, sessionQ, wrapQ, sessionQ, wrapCmd,
201204
)
202205
}
@@ -898,6 +901,6 @@ func RunSessionsAttach(conn *ssh.Client, sessionName string, hasProxy bool, cwd
898901
fmt.Fprintln(os.Stderr, errcodes.Format(errcodes.SESSION_NOT_FOUND, sessionName))
899902
return ExitConfigError, fmt.Errorf("session not found: %s", sessionName)
900903
}
901-
remoteCmd := fmt.Sprintf("exec tmux attach-session -t %s", sessQ)
904+
remoteCmd := fmt.Sprintf("exec tmux -u attach-session -t %s", sessQ)
902905
return runClaudePTYBare(conn, remoteCmd)
903906
}

internal/cloudclaude/session_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ func TestBuildTmuxRemoteCmd_ContainsAllParts(t *testing.T) {
158158
mustContain := []string{
159159
"cd /workspace/proj",
160160
"command -v tmux >/dev/null 2>&1",
161-
"exec tmux new-session -A -d -s claude-abcdef12",
161+
"exec tmux -u new-session -A -d -s claude-abcdef12",
162162
"\\; attach-session -t claude-abcdef12",
163-
"|| exec cd /workspace/proj && claude --foo",
163+
"|| exec export LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 && cd /workspace/proj && claude --foo",
164164
}
165165
for _, s := range mustContain {
166166
if !strings.Contains(got, s) {

0 commit comments

Comments
 (0)