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.
102 lines
3.4 KiB
Go
102 lines
3.4 KiB
Go
package agent
|
|
|
|
// Claude Code kept in more than one config folder (CLAUDE_CONFIG_DIR, as in
|
|
// `alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'`): the one
|
|
// the variable (or ~/.claude) names is the claude row; every other folder
|
|
// beside it under the home folder that is named .claude… and holds a
|
|
// Claude Code's own files is a row of its own, claude#<name> (the way omp's
|
|
// profiles are omp#<name>), with its own settings.json to connect, a model
|
|
// to pick and Check. BieJian21872 on X: only the one at the default path
|
|
// was found.
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/appdir"
|
|
"github.com/yetone/magpie/internal/desktopiso"
|
|
"github.com/yetone/magpie/internal/dirent"
|
|
)
|
|
|
|
// claudeDirName is the part of a folder's name after ".claude" as a row's
|
|
// name: ".claude-work" is "work", ".claude2" is "2". "" for a name that is
|
|
// no extra Claude Code folder (the file ~/.claude.json and its backups, the
|
|
// folder .claude itself, the launch file's).
|
|
func claudeDirName(base string) string {
|
|
rest, ok := strings.CutPrefix(strings.ToLower(base), ".claude")
|
|
if !ok || rest == "" || strings.HasPrefix(rest, ".") {
|
|
return ""
|
|
}
|
|
rest = strings.Trim(rest, "-_")
|
|
if rest == "" || rest == "launch" {
|
|
return ""
|
|
}
|
|
return strings.Map(func(r rune) rune {
|
|
if r >= 'a' && r <= 'z' || r >= '0' && r <= '9' || r == '-' || r == '_' {
|
|
return r
|
|
}
|
|
return '-'
|
|
}, rest)
|
|
}
|
|
|
|
// claudeDirIsClaude says whether dir holds what Claude Code itself keeps in
|
|
// a config folder: its settings.json or its sign-in file, or its projects.
|
|
// Another tool's .claude-… folder (a router's, a launcher's) has none.
|
|
func claudeDirIsClaude(dir string) bool {
|
|
for _, f := range []string{"settings.json", ".credentials.json"} {
|
|
if fi, err := os.Stat(filepath.Join(dir, f)); err == nil && fi.Mode().IsRegular() {
|
|
return true
|
|
}
|
|
}
|
|
return isDir(filepath.Join(dir, "projects"))
|
|
}
|
|
|
|
// claudeDirAgents are the Claude Code config folders beside the claude
|
|
// row's, each an agent of its own. None while the folder has no Claude
|
|
// Code's files: a leftover is no agent.
|
|
func claudeDirAgents(home string) []*Agent {
|
|
es, err := os.ReadDir(home)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
main := appdir.ClaudeDirIn(home)
|
|
var names []string
|
|
byName := map[string]string{}
|
|
for _, e := range es {
|
|
name := claudeDirName(e.Name())
|
|
dir := filepath.Join(home, e.Name())
|
|
if name == "" || !dirent.IsFolder(home, e) || dir == main || !claudeDirIsClaude(dir) {
|
|
continue
|
|
}
|
|
if _, dup := byName[name]; dup {
|
|
continue
|
|
}
|
|
byName[name] = dir
|
|
names = append(names, name)
|
|
}
|
|
// with CLAUDE_CONFIG_DIR elsewhere, the default folder is one of the others
|
|
if def := filepath.Join(home, ".claude"); def != main && isDir(def) && claudeDirIsClaude(def) {
|
|
byName["default"] = def
|
|
names = append(names, "default")
|
|
}
|
|
sort.Strings(names)
|
|
var out []*Agent
|
|
for _, name := range names {
|
|
dir := byName[name]
|
|
id := "claude#" + name
|
|
a := claudeIn(place{home: home, id: id, dir: dir})
|
|
a.ID, a.Name = id, "Claude Code · "+name
|
|
// the isolated Claude Desktop's Code tab's (#6459), by its app's name
|
|
if dir == desktopIsolatedClaudeDir(home) {
|
|
a.Name = "Claude Code · " + desktopiso.Name
|
|
}
|
|
// the claude row keeps the command, the names and the requests
|
|
a.Aliases, a.UA, a.Bin = nil, nil, ""
|
|
a.detect = func() bool { return claudeDirIsClaude(dir) }
|
|
out = append(out, a)
|
|
}
|
|
return out
|
|
}
|