Files
magpie/internal/wslrun
yetone c112d2a448 gateway: the Claude subscription answers when magpie runs as root (FrierenF)
Run as root (a server, a Docker container), every Claude subscription
request failed with "Claude Code: exited before it answered magpie's
initialize request (exit status 1): --dangerously-skip-permissions cannot
be used with root/sudo privileges for security reasons".

Claude Code 2.1.296's setup refuses bypassPermissions/
--dangerously-skip-permissions when process.getuid() === 0, IS_SANDBOX is
not "1" and CLAUDE_CODE_BUBBLEWRAP is unset (read from the installed
binary; --permission-mode bypassPermissions is refused the same way). The
bridge's run has no tool of Claude Code's own that touches the machine,
only magpie's MCP tools, answered by the client, and Anthropic's web
search, so the bridge run as root is now given IS_SANDBOX=1
(claudeCLI.asRoot). Its args are unchanged, and a run as anyone else has
its env exactly as before. A WSL distro whose default user is root is the
same case: the WSL probe now prints `id -u` (wslrun.Tool.Root), and
IS_SANDBOX goes into the distro (WSLENV) only then. The warm-up and /usage
runs don't pass the flag and are untouched.

Run:
- Docker node:22-bookworm-slim as root, @anthropic-ai/claude-code@2.1.296,
  fake API: the bridge's exact argv refuses with the message above without
  IS_SANDBOX, and with IS_SANDBOX=1 answers from the fake API
  (permissionMode bypassPermissions).
- The gateway's serveClaudeSubscription as root in that container (linux
  test binary, real claude, no credentials): before, 502 "Claude Code
  ended without an answer"; after, it gets past the check to Claude
  Code's own "Not logged in".
- TestClaudeRunsAsRoot (a fake that refuses as root does) goes red with
  asRoot removed from the launch; TestClaudeAsRootEnv; TestParseProbe.
- go test -tags nogui ./internal/gateway ./internal/wslrun ./internal/agent,
  gofmt -l, go vet (darwin, GOOS=linux, GOOS=windows). WSL root path is
  unit-tested only, not tried on the Windows box.
2026-10-10 19:39:19 +08:00
..