Files
magpie/internal/cli/claude_desktop_launch_cli.go
T
yetone 6bc0d1e203 claude-desktop: Claude Magpie's Code tab on a Claude Code folder of its own (#6459)
The Separate app (Claude Magpie.app, #5671) kept its own Desktop
userData, but its Code tab's bundled Claude Code still read and wrote
the user's ~/.claude: their CLAUDE.md, skills, plugins and history went
into the twin, and the twin's sessions into theirs (xMopf7RF on X).

An opt-in, macOS-only switch under the Separate app's Advanced fold
(settings.DesktopIsolatedClaude, POST /api/settings/desktop-isolated-
claude, `magpie claude-desktop launcher claude-dir on|off`) gives it
~/.claude-magpie-desktop:

- desktopiso.Script exports CLAUDE_CONFIG_DIR in the app's launch
  script; turning the option on or off remakes the app, and the hint
  says to quit and reopen Claude Magpie, since a running one keeps its
  environment.
- desktopOn writes Desktop's model windows, caps and explore entries
  into that folder's settings.json instead of ~/.claude's while it is on
  (desktopCodeDir, desktopClaudeSync); off moves them back. The folder
  is kept when it is turned off, and shows as the claude# row "Claude
  Code · Claude Magpie".
- The fold is drawn by claudemagpie.js, imported the first time it
  shows; what stays in app.js is the import (isoLazy) and the fold's
  place, 216 bytes, so the core budget goes up by 180 (the 36 of room
  there was taken first).

Run:
- gofmt -l clean; go vet ./internal/... on darwin, GOOS=windows and
  GOOS=linux -tags nogui vet of agent, cli, desktopiso, gui, settings,
  settingsapi (mote).
- go test agent, cli, desktopiso, desktopdir, settings, settingsapi,
  gui, library on mote: all ok except cli's three healthcheck/update
  tests, which ask the gateway mote's own magpie serves on :3425
  (#6223, the same with or without this change).
- TestCoreScriptBudget and TestSettingsSaveKeepsWhatItDoesNotSend at
  this commit and the next.
- GUI on mote, Chromium and WebKit: desktop-isolated-claude (five
  languages, 1100 and 640px), desktop-isolated, i18n-keys,
  i18n-en-no-cjk, old-webkit, and every agent*/desktop*/claude* file
  (98 files, 1,595 of 1,662 pass). Every red is the same on origin/main
  92bce5c72 run alone: old-webkit (#6467, #5919), agent-details-ready
  (#6373), agent-switch-accounts (#5925), claude-quota-onboarding
  (#6179), agent-menu-label (#6371), desktop-tiers Chromium (#6475).
- A real Claude Desktop on mote in a sandbox HOME (~/sb6459, removed
  after): `claude-desktop magpie`, `launcher add`, `launcher claude-dir
  on`. The window and caps moved into .claude-magpie-desktop/
  settings.json, ~/.claude kept only its theme, the script exported
  CLAUDE_CONFIG_DIR, and the launched Desktop's main process and
  children had it in their environment. `claude-dir off` moved them
  back and dropped the export; `launcher remove` removed the app.
  mote's real ~/.claude was listed before and after: unchanged.

Broken by hand:
- desktopOn without the clone-folder branch: TestClaudeDesktopIsolated
  ClaudeDir red (the window stays in ~/.claude).
- The fold without its ontoggle: desktop-isolated-claude red ("shut by
  the redraw").
- settingsapi not keeping the field: TestSettingsSaveKeepsWhatItDoes
  NotSend red.

Not tried: a Code-tab session driven in the real Desktop's UI, so
bundled Claude Code writing into the folder was not seen in this run
(an earlier look at #6459 saw it). Library has no targets for the
clone's folder yet (#6469). The whole GUI suite (1,484 files) was not
run; the files on the Agents page and every i18n file were.
2026-11-13 16:02:12 +08:00

133 lines
4.2 KiB
Go

package cli
import (
"errors"
"fmt"
"os"
"slices"
"github.com/yetone/magpie/internal/agent"
)
// `magpie claude-desktop launcher [add|remove]` is the isolated Claude
// Desktop (#5671, baranwang on X), as `magpie claude launcher` is
// claude-magpie: add makes ~/Applications/Claude Magpie.app, which starts
// Claude Desktop on magpie in a folder of its own, and moves a Desktop on
// magpie there, so the user's own Claude.app stays signed in with
// Anthropic; remove puts it back. The GUI's switch on Claude Desktop's
// row does the same (agent.SetDesktopIsolated). macOS only.
const claudeDesktopLauncherUsage = `magpie claude-desktop launcher [add|remove]
Claude Magpie.app (macOS): Claude Desktop on magpie in a folder of
its own, beside your own Claude Desktop signed in with Anthropic
magpie claude-desktop launcher claude-dir [on|off]
its Code tab's Claude Code on a folder of its own
(CLAUDE_CONFIG_DIR=~/.claude-magpie-desktop), or on ~/.claude
`
// claudeDesktopLaunchCmd is `magpie claude-desktop launcher …`; ok false
// for another form.
func claudeDesktopLaunchCmd(args []string) (ok bool, err error) {
if len(args) < 2 || args[0] != "claude-desktop" && args[0] != "claude-app" || args[1] != "launcher" {
return false, nil
}
rest := args[2:]
if len(rest) > 0 && slices.Contains([]string{"-h", "--help", "help"}, rest[0]) {
fmt.Print(claudeDesktopLauncherUsage)
return true, nil
}
return true, claudeDesktopLauncher(rest)
}
// setDesktopIsolated is agent.SetDesktopIsolated; tests set it.
var setDesktopIsolated = agent.SetDesktopIsolated
// desktopIsolatedHere is agent.DesktopIsolatedHere; tests set it.
var desktopIsolatedHere = agent.DesktopIsolatedHere
// setDesktopIsolatedClaude is agent.SetDesktopIsolatedClaude; tests set it.
var setDesktopIsolatedClaude = agent.SetDesktopIsolatedClaude
func claudeDesktopLauncher(args []string) error {
what := "status"
if len(args) > 0 {
what = args[0]
}
if what == "claude-dir" {
return claudeDesktopClaudeDir(args[1:])
}
if len(args) > 1 {
return fmt.Errorf("magpie claude-desktop launcher takes one word, not %q", args[1])
}
if what != "status" && what != "add" && what != "remove" {
return fmt.Errorf("magpie claude-desktop launcher: add, remove or nothing, not %q", what)
}
st, ok := desktopIsolatedHere()
if !ok {
return errors.New("Claude Desktop runs in a folder of its own on macOS only")
}
home, _ := os.UserHomeDir()
switch what {
case "add":
p, err := setDesktopIsolated(home, true)
if err != nil {
return err
}
fmt.Println("Claude Magpie:", p)
fmt.Println("Open it to use Claude Desktop on magpie; your own Claude Desktop stays signed in with Anthropic.")
return nil
case "remove":
was := st.Launcher
if _, err := setDesktopIsolated(home, false); err != nil {
return err
}
if was != "" {
fmt.Println("removed", was)
}
return nil
}
if st.On && st.Launcher != "" {
fmt.Println(st.Launcher)
return nil
}
fmt.Println("no Claude Magpie app: run `magpie claude-desktop launcher add`")
return nil
}
// claudeDesktopClaudeDir is `magpie claude-desktop launcher claude-dir
// [on|off]` (#6459): the Code tab of Claude Magpie.app's Desktop on a
// Claude Code folder of its own, or on ~/.claude; nothing says which.
func claudeDesktopClaudeDir(args []string) error {
if len(args) > 1 {
return fmt.Errorf("magpie claude-desktop launcher claude-dir takes one word, not %q", args[1])
}
st, ok := desktopIsolatedHere()
if !ok {
return errors.New("Claude Desktop runs in a folder of its own on macOS only")
}
if len(args) == 0 {
if st.Claude {
fmt.Println(st.ClaudeDir)
} else {
fmt.Println("~/.claude: run `magpie claude-desktop launcher claude-dir on` for a folder of its own")
}
return nil
}
if args[0] != "on" && args[0] != "off" {
return fmt.Errorf("magpie claude-desktop launcher claude-dir: on, off or nothing, not %q", args[0])
}
home, _ := os.UserHomeDir()
if err := setDesktopIsolatedClaude(home, args[0] == "on"); err != nil {
return err
}
if args[0] == "on" {
fmt.Println("Claude Code in Claude Magpie:", st.ClaudeDir)
} else {
fmt.Println("Claude Code in Claude Magpie: ~/.claude")
}
if st.Launcher != "" {
fmt.Println("Quit Claude Magpie and open it again to use it.")
}
return nil
}