Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

zcode: on Windows, write where ZCode reads, %HOME% before %USERPROFILE%

yetonec358e7660789
diff --git a/docs/reference.md b/docs/reference.md
index 018fc58d2..d3f0e75a7 100644
--- a/docs/reference.md
+++ b/docs/reference.md
@@ -136,7 +136,7 @@ line; agents connected to magpie lose it when it quits.
| Qoder CN (CLI) | `~/.qoder-cn/settings.json` (`$QODERCN_CONFIG_DIR`) | model, effort (as Qoder; its own accounts, a Qoder CN plan with BYOK) |
| Grok Build | `~/.grok/config.toml` (`$GROK_HOME`) | model, effort |
| Grok App | `agent-home/config.toml` in its data folder (`$GROK_APP_HOME`, else `~/Library/Application Support/com.grokapp.grok-app`, `%APPDATA%\grokapp\grok-app\data`, `$XDG_DATA_HOME/grok-app`, or `~/.grok-app`) | model (a `[model.magpie]` custom provider under Accounts, with magpie's models and their effort levels in `app_models`; the route, `[models] default`, stays until the user presses Use on magpie there (one of the App's own routes picked in magpie is written as the route, and magpie's channel goes); a route an older magpie set to `magpie` is put back once; Disconnect drops the channel and puts the route back only if it is still `magpie`, else the one it was on before Connect if none is left; a model or default effort picked in the App kept; instructions, MCP and skills are the Library's Grok App row on agent-home; RTK has no hook for it or for Grok Build) |
-| ZCode | `~/.zcode/v2/config.json` | provider (magpie's models in ZCode's picker) |
+| ZCode | `~/.zcode/v2/provider_config.json` and `config.json`, under the data folder moved in ZCode's settings (`dataBaseDir`); `~` is `$HOME` when set, on Windows too, as ZCode reads it before `%USERPROFILE%` | provider (magpie's models in ZCode's picker) |
| WorkBuddy | `~/.workbuddy/models.json` (`$WORKBUDDY_CONFIG_DIR`) | provider (magpie's models in WorkBuddy's picker) |
| WorkBuddy AI | `~/.workbuddy-ai/models.json` (the international build) | provider (magpie's models in WorkBuddy AI's picker) |
| CodeBuddy Code | `~/.codebuddy/models.json` (`$CODEBUDDY_CONFIG_DIR`), `settings.json` | model (magpie's models in its list; the session model) |
diff --git a/internal/agent/zcode.go b/internal/agent/zcode.go
index fe5a04db1..b34002fb5 100644
--- a/internal/agent/zcode.go
+++ b/internal/agent/zcode.go
@@ -8,6 +8,7 @@ import (
"net/url"
"os"
"path/filepath"
+ "runtime"
"slices"
"strings"
@@ -57,9 +58,14 @@ import (
// files (zcodeFormat), and only a provider magpie adds new starts on
// Anthropic Messages.
+// zcodeOS is the OS ZCode's home is found for, so a test can ask for
+// Windows' (appdir.ZCodeHomeOn).
+var zcodeOS = runtime.GOOS
+
func zcode(home string) *Agent {
- // where ZCode keeps its data, moved there in its settings or not
- dir := filepath.Join(appdir.ZCodeDataIn(home), ".zcode")
+ // where ZCode keeps its data, moved there in its settings or not, under
+ // the home ZCode reads (HOME first, on Windows too)
+ dir := filepath.Join(appdir.ZCodeDataIn(appdir.ZCodeHomeOn(zcodeOS, home)), ".zcode")
path := filepath.Join(dir, "v2", "config.json")
rules := filepath.Join(dir, "v2", "provider_config.json")
key := "provider." + magpieID
diff --git a/internal/agent/zcode_test.go b/internal/agent/zcode_test.go
index 16211235f..63837df81 100644
--- a/internal/agent/zcode_test.go
+++ b/internal/agent/zcode_test.go
@@ -618,3 +618,68 @@ func TestZCodeKeepsTheUsersSettings(t *testing.T) {
}
check("pick")
}
+
+// ZCode reads $HOME before os.homedir() on every OS, so on a Windows where
+// the user set HOME (for Git Bash, MSYS2, Emacs) its providers, settings
+// and moved data folder are under %HOME%\.zcode, not %USERPROFILE%\.zcode,
+// Go's home. magpie wrote its provider under USERPROFILE: connected, no
+// error, and no magpie in ZCode (Gearclickist on Discord).
+func TestZCodeOnWindowsUsesTheHomeZCodeReads(t *testing.T) {
+ profile := syncHome(t)
+ old := zcodeOS
+ zcodeOS = "windows"
+ t.Cleanup(func() { zcodeOS = old })
+ set := t.TempDir()
+ t.Setenv("HOME", set)
+ if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro"}}); err != nil {
+ t.Fatal(err)
+ }
+
+ want := filepath.Join(set, ".zcode")
+ a := zcode(profile)
+ if a.Dir != want || a.Path != filepath.Join(want, "v2", "config.json") {
+ t.Fatalf("ZCode's folder on Windows with HOME set: %s, %s; want %s", a.Dir, a.Path, want)
+ }
+ if err := a.Field("provider").Set("magpie"); err != nil {
+ t.Fatal(err)
+ }
+ if !zcodeRuled(filepath.Join(want, "v2", "provider_config.json")) {
+ t.Fatalf("no magpie in %s:\n%s", want, readFile(filepath.Join(want, "v2", "provider_config.json")))
+ }
+ if _, ok := edit.GetJSON(filepath.Join(want, "v2", "config.json"), "provider.magpie"); !ok {
+ t.Fatal("no magpie in config.json under HOME")
+ }
+ if _, err := os.Stat(filepath.Join(profile, ".zcode")); err == nil {
+ t.Fatal("written under USERPROFILE, which ZCode doesn't read while HOME is set")
+ }
+
+ // the data folder moved in ZCode's settings is read from the setting.json
+ // under HOME, where ZCode keeps it
+ moved := t.TempDir()
+ setting, _ := json.Marshal(map[string]any{"dataBaseDir": moved})
+ os.WriteFile(filepath.Join(want, "v2", "setting.json"), setting, 0o644)
+ if got := zcode(profile).Dir; got != filepath.Join(moved, ".zcode") {
+ t.Fatalf("moved data folder under HOME's settings: %s", got)
+ }
+ os.Remove(filepath.Join(want, "v2", "setting.json"))
+
+ // no HOME, or one that isn't rooted: USERPROFILE, as ZCode's os.homedir()
+ for _, h := range []string{"", " ", "relative"} {
+ t.Setenv("HOME", h)
+ if got := zcode(profile).Dir; got != filepath.Join(profile, ".zcode") {
+ t.Fatalf("HOME %q: %s", h, got)
+ }
+ }
+ // a folder that isn't the user's own home (a test's, a WSL distro's) is
+ // ZCode's as given
+ t.Setenv("HOME", set)
+ other := t.TempDir()
+ if got := zcode(other).Dir; got != filepath.Join(other, ".zcode") {
+ t.Fatalf("a given folder that isn't USERPROFILE: %s", got)
+ }
+ // elsewhere Go's home is HOME already: the folder given stays
+ zcodeOS = "darwin"
+ if got := zcode(profile).Dir; got != filepath.Join(profile, ".zcode") {
+ t.Fatalf("darwin: %s", got)
+ }
+}
diff --git a/internal/appdir/zcode.go b/internal/appdir/zcode.go
index 59a2d316a..df41d7b12 100644
--- a/internal/appdir/zcode.go
+++ b/internal/appdir/zcode.go
@@ -4,9 +4,37 @@ import (
"encoding/json"
"os"
"path/filepath"
+ "runtime"
"strings"
)
+// ZCodeHome is the home folder ZCode (Zhipu's desktop app) reads, given
+// home, the user's home as Go reads it (os.UserHomeDir). ZCode, a Node
+// app, takes $HOME before os.homedir() on every OS: its data folder
+// (getDataBaseDir: process.env.HOME?.trim() || homedir()), its settings
+// (resolveUserHomeDir: HOME, then USERPROFILE) and the skills and MCP
+// servers it reads. On a Mac or Linux that is Go's home too. On Windows
+// Go's is USERPROFILE and HOME is mostly unset, but one the user set (for
+// Git Bash, MSYS2 or Emacs) is where ZCode keeps everything, and magpie
+// wrote its provider under USERPROFILE, where ZCode never looked
+// (Gearclickist on Discord: connected, no error, and no magpie in ZCode).
+func ZCodeHome(home string) string { return ZCodeHomeOn(runtime.GOOS, home) }
+
+// ZCodeHomeOn is ZCodeHome on goos, so a test can ask for Windows'. A
+// HOME that isn't rooted is left out. Only the user's own home is moved:
+// a folder that isn't USERPROFILE (a test's, a WSL distro's) is ZCode's
+// as given.
+func ZCodeHomeOn(goos, home string) string {
+ if goos != "windows" {
+ return home
+ }
+ h := strings.TrimSpace(os.Getenv("HOME"))
+ if h == "" || !rooted(h) || !strings.EqualFold(filepath.Clean(home), filepath.Clean(os.Getenv("USERPROFILE"))) {
+ return home
+ }
+ return h
+}
+
// ZCodeDataIn is the folder ZCode (Zhipu's desktop app) keeps its .zcode
// data in, with home as the user's home folder: the home folder, unless the
// user moved it in ZCode's settings (数据存储路径, "data storage path").
diff --git a/internal/library/targets.go b/internal/library/targets.go
index ecfe544fa..a985cb96d 100644
--- a/internal/library/targets.go
+++ b/internal/library/targets.go
@@ -240,7 +240,8 @@ func targetOf(a *agent.Agent) *Target {
case "zcode":
// ZCode's own servers are its cli/config.json's mcp.servers (the
// app's MCP settings write there); AGENTS.md and skills beside it
- d := filepath.Join(h, ".zcode")
+ // under the home ZCode reads, HOME first on Windows too
+ d := filepath.Join(appdir.ZCodeHome(h), ".zcode")
t.Instructions = filepath.Join(d, "AGENTS.md")
t.MCP = &mcpFile{Path: filepath.Join(d, "cli", "config.json"), Format: fmtZCode}
t.Skills = filepath.Join(d, "skills")
diff --git a/internal/provider/zcode.go b/internal/provider/zcode.go
index 7e091a785..eec3d6752 100644
--- a/internal/provider/zcode.go
+++ b/internal/provider/zcode.go
@@ -76,7 +76,7 @@ type zcodeKey struct {
func zcodeCredentialsPath() string {
home, _ := os.UserHomeDir()
// under the folder ZCode's data was moved to, when it was
- return filepath.Join(appdir.ZCodeDataIn(home), ".zcode", "v2", "credentials.json")
+ return filepath.Join(appdir.ZCodeDataIn(appdir.ZCodeHome(home)), ".zcode", "v2", "credentials.json")
}
// zcodeSecret is the key ZCode encrypts its credentials with.
diff --git a/internal/provider/zcode_team.go b/internal/provider/zcode_team.go
index 3eb7d70a3..a6396b2e9 100644
--- a/internal/provider/zcode_team.go
+++ b/internal/provider/zcode_team.go
@@ -49,6 +49,8 @@ import (
"strconv"
"strings"
"time"
+
+ "github.com/yetone/magpie/internal/appdir"
)
func (k zcodeKey) team() bool { return k.Org != "" && k.Project != "" }
@@ -109,7 +111,7 @@ func zcodeOwnTeam(store map[string]string, secret []byte) (zcodeKey, bool) {
} `json:"providerFamilyConnectionSelections"`
Legacy map[string]string `json:"modelProviderFamilySelectedKeys"` // before providerFamilyConnectionSelections (migrateLegacyAccountConnectionSettings)
}
- if !readJSON(filepath.Join(home, ".zcode", "v2", "setting.json"), &set) {
+ if !readJSON(filepath.Join(appdir.ZCodeHome(home), ".zcode", "v2", "setting.json"), &set) {
return zcodeKey{}, false
}
families := []string{"zai", "bigmodel"}
diff --git a/internal/sessions/zcode.go b/internal/sessions/zcode.go
index 500a66e10..dc254a4b3 100644
--- a/internal/sessions/zcode.go
+++ b/internal/sessions/zcode.go
@@ -15,7 +15,11 @@ import (
// subagent's work is a session whose parent is the one it ran in, as in
// OpenCode. ZCode is a desktop app: no command picks a session up again.
-// ZCodeDir is ZCode's folder, ~/.zcode.
+// ZCodeDir is ZCode's folder, ~/.zcode, under Go's home. Its CLI's
+// database stays there, USERPROFILE on Windows, even where the app keeps
+// the rest under a HOME the user set (appdir.ZCodeHome): ZCode 3.14.3 for
+// Windows, run with both, wrote cli\db\db.sqlite under USERPROFILE and
+// v2 under HOME.
func ZCodeDir() string {
home, _ := os.UserHomeDir()
return filepath.Join(home, ".zcode")