claude: Claude Code in WSL runs interactively when Windows can't read its transcripts

With the interactive mode on, Claude Code in WSL was refused with a 502
in two cases: the distro user's own folder unreadable from Windows
(\\wsl$ needs the 9P redirector, which a session over ssh hasn't;
"wslread") and a distro whose home the probe didn't find ("wsl-home").
Both now run interactively: the helper reads the transcript inside the
distro.

- claudetui/wslread.go: before Claude Code starts, a shell run through
  wsl.exe notes how much of $HOME/.claude/projects/*/<sid>.jsonl is
  there (a resumed session's earlier turns), says "ready", then tail -F's
  the rest; the helper copies it to a file of its own and tails that as
  any transcript. When Claude Code ends it waits for the copy to stop
  growing (settle), then closes the shell's stdin, which ends it.
- claudetui.WSL gets Distro (Projects omitempty); the gateway's tuiWSL
  sets it when Windows can't read the folder or the home is unknown.
- the wslread and wsl-home refusals are gone (claudeTUI, claudeWhy,
  claudeNotTUIWhy); the GUI's "wsl-home" reason and its 4 strings too.
- docs/subsystems/claude-subscription-bridge.md says how it is read.

Run, at origin/main ff65ebd14 plus this change (the reader through real
wsl.exe and the break-by-hand at 546cdbde6):
- WSL (magpie-desktop, go1.26.8): go vet -tags nogui, GOOS=windows vet,
  GOOS=darwin CGO_ENABLED=0 vet of claudetui ok; go test ./internal/claudetui
  ok; go test -run 'Claude|WSL' ./internal/gateway ok (51s);
  claude-mode.test.cjs chromium + webkit 44/44; i18n-keys 4/4.
- Windows 11 (xiaomi-gpu): go vet ok; go test ./internal/claudetui ok
  but TestShimFirstMessageWaitsForTools, red the same at main 2739626c3
  (bee3ea675's test, #4810);
  go test -run 'Claude|WSL' ./internal/gateway ok with
  TestClaudeAsRootEnv skipped: it is red the same at main 546cdbde6 on
  Windows (#2425, a root test where magpie is never root), at 546cdbde6.
- the reader through the real wsl.exe into magpie-desktop (a temporary
  test, not committed): ready in 93ms, the line already in the file left
  out, two lines written after copied, stopped in 9ms, no tail left in
  the distro.

Broken by hand: tuiWSL not setting Distro: TestClaudeTUIWSL red ("its
own folder, unread": Distro empty).

Not tried: a real Claude Code turn in WSL over ssh (real runs stay on
this Mac); mote (its disk is full); the full go test ./... .
This commit is contained in:
yetone
2026-11-02 00:12:40 +08:00
parent 2739626c38
commit 14e3513780
11 changed files with 378 additions and 102 deletions
+13 -7
View File
@@ -148,10 +148,18 @@ talks to it as it talks to `-p`: stream-json in and out. The helper:
added to `WSLENV`, and an image's path is pasted as the distro reads
it (`/mnt/c/…`, `shim.path`). The helper itself is the Windows
magpie.exe, not the `/mnt/c/…` path the MCP helper is started at.
In the distro user's own folder the run is `-p` when Windows can't
stat `\\wsl$\<distro>\<home>` (`tuiWSLUnread`), since the helper
would wait for a transcript it can't see: a session with no 9P
redirector, as one over ssh, reads nothing there.
In the distro user's own folder, when Windows can't stat
`\\wsl$\<distro>\<home>` (`tuiWSLUnread`: a session with no 9P
redirector, as one over ssh, reads nothing there) or the probe found
no home, the transcript is read inside the distro (`WSL.Distro`, no
`Projects`; `wslread.go`): before Claude Code starts, a shell run
through `wsl.exe` notes how much of `$HOME/.claude/projects/*/<sid>.jsonl`
is there (a resumed session's earlier turns), says `ready`, then
`tail -F`s the rest, and the helper copies it to a file of its own
that it tails as it tails any transcript. Once Claude Code ends the
helper waits for the copy to stop growing (`settle`), then closes the
shell's stdin, which ends it. Until 11-01 both cases were refused
(`wslread`, `wsl-home`).
Killing the gateway ended the distro's Claude Code with wsl.exe (tried
on Windows 11 26200, magpie-desktop, Claude Code 2.1.289);
- pastes each user message into the prompt (bracketed paste) and presses
@@ -278,8 +286,6 @@ Replies…\",\"type\":\"invalid_request_error" read as a model not served
(`provider.ModelUnserved`), which made the 400 retryable again. That is
when (`claudeTUI`, `claudePrint`):
- it is Claude Code in WSL whose home the probe didn't find, or, in
the distro user's own folder, one Windows can't read (`wslread`);
- the request has a JSON schema;
A first message of any length is pasted: a conversation told whole to
@@ -330,7 +336,7 @@ reads `GET /api/claude/mode` (`gateway.ClaudeModeNow`) as the page
opens, kept 30 seconds and dropped when the setting changes, not in
`/api/providers`' polls. What decides it for every run on the machine is
`claudeMachineWhy`, whose codes the page words: `off` (the setting),
`wsl-home`, `missing` (no Claude Code found), `os` and `no-shim`. Beside
`missing` (no Claude Code found), `os` and `no-shim`. Beside
the switch: turned off, that every request runs as claude -p; on where
the interactive mode can't run, that Claude requests fail, and why;
otherwise the last request, when it was the interactive mode's. A
+6 -2
View File
@@ -26,8 +26,12 @@ type WSL struct {
// Mount is where the distro mounts Windows' drives ("/mnt/"): an
// image's path is pasted as Claude Code there reads it
Mount string `json:"mount"`
// Projects is Claude Code's projects folder, as Windows reads it
Projects string `json:"projects"`
// Projects is Claude Code's projects folder, as Windows reads it; ""
// with Distro set when Windows can't, or its home is unknown: the
// transcript is then read inside the distro (wslread.go)
Projects string `json:"projects,omitempty"`
// Distro is the distro, as wsl.exe -d names it
Distro string `json:"distro,omitempty"`
}
// MCPCommand is the hidden subcommand of magpie's tool server, the MCP
+18 -4
View File
@@ -92,8 +92,10 @@ type shim struct {
nimages int
// wsl is a Claude Code in a WSL distro (WSLEnv); nil for this
// machine's
wsl *WSL
// machine's. wslr reads its transcript inside the distro, when
// Windows can't (wslread.go)
wsl *WSL
wslr *wslRead
// tap copies the replies' streams (tap.go), nil with none; env is
// what Claude Code is given for it
@@ -119,7 +121,7 @@ func Run(args []string) error {
var wsl *WSL
if v := os.Getenv(WSLEnv); v != "" {
wsl = &WSL{}
if err := json.Unmarshal([]byte(v), wsl); err != nil || len(wsl.Args) == 0 || wsl.Projects == "" {
if err := json.Unmarshal([]byte(v), wsl); err != nil || len(wsl.Args) == 0 || wsl.Projects == "" && wsl.Distro == "" {
return fmt.Errorf("%s: %q", WSLEnv, v)
}
// wsl.exe's own arguments, then Claude Code's
@@ -144,8 +146,19 @@ func Run(args []string) error {
args = append(args, "--session-id", s.sid)
}
s.projects = filepath.Join(configDir(), "projects")
if wsl != nil {
if wsl != nil && wsl.Projects != "" {
s.projects = wsl.Projects
} else if wsl != nil {
dir, err := os.MkdirTemp("", "magpie-claude-wsl-")
if err != nil {
return fail(err.Error())
}
defer os.RemoveAll(dir)
if s.wslr, err = startWSLRead(wsl.Distro, s.sid, dir); err != nil {
return fail(err.Error())
}
defer s.wslr.stop()
s.projects = dir
}
// a resumed session's file has its earlier turns: only what is
// written after the start is read
@@ -858,6 +871,7 @@ func (s *shim) tail(from int64) {
select {
case <-s.exited:
// what it wrote last
s.wslr.settle()
if line, _ := rd.ReadBytes('\n'); len(line) > 0 {
t.row(append(part, line...))
}
+146
View File
@@ -0,0 +1,146 @@
package claudetui
import (
"bufio"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"time"
"github.com/yetone/magpie/internal/proc"
)
// A Claude Code in WSL whose transcripts Windows can't read (the distro
// user's own folder, through \\wsl$, which a session with no 9P
// redirector, one over ssh, has none of), or whose home the probe didn't
// find, has its transcript read inside the distro: a shell there, run
// through wsl.exe, waits for the session's file and tails it, and the
// helper copies what it prints to a file of its own, which it reads as
// it reads any transcript. The shell finds the folder as Claude Code
// does, under its own $HOME.
// wslReadScript is the shell's script: $1 is the session id. It prints
// "ready" once it knows how much of the file is there before Claude Code
// starts (a resumed session's earlier turns), then whatever is written
// after, until its standard input ends.
const wslReadScript = `d="$HOME/.claude/projects"; s="$1"; n=0
for f in "$d"/*/"$s".jsonl; do [ -f "$f" ] && n=$(wc -c <"$f"); done
echo ready
( while :; do for f in "$d"/*/"$s".jsonl; do [ -f "$f" ] && exec tail -c +$((n+1)) -F "$f" 2>/dev/null; done; sleep 0.1; done ) &
cat >/dev/null; kill $! 2>/dev/null`
// wslReadCommand is the shell's command; a var for tests, which run the
// script here.
var wslReadCommand = func(distro, sid string) *exec.Cmd {
return proc.Command("wsl.exe", "-d", distro, "--exec", "/bin/sh", "-c", wslReadScript, "sh", sid)
}
// how long the shell has to say it is ready
var wslReadWait = 30 * time.Second
var sidRe = regexp.MustCompile(`^[0-9A-Za-z-]+$`)
// wslRead is a transcript read inside the distro, copied to path.
type wslRead struct {
path string
cmd *exec.Cmd
in io.WriteCloser
done chan struct{}
}
// startWSLRead starts reading session sid's transcript inside distro,
// before Claude Code starts, into a file under folder projects as a
// projects folder has it (<projects>/<folder>/<sid>.jsonl).
func startWSLRead(distro, sid, projects string) (*wslRead, error) {
if !sidRe.MatchString(sid) {
return nil, fmt.Errorf("a session id %q", sid)
}
if err := os.MkdirAll(filepath.Join(projects, "wsl"), 0o700); err != nil {
return nil, err
}
f, err := os.Create(filepath.Join(projects, "wsl", sid+".jsonl"))
if err != nil {
return nil, err
}
cmd := wslReadCommand(distro, sid)
in, err := cmd.StdinPipe()
if err != nil {
f.Close()
return nil, err
}
out, err := cmd.StdoutPipe()
if err != nil {
f.Close()
return nil, err
}
if err := cmd.Start(); err != nil {
f.Close()
return nil, err
}
r := &wslRead{path: f.Name(), cmd: cmd, in: in, done: make(chan struct{})}
rd := bufio.NewReader(out)
ready := make(chan error, 1)
go func() {
line, err := rd.ReadString('\n')
if err == nil && strings.TrimSpace(line) != "ready" {
err = fmt.Errorf("it said %q", line)
}
ready <- err
if err == nil {
_, _ = io.Copy(f, rd)
}
f.Close()
close(r.done)
}()
select {
case err = <-ready:
case <-time.After(wslReadWait):
err = errors.New("it didn't start")
}
if err != nil {
r.stop()
return nil, fmt.Errorf("the transcript can't be read in WSL: %v", err)
}
return r, nil
}
// settle waits, once Claude Code has ended, for the last of what it
// wrote: until the copy hasn't grown for a moment.
func (r *wslRead) settle() {
if r == nil {
return
}
var size int64 = -1
for until := time.Now().Add(3 * time.Second); time.Now().Before(until); {
fi, err := os.Stat(r.path)
if err != nil || fi.Size() == size {
return
}
size = fi.Size()
select {
case <-r.done:
return
case <-time.After(300 * time.Millisecond):
}
}
}
// stop ends the shell: its standard input ends, and it ends its tail.
func (r *wslRead) stop() {
if r == nil {
return
}
_ = r.in.Close()
select {
case <-r.done:
case <-time.After(5 * time.Second):
_ = r.cmd.Process.Kill()
<-r.done
}
_ = r.cmd.Wait()
}
+125
View File
@@ -0,0 +1,125 @@
package claudetui
import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
)
// wslHere runs the in-distro reader's script with this machine's sh, its
// $HOME the test's.
func wslHere(t *testing.T) string {
t.Helper()
if runtime.GOOS == "windows" {
t.Skip("the script is the distro's sh's")
}
home := t.TempDir()
old := wslReadCommand
wslReadCommand = func(distro, sid string) *exec.Cmd {
if distro != "Ubuntu" {
t.Errorf("distro %q", distro)
}
cmd := exec.Command("/bin/sh", "-c", wslReadScript, "sh", sid)
cmd.Env = append(os.Environ(), "HOME="+home)
return cmd
}
t.Cleanup(func() { wslReadCommand = old })
return filepath.Join(home, ".claude", "projects", "-work")
}
// waitFor waits until file path holds want.
func waitFor(t *testing.T, path, want string) {
t.Helper()
var got []byte
for until := time.Now().Add(10 * time.Second); time.Now().Before(until); time.Sleep(20 * time.Millisecond) {
if got, _ = os.ReadFile(path); string(got) == want {
return
}
}
t.Fatalf("%s holds %q, want %q", path, got, want)
}
func appendTo(t *testing.T, path, s string) {
t.Helper()
f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o600)
if err != nil {
t.Fatal(err)
}
defer f.Close()
if _, err := f.WriteString(s); err != nil {
t.Fatal(err)
}
}
// A transcript Windows can't read is read inside the distro: a resumed
// session's earlier turns are left out, what is written after is copied
// as it is written, and the shell ends with the run.
func TestWSLReadResumed(t *testing.T) {
dir := wslHere(t)
if err := os.MkdirAll(dir, 0o700); err != nil {
t.Fatal(err)
}
sid := "0f3c-1"
file := filepath.Join(dir, sid+".jsonl")
appendTo(t, file, `{"earlier":1}`+"\n")
r, err := startWSLRead("Ubuntu", sid, t.TempDir())
if err != nil {
t.Fatal(err)
}
if want := filepath.Join(filepath.Dir(filepath.Dir(r.path)), "wsl", sid+".jsonl"); r.path != want {
t.Fatalf("copied to %s, not as a projects folder has it", r.path)
}
appendTo(t, file, `{"later":1}`+"\n")
waitFor(t, r.path, `{"later":1}`+"\n")
appendTo(t, file, `{"later":2}`+"\n")
waitFor(t, r.path, `{"later":1}`+"\n"+`{"later":2}`+"\n")
done := make(chan struct{})
go func() { r.stop(); close(done) }()
select {
case <-done:
case <-time.After(10 * time.Second):
t.Fatal("the shell didn't end with the run")
}
if r.cmd.ProcessState == nil || !r.cmd.ProcessState.Exited() {
t.Fatalf("the shell: %v", r.cmd.ProcessState)
}
}
// A new session's file, written after Claude Code starts, is read whole.
func TestWSLReadNewSession(t *testing.T) {
dir := wslHere(t)
r, err := startWSLRead("Ubuntu", "abc", t.TempDir())
if err != nil {
t.Fatal(err)
}
t.Cleanup(r.stop)
if err := os.MkdirAll(dir, 0o700); err != nil {
t.Fatal(err)
}
appendTo(t, filepath.Join(dir, "abc.jsonl"), "one\ntwo\n")
waitFor(t, r.path, "one\ntwo\n")
}
// A session id is the bridge's, but never reaches the shell as anything
// but a word; a shell that never says it is ready fails the run.
func TestWSLReadRefuses(t *testing.T) {
wslHere(t)
if _, err := startWSLRead("Ubuntu", "x; rm -rf ~", t.TempDir()); err == nil {
t.Fatal("an id with a shell's words in it")
}
old, oldWait := wslReadCommand, wslReadWait
wslReadWait = 200 * time.Millisecond
wslReadCommand = func(string, string) *exec.Cmd { return exec.Command("/bin/sh", "-c", "echo nope; cat >/dev/null") }
t.Cleanup(func() { wslReadCommand, wslReadWait = old, oldWait })
if _, err := startWSLRead("Ubuntu", "abc", t.TempDir()); err == nil || !strings.Contains(err.Error(), "can't be read in WSL") {
t.Fatalf("a shell that said nope: %v", err)
}
wslReadCommand = func(string, string) *exec.Cmd { return exec.Command("/bin/sh", "-c", "cat >/dev/null") }
if _, err := startWSLRead("Ubuntu", "abc", t.TempDir()); err == nil || !strings.Contains(err.Error(), "didn't start") {
t.Fatalf("a shell that said nothing: %v", err)
}
}
+19 -30
View File
@@ -714,31 +714,32 @@ func (c claudeCLI) file(path string) string {
// transcripts read from Windows, through \\wsl$ for the distro's own
// folder.
func (c claudeCLI) tuiWSL(configDir string) string {
projects := filepath.Join(configDir, "projects")
w := claudetui.WSL{Args: c.wsl.Args(), Mount: c.wsl.Mount, Projects: filepath.Join(configDir, "projects")}
if configDir == "" {
projects = c.wsl.Windows(path.Join(c.wsl.Home, ".claude", "projects"))
w.Projects = c.wsl.Windows(path.Join(c.wsl.Home, ".claude", "projects"))
if c.tuiWSLUnread() {
// the helper reads the transcript inside the distro
w.Projects, w.Distro = "", c.wsl.Distro
}
}
b, _ := json.Marshal(claudetui.WSL{Args: c.wsl.Args(), Mount: c.wsl.Mount, Projects: projects})
b, _ := json.Marshal(w)
return string(b)
}
// wslStat is os.Stat; a var for tests.
var wslStat = os.Stat
// tuiWSLUnread is the folder of this Claude Code in WSL that Windows can't
// read, where its transcripts are in config directory configDir: the
// distro user's home through \\wsl$ for its own folder, which a session
// with no 9P redirector (one over ssh) has none of. "" when it is read,
// or is the account's, a Windows folder.
func (c claudeCLI) tuiWSLUnread(configDir string) string {
if configDir != "" {
return ""
// tuiWSLUnread is whether Windows can't read the transcripts of this
// Claude Code in WSL in its own folder: the probe didn't find the distro
// user's home, or Windows can't read it through \\wsl$, which a session
// with no 9P redirector (one over ssh) has none of. An account's folder
// is a Windows one.
func (c claudeCLI) tuiWSLUnread() bool {
if c.wsl.Home == "" {
return true
}
home := c.wsl.Windows(c.wsl.Home)
if _, err := wslStat(home); err != nil {
return home
}
return ""
_, err := wslStat(c.wsl.Windows(c.wsl.Home))
return err != nil
}
// exe is magpie's own executable, as this Claude Code starts it.
@@ -998,15 +999,9 @@ func (b *subscriptionBridge) startRun(ctx context.Context, req *Request, model,
// runs them interactively. A run it can't take is refused, never made
// -p: a refused request never ran, and isn't the last run
tui, code := claudeTUI(req, binary)
if tui && binary.wsl != nil {
// the helper would wait for a transcript it can't see
if dir := binary.tuiWSLUnread(configDir); dir != "" {
tui, code = false, "wslread"
}
}
if !tui && code != "off" && code != "no-shim" {
cleanup()
return nil, nil, &tuiRefusal{claudeTUIErr(claudeNotTUIWhy(req, binary, configDir))}
return nil, nil, &tuiRefusal{claudeTUIErr(claudeNotTUIWhy(req, binary))}
}
noteClaudeRun(code)
var cmd *exec.Cmd
@@ -1262,7 +1257,6 @@ func claudeMachineWhy(binary claudeCLI) (code, why string) {
}{
{!claudeTUIRuns, "no-shim", "no shim"},
{runtime.GOOS != "darwin" && runtime.GOOS != "linux" && runtime.GOOS != "windows", "os", runtime.GOOS},
{binary.wsl != nil && binary.wsl.Home == "", "wsl-home", "Claude Code in WSL, its home unknown"},
{binary.wsl == nil && binary.path == "", "missing", "no Claude Code path"},
{settings.Load().ClaudePrintMode, "off", "the interactive mode is turned off"},
} {
@@ -1415,15 +1409,10 @@ func claudeTUIOn() bool {
}
// claudeNotTUIWhy is why a run isn't the interactive mode.
func claudeNotTUIWhy(req *Request, binary claudeCLI, configDir string) string {
func claudeNotTUIWhy(req *Request, binary claudeCLI) string {
if why := claudePrintWhy(req, binary); why != "" {
return why
}
if binary.wsl != nil {
if dir := binary.tuiWSLUnread(configDir); dir != "" {
return "Windows can't read " + dir + ", where Claude Code in WSL writes its transcripts"
}
}
return "the interactive mode can't run here"
}
+42 -39
View File
@@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"runtime"
"slices"
"strings"
"testing"
@@ -39,7 +40,7 @@ func TestClaudeTUIChosen(t *testing.T) {
{"a plain turn", &Request{Messages: text("hi")}, here, false, on, ""},
{"turned off", &Request{Messages: text("hi")}, here, true, false, "the interactive mode is turned off"},
{"in WSL", &Request{Messages: text("hi")}, claudeCLI{path: "claude", wsl: &wslrun.Tool{Distro: "Ubuntu", Home: "/home/me"}}, false, on, ""},
{"in WSL, its home unknown", &Request{Messages: text("hi")}, claudeCLI{path: "claude", wsl: &wslrun.Tool{Distro: "Ubuntu"}}, false, false, "Claude Code in WSL, its home unknown"},
{"in WSL, its home unknown", &Request{Messages: text("hi")}, claudeCLI{path: "claude", wsl: &wslrun.Tool{Distro: "Ubuntu"}}, false, on, ""},
{"safeguards", &Request{Messages: text("hi"), Safeguards: json.RawMessage(`{"a":1}`)}, here, false, on, ""},
{"client cache marks", &Request{Messages: text("hi"), clientCache: &clientCache{}}, here, false, on, ""},
{"a schema", &Request{Messages: text("hi"), Format: &Format{Type: "json_schema", Schema: json.RawMessage(`{"type":"object"}`)}}, here, false, false, "a JSON schema"},
@@ -84,33 +85,14 @@ func TestClaudeTUIFallbackLogged(t *testing.T) {
// A Claude Code in WSL is run by the helper through wsl.exe, its
// transcripts read from Windows: the distro's own folder through \\wsl$,
// or the account's config directory, a Windows folder.
// or the account's config directory, a Windows folder. Where Windows
// can't read the distro's folder (no 9P redirector, as over ssh), or the
// probe didn't find its home, the helper reads the transcript inside the
// distro, never refusing the run; an account's folder is never asked
// about.
func TestClaudeTUIWSL(t *testing.T) {
c := claudeCLI{path: "claude", wsl: &wslrun.Tool{Distro: "Ubuntu", Path: "/home/me/.local/bin/claude", Home: "/home/me", Mount: "/mnt/"}}
for _, tc := range []struct{ configDir, projects string }{
{"", `\\wsl$\Ubuntu\home\me\.claude\projects`},
{filepath.Join("acct", "1"), filepath.Join("acct", "1", "projects")},
} {
var w claudetui.WSL
if err := json.Unmarshal([]byte(c.tuiWSL(tc.configDir)), &w); err != nil {
t.Fatal(err)
}
if w.Projects != tc.projects || w.Mount != "/mnt/" {
t.Fatalf("config %q: %+v", tc.configDir, w)
}
if len(w.Args) < 2 || w.Args[0] != "-d" || w.Args[1] != "Ubuntu" || w.Args[len(w.Args)-1] != c.wsl.Path {
t.Fatalf("args %q", w.Args)
}
}
}
// The distro's own folder, read through \\wsl$, is a -p run's when
// Windows can't read it (no 9P redirector, as over ssh); an account's
// config directory is a Windows folder, never asked about.
func TestClaudeTUIWSLUnread(t *testing.T) {
c := claudeCLI{wsl: &wslrun.Tool{Distro: "Ubuntu", Home: "/home/me"}}
var asked []string
readable := false
readable := true
old := wslStat
wslStat = func(p string) (os.FileInfo, error) {
asked = append(asked, p)
@@ -120,21 +102,42 @@ func TestClaudeTUIWSLUnread(t *testing.T) {
return nil, os.ErrNotExist
}
t.Cleanup(func() { wslStat = old })
if got := c.tuiWSLUnread(""); got != `\\wsl$\Ubuntu\home\me` {
t.Fatalf("unread %q", got)
}
readable = true
if got := c.tuiWSLUnread(""); got != "" {
t.Fatalf("read, yet %q", got)
}
readable = false
if got := c.tuiWSLUnread("acct"); got != "" || len(asked) != 2 {
t.Fatalf("the account's folder: %q, asked %q", got, asked)
tool := wslrun.Tool{Distro: "Ubuntu", Path: "/home/me/.local/bin/claude", Home: "/home/me", Mount: "/mnt/"}
homeless := tool
homeless.Home = ""
for _, tc := range []struct {
name string
tool wslrun.Tool
readable bool
configDir string
projects, distro string
asked []string
}{
{"its own folder", tool, true, "", `\\wsl$\Ubuntu\home\me\.claude\projects`, "", []string{`\\wsl$\Ubuntu\home\me`}},
{"an account's", tool, false, filepath.Join("acct", "1"), filepath.Join("acct", "1", "projects"), "", nil},
{"its own folder, unread", tool, false, "", "", "Ubuntu", []string{`\\wsl$\Ubuntu\home\me`}},
{"its home unknown", homeless, true, "", "", "Ubuntu", nil},
} {
asked, readable = nil, tc.readable
c := claudeCLI{path: "claude", wsl: &tc.tool}
var w claudetui.WSL
if err := json.Unmarshal([]byte(c.tuiWSL(tc.configDir)), &w); err != nil {
t.Fatal(err)
}
if w.Projects != tc.projects || w.Distro != tc.distro || w.Mount != "/mnt/" || !slices.Equal(asked, tc.asked) {
t.Fatalf("%s: %+v, asked %q", tc.name, w, asked)
}
if len(w.Args) < 2 || w.Args[0] != "-d" || w.Args[1] != "Ubuntu" || w.Args[len(w.Args)-1] != tool.Path {
t.Fatalf("%s: args %q", tc.name, w.Args)
}
if code, why := claudeMachineWhy(c); code == "wsl-home" {
t.Fatalf("%s: every run refused: %s", tc.name, why)
}
}
}
// The provider page's codes for why every run is -p: the setting, a
// WSL Claude Code whose home is unknown, none found; "" for the TUI.
// The provider page's codes for why every run is -p: the setting, none
// found; "" for the TUI, a WSL Claude Code whose home is unknown too.
func TestClaudeMachineWhy(t *testing.T) {
if runtime.GOOS != "darwin" && runtime.GOOS != "linux" && runtime.GOOS != "windows" {
t.Skip("no interactive mode on " + runtime.GOOS)
@@ -153,7 +156,7 @@ func TestClaudeMachineWhy(t *testing.T) {
{"here", here, false, ""},
{"in WSL", claudeCLI{wsl: &wslrun.Tool{Distro: "Ubuntu", Home: "/home/me"}}, false, ""},
{"turned off", here, true, "off"},
{"in WSL, its home unknown", claudeCLI{wsl: &wslrun.Tool{Distro: "Ubuntu"}}, false, "wsl-home"},
{"in WSL, its home unknown", claudeCLI{wsl: &wslrun.Tool{Distro: "Ubuntu"}}, false, ""},
{"none", claudeCLI{}, false, "missing"},
} {
st := settings.Load()
-5
View File
@@ -86,11 +86,6 @@ func askClaudeTUI(ctx context.Context, binary claudeCLI, configDir, model string
if _, why := claudeMachineWhy(binary); why != "" {
return claudeTUIErr(why)
}
if binary.wsl != nil {
if dir := binary.tuiWSLUnread(configDir); dir != "" {
return claudeTUIErr("Windows can't read " + dir + ", where Claude Code in WSL writes its transcripts")
}
}
tmp, err := os.MkdirTemp("", "magpie-claude-")
if err != nil {
return err
-1
View File
@@ -12,7 +12,6 @@
const CC_WHY = {
off: "the interactive mode is off in Settings",
os: "this system can't run the interactive mode",
"wsl-home": "magpie couldn't find the home folder of Claude Code in WSL",
missing: "Claude Code isn't installed on this computer",
};
const ccWhy = (code) => t(CC_WHY[code] || CC_WHY.os);
-4
View File
@@ -350,7 +350,6 @@ const I18N = {
"Stop looping replies": "停止循环的回复",
"Short Claude system prompt": "精简 Claude 系统提示词",
"Claude Code's interactive mode": "Claude Code 交互模式",
"magpie couldn't find the home folder of Claude Code in WSL": "magpie 找不到 WSL 里 Claude Code 的主目录",
"Claude Code isn't installed on this computer": "这台电脑上没有安装 Claude Code",
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. On, no request ever runs as -p. Off runs every request as claude -p": "Claude 订阅像人一样以交互模式运行 Claude Code,套餐对每次请求的计量约为 -p 的一半。开启时,任何请求都不会走 -p。关闭则每个请求都以 claude -p 运行",
"Claude requests fail: {why}": "Claude 请求会报错:{why}",
@@ -4729,7 +4728,6 @@ const I18N = {
"Stop looping replies": "停止循環的回覆",
"Short Claude system prompt": "精簡 Claude 系統提示詞",
"Claude Code's interactive mode": "Claude Code 互動模式",
"magpie couldn't find the home folder of Claude Code in WSL": "magpie 找不到 WSL 中 Claude Code 的主目錄",
"Claude Code isn't installed on this computer": "這台電腦上沒有安裝 Claude Code",
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. On, no request ever runs as -p. Off runs every request as claude -p": "Claude 訂閱像人一樣以互動模式執行 Claude Code,方案對每次請求的計量約為 -p 的一半。開啟時,任何請求都不會走 -p。關閉則每個請求都以 claude -p 執行",
"Claude requests fail: {why}": "Claude 請求會報錯:{why}",
@@ -9077,7 +9075,6 @@ const I18N = {
"Stop looping replies": "ループする応答を止める",
"Short Claude system prompt": "Claude のシステムプロンプトを短く",
"Claude Code's interactive mode": "Claude Code の対話モード",
"magpie couldn't find the home folder of Claude Code in WSL": "magpie は WSL 内の Claude Code のホームフォルダを見つけられませんでした",
"Claude Code isn't installed on this computer": "このコンピュータには Claude Code がインストールされていません",
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. On, no request ever runs as -p. Off runs every request as claude -p": "Claude サブスクリプションは人と同じように Claude Code を対話モードで実行し、プランはリクエストを -p の約半分として数えます。オンのときは、どのリクエストも -p では実行しません。オフにするとすべてのリクエストを claude -p で実行します",
"Claude requests fail: {why}": "Claude へのリクエストはエラーになります:{why}",
@@ -13435,7 +13432,6 @@ const I18N = {
"Stop looping replies": "Schleifende Antworten beenden",
"Short Claude system prompt": "Kurzer Claude-Systemprompt",
"Claude Code's interactive mode": "Interaktiver Modus von Claude Code",
"magpie couldn't find the home folder of Claude Code in WSL": "magpie hat den Home-Ordner von Claude Code in WSL nicht gefunden",
"Claude Code isn't installed on this computer": "Claude Code ist auf diesem Computer nicht installiert",
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. On, no request ever runs as -p. Off runs every request as claude -p": "Ein Claude-Abo führt Claude Code wie ein Mensch im interaktiven Modus aus, wo der Plan eine Anfrage mit etwa der Hälfte von -p anrechnet. Ein: Keine Anfrage läuft je als -p. Aus führt jede Anfrage als claude -p aus",
"Claude requests fail: {why}": "Claude-Anfragen schlagen fehl: {why}",
+9 -10
View File
@@ -34,16 +34,16 @@ const codex = { id: "codex", name: "Codex", icon: "codex", models: [{ id: "gpt-6
const RUNS = {
tui: { tui: true, last: { tui: true, at: ago(3) } },
off: { tui: false, why: "off", last: { tui: false, why: "off", at: ago(3) } },
wsl: { tui: false, why: "wsl-home", wsl: true },
os: { tui: false, why: "os" },
};
// each language's words, as the i18n table has them
const W = {
en: { row: "Claude Code runs as", tui: "Interactive mode (TUI)", inUse: "In use", lastTui: "interactive mode", allP: "Every request runs as claude -p", wsl: "WSL" },
zh: { row: "Claude Code 运行方式", tui: "交互模式(TUI)", inUse: "使用中", lastTui: "交互模式", allP: "每个请求都以 claude -p 运行", wsl: "WSL" },
"zh-TW": { row: "Claude Code 執行方式", tui: "互動模式(TUI)", inUse: "使用中", lastTui: "互動模式", allP: "每個請求都以 claude -p 執行", wsl: "WSL" },
ja: { row: "Claude Code の実行方式", tui: "対話モード(TUI)", inUse: "使用中", lastTui: "対話モード", allP: "すべてのリクエストを claude -p で実行します", wsl: "WSL" },
de: { row: "Claude Code läuft als", tui: "Interaktiver Modus (TUI)", inUse: "In Verwendung", lastTui: "interaktiver Modus", allP: "Jede Anfrage läuft als claude -p", wsl: "WSL" },
en: { row: "Claude Code runs as", tui: "Interactive mode (TUI)", inUse: "In use", lastTui: "interactive mode", allP: "Every request runs as claude -p" },
zh: { row: "Claude Code 运行方式", tui: "交互模式(TUI)", inUse: "使用中", lastTui: "交互模式", allP: "每个请求都以 claude -p 运行" },
"zh-TW": { row: "Claude Code 執行方式", tui: "互動模式(TUI)", inUse: "使用中", lastTui: "互動模式", allP: "每個請求都以 claude -p 執行" },
ja: { row: "Claude Code の実行方式", tui: "対話モード(TUI)", inUse: "使用中", lastTui: "対話モード", allP: "すべてのリクエストを claude -p で実行します" },
de: { row: "Claude Code läuft als", tui: "Interaktiver Modus (TUI)", inUse: "In Verwendung", lastTui: "interaktiver Modus", allP: "Jede Anfrage läuft als claude -p" },
};
function serve(lang, run, switchOnly, reads) {
@@ -180,15 +180,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
test(`${engine} ${lang}: on where it can't run, Claude requests are said to fail, and why`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const { page, errors } = await openEditor(browser, lang, RUNS.wsl);
const { page, errors } = await openEditor(browser, lang, RUNS.os);
const row = runRow(page);
await row.waitFor();
const tr = (k, v) => page.evaluate(([k, v]) => t(k, v), [k, v]);
assert.equal(await row.locator(".cc-pick .opt").first().getAttribute("aria-pressed"), "true", "TUI is still the one chosen: never -p");
const said = (await row.locator(".cc-said.bad").textContent()).trim();
assert.equal(said, await tr("Claude requests fail: {why}", { why: await tr("magpie couldn't find the home folder of Claude Code in WSL") }));
assert.match(said, new RegExp(w.wsl));
if (lang !== "en") assert(!/Claude requests fail|couldn't find/.test(said), said);
assert.equal(said, await tr("Claude requests fail: {why}", { why: await tr("this system can't run the interactive mode") }));
if (lang !== "en") assert(!/Claude requests fail|can't run/.test(said), said);
assert.deepEqual(errors, []);
});
}