Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
usage: a Claude Code call skips the desktop-root path arithmetic
yetone80d32fd60965
diff --git a/internal/usage/session_provider.go b/internal/usage/session_provider.goindex eb728dd2e..9f1502b5e 100644--- a/internal/usage/session_provider.go+++ b/internal/usage/session_provider.go@@ -160,19 +160,33 @@ func (r *sessionResolver) officialLogin(c sessions.Call, account string) bool {return false}+// desktopAgentSessions is the folder of a desktop root that holds Claude+// desktop's agent-mode sessions, each beside the metadata naming its+// account.+const desktopAgentSessions = "local-agent-mode-sessions"+func (r *sessionResolver) desktopIdentity(c sessions.Call) (desktopSessionIdentity, bool) {if c.Agent != "claude" && c.Agent != "claude-desktop" {return desktopSessionIdentity{}, false}var id desktopSessionIdentityfound := false- for _, root := range r.roots {+ // Only a file under a desktop root's local-agent-mode-sessions can+ // name one: the rest (every Claude Code session, ~380k calls in a+ // long history, asked twice each) skip the Rel and the Split, which+ // were a fifth of what a started magpie's first Requests read+ // allocated.+ roots := r.roots+ if !strings.Contains(c.File, desktopAgentSessions) {+ roots = nil+ }+ for _, root := range roots {rel, err := filepath.Rel(root, c.File)if err != nil {continue}parts := strings.Split(rel, string(filepath.Separator))- if len(parts) > 4 && parts[0] == "local-agent-mode-sessions" && strings.HasPrefix(parts[3], "local_") && parts[4] == ".claude" {+ if len(parts) > 4 && parts[0] == desktopAgentSessions && strings.HasPrefix(parts[3], "local_") && parts[4] == ".claude" {path := filepath.Join(root, filepath.Join(parts[:4]...)) + ".json"id, found = r.desktop[path]breakdiff --git a/internal/usage/session_provider_test.go b/internal/usage/session_provider_test.goindex 4ee00a12b..f7ce46d8a 100644--- a/internal/usage/session_provider_test.go+++ b/internal/usage/session_provider_test.go@@ -291,3 +291,15 @@ func TestOpenCodeSessionCallIsWhatItAskedFor(t *testing.T) {t.Fatalf("an OpenCode call: requested %q model %q served %q effort %q", r.Requested, r.Model, r.Served, r.Effort)}}++// A Claude Code call outside every desktop root costs nothing to place:+// a started magpie's first Requests read asks this of every call twice,+// and the path arithmetic it skipped was a fifth of what that read+// allocated.+func TestDesktopIdentityOfCLICallAllocatesNothing(t *testing.T) {+ r := &sessionResolver{roots: []string{"/Users/u/Library/Application Support/Claude", "/Users/u/Library/Application Support/Claude-3p"}}+ call := sessions.Call{Agent: "claude", Session: "s", File: "/Users/u/.claude/projects/-Users-u-src-app/0b9c2f6e-1d3a-4e8f-9a7b-5c6d7e8f9a0b.jsonl"}+ if n := testing.AllocsPerRun(100, func() { r.desktopIdentity(call) }); n != 0 {+ t.Fatalf("a CLI call's desktop identity allocated %v times", n)+ }+}